作者:瀚高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)