当前位置: 首页 > news >正文

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 ~]$

http://www.xdnf.cn/news/1478377.html

相关文章:

  • 详解文件操作
  • 数据库集群分类详解
  • 【Java】抽象类和接口对比+详解
  • Altium Designer(AD24)加载License文件方法
  • 计算机CPU的工作原理介绍
  • 抽成独立组件库:微前端架构下公共组件共享的最佳实践
  • MyBatis Example模式SQL注入风险
  • C#中一段程序类比博图
  • 【完整源码+数据集+部署教程】水培植物病害检测系统源码和数据集:改进yolo11-AKConv
  • 从 JDK 1.8 切换到 JDK 21 时遇到 NoProviderFoundException 该如何解决?
  • 【科研成果速递-IJGIS】如何描述与分类移动对象的时空模式?一个新的分类框架与体系!
  • JDBC操作数据库所需要的组件
  • 《Kubernetes 构建 MySQL MGR 集群实战教程》
  • 使用Spring Boot DevTools快速重启功能
  • Python爬虫实战:研究Event Handling机制,构建在线教育平台的课程数据采集和分析系统
  • 使用 YAML 自动化 Azure DevOps 管道
  • browser-use 的三种启动方式详解
  • Android Framework智能座舱面试题
  • 【Python自动化】 21.2 Pandas 读取 Excel 时的 dtype 参数完全指南
  • 贪心算法应用:DNA自组装问题详解
  • Flask论坛与个人中心页面开发教程完整详细版
  • 【LeetCode 热题 100】49. 字母异位词分组
  • Windows 11 手动下载安装配置 uv、配置国内源
  • 固定资产管理系统(vue+Springboot+mybatis)
  • 行为式验证码技术解析:滑块拼图、语序选词与智能无感知
  • Vllm-0.10.1:vllm bench serve参数说明
  • 【完整源码+数据集+部署教程】农作物病害检测系统源码和数据集:改进yolo11-HSFPN
  • Flutter常用库集锦
  • Webpack热更新(HMR)底层原理详解
  • 基于定制开发开源AI智能名片S2B2C商城小程序的DMP平台离线文件上传功能优化研究