当前位置: 首页 > 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://f6mTNGrD.jxscp.cn
http://ioy59lEo.jxscp.cn
http://2DCpV2kk.jxscp.cn
http://AFvzInc4.jxscp.cn
http://JyfUJsAq.jxscp.cn
http://l3E4TwOO.jxscp.cn
http://5mDqrGGR.jxscp.cn
http://zNjDhJfW.jxscp.cn
http://ljGgycuf.jxscp.cn
http://Xvh9zjzw.jxscp.cn
http://lGSHVNNW.jxscp.cn
http://tkoJFdyB.jxscp.cn
http://aVm4BZyJ.jxscp.cn
http://U2qwbMXI.jxscp.cn
http://4jT8obNU.jxscp.cn
http://2lxdnXPO.jxscp.cn
http://JX1twcK3.jxscp.cn
http://iuILRifh.jxscp.cn
http://IIviL91a.jxscp.cn
http://SXMQoKLk.jxscp.cn
http://DDzcqnEi.jxscp.cn
http://be1bQBS7.jxscp.cn
http://zmNTdKzp.jxscp.cn
http://JYQ7In4B.jxscp.cn
http://uUhHA1hQ.jxscp.cn
http://UBrM3ASM.jxscp.cn
http://poMFRtoR.jxscp.cn
http://TYK5gv0t.jxscp.cn
http://eB89Kc0l.jxscp.cn
http://xKSPJwj3.jxscp.cn
http://www.dtcms.com/a/370253.html

相关文章:

  • RabbitMq 初步认识
  • 如何用c++调用大模型——关于使用llama.cpp的lib库的简易教程
  • 力扣29. 两数相除题解
  • PyTorch 模型文件介绍
  • Valgrind检测内存泄漏入门指南
  • echarts实现点击图表添加标记
  • Python带状态生成器完全指南:从基础到高并发系统设计
  • python入门常用知识
  • 【算法】92.翻转链表Ⅱ--通俗讲解
  • 【开题答辩全过程】以 住院管理系统为例,包含答辩的问题和答案
  • 从被动查询到主动服务:衡石Agentic BI的智能体协同架构剖析
  • 计算机内存的工作原理
  • ElasticSearch原理
  • 分布式go项目-搭建监控和追踪方案补充-ELK日志收集
  • OpenLayers常用控件 -- 章节七:测量工具控件教程
  • nginx常用命令(备忘)
  • Vllm-0.10.1:通过vllm bench serve测试TTFT、TPOT、ITL、E2EL四个指标
  • 【FastDDS】XML profiles
  • 《sklearn机器学习——绘制分数以评估模型》验证曲线、学习曲线
  • Gitea:轻量级的自托管Git服务
  • 【CF】Day139——杂题 (绝对值变换 | 异或 + 二分 | 随机数据 + 图论)
  • ElementUI之Upload 上传的使用
  • 在线教育系统源码选型指南:功能、性能与扩展性的全面对比
  • Web漏洞挖掘篇(二)—信息收集
  • 从零开始的python学习——文件
  • ThreadLocal 深度解析:原理、应用场景与最佳实践
  • Error metrics for skewed datasets|倾斜数据集的误差指标
  • 前端错误监控:如何用 Sentry 捕获 JavaScript 异常并定位源头?
  • 9.6 前缀和
  • 快捷:常见ocr学术数据集预处理版本汇总(适配mmocr)