流复制不需要查一致性吧,看差异就好和复制进度即可~
一、大小差异
在主库上执行:
select
application_name,
pg_size_pretty(pg_xlog_location_diff(pg_current_xlog_location(), replay_location)) as diff
from
pg_stat_replication;
或者:
select
application_name,
client_addr,
cur_xlog || '/' || cur_offset as cur_xlog,
sent_xlog || '/' || sent_offset as sent_xlog,
replay_xlog || '/' || replay_offset as replay_xlog,
pg_size_pretty(( ((cur_xlog * 255 * 16 ^ 6) + cur_offset) - ((sent_xlog * 255 * 16 ^ 6) + sent_offset) )::numeric) as master_lag,
pg_size_pretty(( ((sent_xlog * 255 * 16 ^ 6) + sent_offset) - ((replay_xlog * 255 * 16 ^ 6) + replay_offset) )::numeric) as slave_lag,
pg_size_pretty(( ((cur_xlog * 255 * 16 ^ 6) + cur_offset) - ((replay_xlog * 255 * 16 ^ 6) + replay_offset) )::numeric) as total_lag
from (
select
application_name,
client_addr,
('x' || lpad(split_part(sent_location::text,'/', 1), 8, '0'))::bit(32)::bigint as sent_xlog,
('x' || lpad(split_part(replay_location::text, '/', 1), 8, '0'))::bit(32)::bigint as replay_xlog,
('x' || lpad(split_part(sent_location::text, '/', 2), 8, '0'))::bit(32)::bigint as sent_offset,
('x' || lpad(split_part(replay_location::text, '/', 2), 8, '0'))::bit(32)::bigint as replay_offset,
('x' || lpad(split_part(pg_current_xlog_location()::text, '/', 1), 8, '0'))::bit(32)::bigint as cur_xlog,
('x' || lpad(split_part(pg_current_xlog_location()::text, '/', 2), 8, '0'))::bit(32)::bigint as cur_offset
from
pg_stat_replication
) as s;
复制
二、时间差异
在从库上执行:
select now() - pg_last_xact_replay_timestamp() as replication_delay;
复制
如何查看主从复制的状态,且备库应用落后了多少字节
这些信息要在主库中查询
查看流复制的信息可以使用主库上的视图
select pid,state,client_addr,sync_priority,sync_state from pg_stat_replication;
复制
pg_stat_replication中几个字断记录了发送wal的位置及备库接收到的wal的位置、
sent_location–发送wal的位置
write_location–备库接收到的wal的位置
flush_location—备库写wal日志到磁盘的位置
replay_location—备库应用日志的位置
查看备库落后主库多少字节
select pg_xlog_location_diff(pg_current_xlog_location(),replay_location)/1024/1024 as MB from pg_stat_replication;
select pg_xlog_location_diff(pg_current_xlog_location(),replay_location)/1024/1024/1024 as GB from pg_stat_replication;
复制
级联复制
select pg_xlog_location_diff(pg_last_xlog_replay_location(),replay_location)/1024/1024/1024 as GB from pg_stat_replication;
复制
希望能帮助到你~