postgres 退出_Postgresl选择正确的关闭模式
停止数据库的命令:
pg_ctl stop -D $PGDATA [-m shutdown-mode]
shutdown-mode有如下几种模式:
1. smart: 等所有的连接中止后,关闭数据库。如果客户端连接不终止, 则无法关闭数据库。
开启一个空会话:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ psql
psql (9.4.4)
Type "help" for help.
postgres=#
用smart关闭数据库:
[postgres@localhost ~]$ pg_ctl stop -D $PGDATA -m smart
waiting for server to shut down............................................................... failed
pg_ctl: server does not shut down
HINT: The "-m fast" option immediately disconnects sessions rather than
waiting for session-initiated disconnection
2. fast: 快速关闭数据库, 断开客户端的连接,让已有的事务回滚,然后正常关闭数据库。
[postgres@localhost ~]$ pg_ctl stop -D $PGDATA -m fast
waiting for server to shut down.... done
server stopped
查看关闭日志:
LOG: received fast shutdown request
LOG: aborting any active transactions
FATAL: terminating connection due to administrator command
LOG: shutting down
LOG: database system is shut down
会话被强制中断,然后关闭数据库。
起一个事务,然后测试关闭:
postgres=# create table t(id int primary key, name varchar(9));
CREATE TABLE
postgres=# begin;
BEGIN
postgres=# insert into t values(1,'a')
postgres-# ;
INSERT 0 1
不提交, 然后用FAST MODE去关闭数据库:
[postgres@localhost ~]$ pg_ctl stop -D $PGDATA -m fast
waiting for server to shut down.... done
server stopped
查看日志:
LOG: received fast shutdown request
LOG: aborting any active transactions
LOG: autovacuum launcher shutting down
FATAL: terminating connection due to administrator command
LOG: shutting down
LOG: database system is shut down
同样是直接中断会话, 而不去管事务有没有提交。
postgres=# select * from t;
id | name
----+------
(0 rows)
没有提交的数据, 在重启之后并不能查到。
3. immediate: 立即关闭数据库,立即停止数据库进程,直接退出,下次启动时会进行实例恢复。
postgres=# insert into t values(1,'a')
;
INSERT 0 1
postgres=# select * from t;
id | name
----+------
1 | a
(1 row)
关闭数据库:
[postgres@localhost ~]$ pg_ctl stop -D $PGDATA -m immediate
waiting for server to shut down.... done
server stopped
查看日志:
LOG: received immediate shutdown request
WARNING: terminating connection because of crash of another server process
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.
HINT: In a moment you should be able to reconnect to the database and repeat your command.
WARNING: terminating connection because of crash of another server process
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.
HINT: In a moment you should be able to reconnect to the database and repeat your command.
启动数据库:
[postgres@localhost ~]$ pg_ctl -D /apps/pgsql/pgdata -l 1.log start
server starting
查看日志:
LOG: database system was interrupted; last known up at 2017-04-27 18:56:47 PDT
LOG: database system was not properly shut down; automatic recovery in progress #提示非正常关机,自动开启恢复。
LOG: redo starts at 0/181F910
LOG: record with zero length at 0/181FA90
LOG: redo done at 0/181FA60
LOG: last completed transaction was at log time 2017-04-27 18:59:13.727213-07
LOG: MultiXact member wraparound protections are now enabled
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
查看数据:
[postgres@localhost ~]$ psql
psql (9.4.4)
Type "help" for help.
postgres=# select * from t;
id | name
----+------
1 | a
(1 row)
提交的数据已通过实例恢复。
小结:
对比以上三种关库模式:
smart最为安全,但最慢, 需要将所有连接都断开后,才会关库,默认关库模式。
fast强制中断会话,而不管有操作有没有提交,在做系统维护(系统维护时一般应用都正常关闭了,或者不再会有事务操作。)时,需要这种模式来关闭数据库。
immediate最暴力的方式,不管数据有没有落盘(POSGRE是遵循WAL机制),就直接关掉, 待启动时进行实例恢复, 如果在关库前有大量的事务没有写入磁盘, 那这个恢复过程可能会非常的漫长。
postgres 退出_Postgresl选择正确的关闭模式相关推荐
- 四象限运行模式_信息流广告推广怎么选择正确的出价模式?
5分钟教你如何选择信息流广告的正确出价模式 广告主投放信息流广告的时候总是纠结自己的产品应该选择哪种出价扣费模式,今天我们就来介绍下各个模式的出价扣费情况,广告主该如何选择合适的出价扣费模式. 一.了 ...
- 逸管家:把握不同行业生命周期,选择正确商业模式
</P> <P> 原标题:把握不同行业生命周期,选择正确商业模式</P> <P> 现今中小企业已进入理性商业模式选择期,大量中小企业在拿到天使投资后进入 ...
- 数据图表可视化_数据可视化如何选择正确的图表第1部分
数据图表可视化 According to the World Economic Forum, the world produces 2.5 quintillion bytes of data ever ...
- ABBYY FineReader 14之如何选择正确的OCR选项
在使用ABBYY FineReader 14识别文档时,要想获得快速准确的结果,选择正确的OCR选项很重要,决定好要使用的选项之后,还应该考虑文档的类型和复杂性,以及如何去使用识别结果. OCR选项位 ...
- 改善C#程序的建议3:在C#中选择正确的集合进行编码
原文:改善C#程序的建议3:在C#中选择正确的集合进行编码 要选择正确的集合,我们首先要了解一些数据结构的知识.所谓数据结构,就是相互之间存在一种或多种特定关系的数据元素的集合.结合下图,我们看一下对 ...
- java 关闭另一个jvm_JVM安全退出(如何优雅的关闭java服务)
背景 用户:货都到了,购物车里怎么还有刚买的东西,what? 产品:有用户反映,提单完成了,怎么没清购物车,研发赶紧看看是不是有bug啊? 研发:恩,我看看,!@#¥%--&*()一顿狂查,搜 ...
- ecshop 搜索热词推荐_拼多多搜索推广实操——如何选择正确的关键词实现高投产!...
原标题:拼多多搜索推广实操--如何选择正确的关键词实现高投产! 大家好我是拼多多运营林枫,每天都会更新新的内容哦,没关注的记得关注一下哦! 今天和大家讲讲搜索推广怎么正确选择有效的关键词,很多商家可能 ...
- 翻译:程序员数据结构基础:选择正确的数据结构
本文转载自GameDev.net,仅供学习交流.因为刚刚开始学习翻译,难免有些疏漏,如果有哪些地方翻译的不正确,请不吝告知,万分感谢. 原文链接:http://www.gamedev.net/page ...
- clocks_per_sec 时间不正确_壁挂炉不用了怎么关?壁挂炉正确的关闭方法
天气火热,用壁挂炉取暖的用户也都很想了解怎么正确关掉暖气.用过壁挂炉的用户都知道,它不但能采暖,还能提供生活热水,在天气转暖的时候,有些只想单独关闭暖气功能,还有的是暖气和热水功能都不用了,那怎么来正 ...
- 如何正确的关闭 MFC 线程
前言: 近日在网上看到很多人问及如何关闭一下线程,但是我看网上给出的并不详细,而且有些方法还是错误的.小弟在此拙作一篇,不谈别的,只谈及如何正确的关闭MFC的线程,至于Win32和C RunTime的 ...
最新文章
- Android App压力测试(Monkey和ADB)
- 十一、H.264的Slice Header解析
- mysqldatareader获取整行数据给datarow_SqlDataReader的用法(读取1整行)
- nat,acl及单臂路由实验(ensp)
- RocketMQ消息重试机制
- Swift 5新特性详解:ABI 稳定终于来了!
- 17大主链均狂跌国内项目却看涨, 本周不可不知的7组榜单 | 数据周榜
- Selenium下载与安装
- cad怎么画立体图形教学_CAD画三维图中如何绘制三维实体
- 【百度】怎么使用cookie登陆百度账号
- 香港服务器怎么加速?
- 海马玩模拟器 v0.7.2 官方版
- Gimp 将图片中的颜色更改
- ESXI8.0一键安装黑群晖DSM7
- Docker容器入门及网易最佳实践
- python导出项目pip_pip导出当前项目所用的包list列表
- Python爬取图片+百度人脸检测过滤高颜值美女!
- PPP协议实现透明传输的2种方法以及工作状态
- MDK5.23中文件图标上红叉,横杠,灰色,叹号的含义
- 2018,如何从小白升级到大牛程序员呢?
热门文章
- cad缩放_CAD软件中的CAD图纸界限是什么?
- cmd: cd /D %~dp0 的含义
- Android手机怎么找回微信好友,五种实用方法 安卓微信怎么恢复好友
- 【Audio音频兴趣拓展】如何调试频响曲线?
- java_SSD3_实验报告_面向对象——多态
- 3分钟快速制作一张高颜值的公众号封面图
- 一款好用的插件——油猴子
- 清华大学计算机系保送,号称计算机世界第一的清华,三位金牌保送生全部投奔了美国...
- ROS系列书籍--机械工业出版社
- 不要问我1是不是质数