標籤:
1. 大小差異
在主庫上執行
select application_name, pg_size_pretty(pg_xlog_location_diff(pg_current_xlog_location(), replay_location)) as difffrom pg_stat_replication;
或者:
selectapplication_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_lagfrom (selectapplication_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_offsetfrompg_stat_replication) as s;
2. 時間差異
在從庫上執行:
select now() - pg_last_xact_replay_timestamp() as replication_delay;
PostgreSQL 主從差異查看