PostgreSQL master-slave diff view

Source: Internet
Author: User
Tags diff

1. Size difference

Executing on the main library

Select Application_name, Pg_size_pretty (Pg_xlog_location_diff (Pg_current_xlog_location (), replay_location)) As Difffrom pg_stat_replication;

Or:

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 (+):: Bigint as sent_ Xlog, (' X '  | |  lpad (Split_part (replay_location::text,  '/',  1), 8,  ' 0 ')):: Bit (+):: Bigint as  replay_xlog, (' X '  | |  lpad (Split_part (sent_location::text,  '/',  2), 8,  ' 0 ')):: Bit (+):: Bigint as  sent_offset, (' X '  | |  lpad (Split_part (replay_location::text,  '/',  2), 8,  ' 0 '):: Bit (+):: Bigint as replay_offset, (' X '  | |  lpad (Split_part (pg_current_xlog_location ()::text,  '/',  1), 8,  ' 0 '):: Bit (+):: bigint  as cur_xlog, (' X '  | |  lpad (Split_part (pg_current_xlog_location ()::text,  '/',  2), 8,  ' 0 '):: Bit (+):: bigint  as cur_offsetfrompg_stat_replication)  as s;

2. Time difference

On the run from the library:

Select Now ()-Pg_last_xact_replay_timestamp () as Replication_delay;


PostgreSQL master-slave diff view

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.