作者:瀚高PG实验室 (Highgo PG Lab)- 天蝎座
highgo=# show max_standby_streaming_delay ;
max_standby_streaming_delay
30s
(1 row)
highgo=# alter system set max_standby_streaming_delay TO -1;
ALTER SYSTEM
highgo=# \q
[highgo@hgdb1 ~]$ pg_ctl restart -m f
waiting for server to shut down… done
server stopped
server starting
[highgo@hgdb1 ~]$ 2018-03-15 17:03:42.291 CSTLOG: 00000: redirecting log output to logging collector process
2018-03-15 17:03:42.291 CSTHINT: Future log output will appear in directory “hgdb_log”.
流复制主备端修改参数 max_standby_streaming_delay为-1,重启主备数据库。
highgo=# show max_standby_streaming_delay;
max_standby_streaming_delay
-1
(1 row)
primary:
highgo=# create table t1 (id int);
CREATE TABLE
highgo=# insert into t1 values (1);
INSERT 0 1
standby:
highgo=# begin;
BEGIN
highgo=# select * from t1;
id
1
(1 row)
–事务不退出
primary:
highgo=# drop table t1;
DROP TABLE
highgo=# select * from pg_stat_replication ;
-[ RECORD 1 ]----±-----------------------------
pid | 1270
usesysid | 16391
usename | replica
application_name | walreceiver
client_addr | 192.168.10.61
client_hostname | hgdb1
client_port | 41424
backend_start | 2018-03-15 17:03:43.158148+08
backend_xmin |
state | streaming
sent_location | 0/130312C0
write_location | 0/130312C0
flush_location | 0/130312C0
replay_location | 0/13030DB8
sync_priority | 0
sync_state | async
replay_location | 0/13030DB8 --standby并未完全追上主库,因为standby有未完成的事务需要查询到t1表,但是primary事实上已经drop了表t1.
primary:
highgo=# create table test(id int, info text, crt_time timestamp);
CREATE TABLE
highgo=# insert into test select generate_series(1,1000000),‘test’,now();
INSERT 0 1000000
highgo=# checkpoint;
CHECKPOINT
highgo=#
highgo=# select * from pg_stat_replication ;
-[ RECORD 1 ]----±-----------------------------
pid | 1270
usesysid | 16391
usename | replica
application_name | walreceiver
client_addr | 192.168.10.61
client_hostname | hgdb1
client_port | 41424
backend_start | 2018-03-15 17:03:43.158148+08
backend_xmin |
state | streaming
sent_location | 0/1AF10888
write_location | 0/1AF10888
flush_location | 0/1AF10888
replay_location | 0/13030DB8
sync_priority | 0
sync_state | async
standby另开一个窗口:
没有test表
highgo=# \d
List of relations
Schema | Name | Type | Owner
----------------±-------------------±------±-------
oracle_catalog | dual | view | highgo
public | pg_stat_statements | view | highgo
public | t1 | table | highgo
public | test01 | table | highgo
(4 rows)
highgo=#
上述证明,standby虽然在接收xlog ,但是并没有应用xlog日志。
在这种情况下,假如备端的该事务一直回滚或提交,那么备端和主端的差距就会越来越大。所以该参数尽量不要设置为-1.
参考:
https://yq.aliyun.com/articles/14644spm=a2c4e.11163080.searchblog.9.3bc62ec1FgtwQl