Last active
November 10, 2015 05:16
-
-
Save dpirotte/3ad9986a641fc19da9e7 to your computer and use it in GitHub Desktop.
Find replication lag in SQL without user defined functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with primary_server as ( | |
select split_part(x.full,'/',1) as xlog, | |
split_part(x.full,'/',2) as offset | |
from (select '88DC/113BBDA0'::text as full) x | |
), | |
standby_server as ( | |
select split_part(x.full,'/',1) as xlog, | |
split_part(x.full,'/',2) as offset | |
from (select '88DB/113BBDA0'::text as full) x | |
) | |
select | |
( | |
x'FF000000'::bigint | |
* (format('x%s',lpad(primary_server.xlog,8,'0')))::bit(32)::bigint | |
+ (format('x%s',lpad(primary_server.offset,8,'0')))::bit(32)::bigint | |
) - ( | |
x'FF000000'::bigint | |
* (format('x%s',lpad(standby_server.xlog,8,'0')))::bit(32)::bigint | |
+ (format('x%s',lpad(standby_server.offset,8,'0')))::bit(32)::bigint | |
) | |
FROM primary_server, standby_server; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment