PostgreSQL三种关闭方式的区别

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:强制中断会话,而不管有操作有没有提交,在做系统维护(系统维护时一般应用都正常关闭了,或者不再会有事务操作。)时,需要这种模式来关闭数据库。 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 \~\]$

相关推荐
咸鱼加辣6 分钟前
【前端的crud】DOM 就是前端里的“数据库”
前端·数据库
Lin_Miao_099 分钟前
基于 DataX + DataX-Web 生成报表数据
java·数据库
一位代码11 分钟前
mysql | 复制表结构和数据
数据库·mysql
IndulgeCui11 分钟前
记一次mysql迁移至OceanBase操作记录
数据库·mysql·oceanbase
悟能不能悟15 分钟前
mybatis sql where a=#{a},如果a为null,会返回什么
数据库·sql·mybatis
l1t20 分钟前
豆包解读论文:将具有分支和循环控制流的命令式程序转换为标准SQL1999的公共表表达式
开发语言·数据库·人工智能·python·sql·postgresql·duckdb
云边有个稻草人24 分钟前
【MySQL】第五节—一文详解 | 表的约束(上)
数据库·mysql·default·表的约束·zerofill·主键约束
马克学长28 分钟前
SSM校外实习管理平台6tu82(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面
数据库·计算机毕设·ssm框架·实习管理信息化·校企协同实习
山峰哥28 分钟前
数据库性能优化实战:从工程架构到SQL调优的深度解析
大数据·数据库·oracle·性能优化·架构·深度优先
soft200152541 分钟前
MySQL Buffer Pool性能优化:LRU链表极致设计之道
数据库·mysql·链表