美文网首页
PostgreSQL三种关闭方式的区别

PostgreSQL三种关闭方式的区别

作者: 登录成功 | 来源:发表于2025-09-05 20:33 被阅读0次

1、使用smart参数关闭数据库:

smart:最为安全,但最慢,需要将所有连接都断开后,才会关库,默认关库模式。

smart: 等所有的连接中止后,关闭数据库。如果客户端连接不终止, 则无法关闭数据库。

[postgresql@master ~]$ pg_ctl stop -D $PGDATA -m smart

waiting for server to shut down.... done

server stopped

[postgresql@master ~]$

使用smart参数关闭数据库的日志:

2025-09-06 19:40:20.479 CST [56233] LOG:  received smart shutdown request

2025-09-06 19:40:20.480 CST [56233] LOG:  background worker "logical replication launcher" (PID 56241) exited with exit code 1

2025-09-06 19:40:20.480 CST [56236] LOG:  shutting down

2025-09-06 19:40:20.485 CST [56233] LOG:  database system is shut down

2、使用fast参数关闭数据库:

fast:强制中断会话,而不管有操作有没有提交https://www.naquan.com/,在做系统维护(系统维护时一般应用都正常关闭了,或者不再会有事务操作。)时,需要这种模式来关闭数据库。

fast: 快速关闭数据库, 断开客户端的连接,让已有的事务回滚,然后正常关闭数据库。

[postgresql@master ~]$ pg_ctl stop -D $PGDATA -m fast

waiting for server to shut down.... done

server stopped

[postgresql@master ~]

使用fast参数关闭数据库的日志:

2025-09-06 19:40:59.477 CST [56258] LOG:  received fast shutdown request

2025-09-06 19:40:59.478 CST [56258] LOG:  aborting any active transactions

2025-09-06 19:40:59.478 CST [56258] LOG:  background worker "logical replication launcher" (PID 56266) exited with exit code 1

2025-09-06 19:40:59.479 CST [56261] LOG:  shutting down

2025-09-06 19:40:59.484 CST [56258] LOG:  database system is shut down

3、使用immediate参数关闭数据库:

immediate:最暴力的方式,不管数据有没有落盘(POSGRE是遵循WAL机制),就直接关掉,待启动时进行实例恢复,如果在关库前有大量的事务没有写入磁盘,那这个恢复过程可能会非常的漫长。

immediate: 立即关闭数据库,立即停止数据库进程,直接退出,下次启动时会进行实例恢复。

[postgresql@master ~]$ pg_ctl stop -D $PGDATA -m immediate

waiting for server to shut down.... done

server stopped

[postgresql@master ~]$

使用immediate参数关闭数据库的日志:

2025-09-06 19:41:40.311 CST [56278] LOG:  received immediate shutdown request

2025-09-06 19:41:40.313 CST [56284] WARNING:  terminating connection because of crash of another server process

2025-09-06 19:41:40.313 CST [56284] DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.

2025-09-06 19:41:40.313 CST [56284] HINT:  In a moment you should be able to reconnect to the database and repeat your command.

2025-09-06 19:41:40.315 CST [56278] LOG:  database system is shut down

4、数据目录:

[postgresql@master ~]$ echo $PGDATA

/usr/local/postgresql/data

5、启动数据库:

[postgresql@master ~]$ pg_ctl start -D $PGDATA

waiting for server to start....2025-09-06 19:40:40.221 CST [56258] LOG:  redirecting log output to logging collector process

2025-09-06 19:40:40.221 CST [56258] HINT:  Future log output will appear in directory "log".

done

server started

[postgresql@master ~]$

相关文章

  • 启动与关闭

    postgresql启动 sudo /etc/init.d/postgresql start关闭 sudo /et...

  • hive搭建方式概览

    hive三种方式区别和搭建 Hive中metastore(元数据存储)的三种方式: a)内嵌Derby方式 b)L...

  • js三种存储方式区别

    js三种存储方式区别 javaScript有三种数据存储方式,分别是: sessionStorage localS...

  • PG体系结构

    创建数据库 PostgreSQL 创建数据库可以用以下三种方式: 1、使用 CREATE DATABASE SQL...

  • 2018-09-19 localStorage如何存储对象

    本地存储方式cookie、localStorage、sessionStorage 三种存储方式的区别 cookie...

  • python 求次方

    推荐阅读 1 python pow() 函数 | 菜鸟教程 python求次方的三种方式 三种方式的区别 我试图在...

  • Java实现线程的三种方式和区别

    Java实现线程的三种方式和区别 Java实现线程的三种方式: 继承Thread 实现Runnable接口 实现C...

  • 关闭 Ubuntu 无人值守更新功能

    Ubuntu 无人值守更新功能会关闭某些关键服务,比如postgresql。 生产环境必须关闭该功能:

  • React创建组件

    一、 React创建组件的三种方式及其区别 React推出后,出于不同的原因先后出现三种定义react组件的方式,...

  • React创建组件的三种方式及其区别

    React创建组件的三种方式及其区别 React推出后,出于不同的原因先后出现三种定义react组件的方式,殊途同...

网友评论

      本文标题:PostgreSQL三种关闭方式的区别

      本文链接:https://www.haomeiwen.com/subject/lsgnajtx.html