pg_is_xlog_replay_paused()

本文介绍了 PostgreSQL 中控制 standby 节点恢复进程的方法,包括如何使用 pg_is_xlog_replay_paused 判断恢复是否已暂停,如何使用 pg_xlog_replay_pause 暂停恢复,以及如何使用 pg_xlog_replay_resume 恢复暂停的恢复进程。

作者:瀚高PG实验室 (Highgo PG Lab)- 天蝎座

pg_is_xlog_replay_paused() bool

True if recovery is paused.

pg_xlog_replay_pause() void

Pauses recovery immediately (restricted to superusers by default, but other users can be granted EXECUTE to run the function).

pg_xlog_replay_resume() void

Restarts recovery if it was paused (restricted to superusers by default, but other users
can be granted EXECUTE to run the function).


While recovery is paused no further database changes are applied. If in hot standby, all new queries will see the same consistent snapshot of the database, and no further query conflicts will be generated until recovery is resumed.

If streaming replication is disabled, the paused state may continue indefinitely without problem. While streaming replication is in progress WAL records will continue to be received, which will eventually fill available disk space, depending upon the duration of the pause, the rate of WAL generation and available disk space.

pg_is_xlog_replay_paused() 判断standby 是否暂停了recovery。

pg_xlog_replay_pause() 暂停standby的recovery。

pg_xlog_replay_resume() 恢复standby的recovery。

下面做个测试:

primary:

highgo=# create table test01(id int  primary key, note text);
CREATE TABLE
highgo=#  insert into test01 values(1,'11111');
INSERT 0 1
highgo=# insert into test01 values(2,'22222');
INSERT 0 1

standby:

highgo=# select * from test01 ;
 id | note
----+-------
  1 | 11111
  2 | 22222
(2 rows)

highgo=# select pg_xlog_replay_pause() ;
 pg_xlog_replay_pause
----------------------

(1 row)

highgo=# select pg_is_xlog_replay_paused();
 pg_is_xlog_replay_paused
--------------------------
 t
(1 row)


primary:

highgo=# insert into test01 values(3,'33333');
INSERT 0 1
highgo=#

standby:

highgo=# select * from test01 ;
 id | note
----+-------
  1 | 11111
  2 | 22222
(2 rows)


highgo=# select pg_xlog_replay_resume();
 pg_xlog_replay_resume
-----------------------

(1 row)

highgo=# select * from test01 ;
 id | note
----+-------
  1 | 11111
  2 | 22222
  3 | 33333
(3 rows)

highgo=# select pg_is_xlog_replay_paused();
 pg_is_xlog_replay_paused
--------------------------
 f
(1 row)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值