上面我们提到replay_lsn:是slave上重放的最后的事务日志位置。 PG中可以使用pg_current_wal_lsn函数获取当前的wal log的写位置。 使用pg_wal_lsn_diff()计算两个wal日志之间的差距。 所以我们可以通过下面的方法获取高可用架构下从库与主库之间以MB为单位的距离(主备延迟): SELECT pg_wal_lsn_diff(A .c1, rep...
(4)standby端 上的WAL接收器通过write()系统函数调用,将接收到的WAL数据写入备库的WAL段,并向WAL发送器返回ACK响应。 (5)standby端 WAL接收器通过调用(如fsync()函数)将WAL数据刷新到WAL段中,向WAL发送器返回另一个ACK响应,并通知启动进程相关WAL数据已更新。 (6)standby端 启动进程重放已写入WAL段的WAL数据。
备库的pg_last_wal_receive_lsn()记录了接收位置 : postgres=# select pg_last_wal_receive_lsn(); pg_last_wal_receive_lsn --- 0/B0004B8 (1 row) 1. 2. 3. 4. 5. 备库的pg_stat_wal_receiver显示复制信息: postgres=# \x Expanded display is on. postgres=# select * from pg_stat_wal...
select client_addr,application_name, pg_wal_lsn_diff(pg_current_wal_lsn(), flush_lsn) as diff, sync_state from pg_stat_replication; client_addr | application_name | diff | sync_state ---+---+---+--- 172.21.0.6 | 172.21.0.6:11000 | 0 | async 查看主备同步状态: select postgres-...
postgres=# create role repl login replication encrypted password 'repl'; CREATE ROLE postgres=#\q --退出psql 2.2.3配置$PGDATA/data/pg_hba.conf,添加下面内容: 格式:host replication 同步用的用户名 备库IP地址或域名/24 trust 2.2.4配置主备库的postgres.con文件 ...
postgres=# create role repl login replication encrypted password 'repl'; CREATE ROLE postgres=#\q --退出psql 2.2.3配置$PGDATA/data/pg_hba.conf,添加下面内容: 格式:host replication 同步用的用户名 备库IP地址或域名/24 trust 2.2.4配置主备库的postgres.con文件 ...
(pg_current_wal_lsn(),flush_lsn) flush_wal,pg_wal_lsn_diff(pg_current_wal_lsn(),replay_lsn) replay_wal from pg_stat_replication; sent_wal | write_wal | flush_wal | replay_wal ---+---+---+--- 0 | 0 | 0 | 151253816 (1 row) postgres=# 在备库有复制延迟的前提下,提升备...
postgres=# create role repl login replication encrypted password 'repl'; CREATE ROLE postgres=#\q --退出psql 2.2.3配置$PGDATA/data/pg_hba.conf,添加下面内容: 格式:host replication 同步用的用户名 备库IP地址或域名/24 trust 2.2.4配置主备库的postgres.con文件 ...
postgres=# create role repl login replication encrypted password 'repl'; CREATE ROLE postgres=#\q --退出psql 2.2.3配置$PGDATA/data/pg_hba.conf,添加下面内容: 格式:host replication 同步用的用户名 备库IP地址或域名/24 trust 2.2.4配置主备库的postgres.con文件 ...
postgres=# create role repl login replication encrypted password 'repl'; CREATE ROLE postgres=#\q --退出psql 2.2.3配置$PGDATA/data/pg_hba.conf,添加下面内容: 格式:host replication 同步用的用户名 备库IP地址或域名/24 trust 2.2.4配置主备库的postgres.con文件 ...