pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedstrem replication standby lag check
3+ messages / 3 participants
[nested] [flat]
* strem replication standby lag check
@ 2014-01-17 19:16 yhe <yinghe0101@yahoo.com>
2014-01-20 12:33 ` Re: strem replication standby lag check desmodemone <desmodemone@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: yhe @ 2014-01-17 19:16 UTC (permalink / raw)
To: pgsql-admin
hi, all,
I know we can connect to primary and SELECT pg_current_xlog_location(); (eg.
'0/36A77900') to get primary xlog position then connect to the standby to do
the following to get the byte lag:
select pg_xlog_location_diff('0/36A77900',pg_last_xlog_replay_location());
0/36A77900 is the xlog position from primary.
My question is that is there a way I can connect to the primary on the
standby host using replica user which i already have the primary_conninfo in
the recovery.conf and get the result of SELECT pg_current_xlog_location();
of the primary so I can simply write a function on the standby to return the
lag in bytes in one call.
any way I can do that without a dblink?
Thank you if any one can help.
best,
Ying
--
View this message in context: http://postgresql.1045698.n5.nabble.com/strem-replication-standby-lag-check-tp5787682.html
Sent from the PostgreSQL - admin mailing list archive at Nabble.com.
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: strem replication standby lag check
2014-01-17 19:16 strem replication standby lag check yhe <yinghe0101@yahoo.com>
@ 2014-01-20 12:33 ` desmodemone <desmodemone@gmail.com>
2014-01-21 02:32 ` Re: strem replication standby lag check Sergey Konoplev <gray.ru@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: desmodemone @ 2014-01-20 12:33 UTC (permalink / raw)
To: yhe <yinghe0101@yahoo.com>; +Cc: pgsql-admin
I think it's better to use the pg_stat_replication
2014/1/17 yhe <yinghe0101@yahoo.com>
> hi, all,
>
> I know we can connect to primary and SELECT pg_current_xlog_location();
> (eg.
> '0/36A77900') to get primary xlog position then connect to the standby to
> do
> the following to get the byte lag:
>
> select pg_xlog_location_diff('0/36A77900',pg_last_xlog_replay_location());
>
> 0/36A77900 is the xlog position from primary.
>
> My question is that is there a way I can connect to the primary on the
> standby host using replica user which i already have the primary_conninfo
> in
> the recovery.conf and get the result of SELECT pg_current_xlog_location();
> of the primary so I can simply write a function on the standby to return
> the
> lag in bytes in one call.
>
> any way I can do that without a dblink?
>
> Thank you if any one can help.
>
> best,
> Ying
>
>
>
>
>
> --
> View this message in context:
> http://postgresql.1045698.n5.nabble.com/strem-replication-standby-lag-check-tp5787682.html
> Sent from the PostgreSQL - admin mailing list archive at Nabble.com.
>
>
> --
> Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-admin
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: strem replication standby lag check
2014-01-17 19:16 strem replication standby lag check yhe <yinghe0101@yahoo.com>
2014-01-20 12:33 ` Re: strem replication standby lag check desmodemone <desmodemone@gmail.com>
@ 2014-01-21 02:32 ` Sergey Konoplev <gray.ru@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Sergey Konoplev @ 2014-01-21 02:32 UTC (permalink / raw)
To: desmodemone <desmodemone@gmail.com>; +Cc: yhe <yinghe0101@yahoo.com>; pgsql-admin
> 2014/1/17 yhe <yinghe0101@yahoo.com>
>> any way I can do that without a dblink?
>>
On Mon, Jan 20, 2014 at 4:33 AM, desmodemone <desmodemone@gmail.com> wrote:
> I think it's better to use the pg_stat_replication
+1
And this is how to make all the calculation of the lag (in bytes):
CREATE OR REPLACE FUNCTION hex_to_int(i_hex text, OUT o_dec integer)
RETURNS integer LANGUAGE 'plpgsql' IMMUTABLE STRICT AS $$
BEGIN
EXECUTE 'SELECT x''' || i_hex || '''::integer' INTO o_dec;
RETURN;
END $$;
SELECT
client_addr,
sent_offset - (
replay_offset - (sent_xlog - replay_xlog) * 255 * 16 ^ 6 ) AS byte_lag
FROM (
SELECT
client_addr,
hex_to_int(split_part(sent_location, '/', 1)) AS sent_xlog,
hex_to_int(split_part(replay_location, '/', 1)) AS replay_xlog,
hex_to_int(split_part(sent_location, '/', 2)) AS sent_offset,
hex_to_int(split_part(replay_location, '/', 2)) AS replay_offset
FROM pg_stat_replication
) AS s;
--
Kind regards,
Sergey Konoplev
PostgreSQL Consultant and DBA
http://www.linkedin.com/in/grayhemp
+1 (415) 867-9984, +7 (901) 903-0499, +7 (988) 888-1979
gray.ru@gmail.com
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2014-01-21 02:32 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-01-17 19:16 strem replication standby lag check yhe <yinghe0101@yahoo.com>
2014-01-20 12:33 ` desmodemone <desmodemone@gmail.com>
2014-01-21 02:32 ` Sergey Konoplev <gray.ru@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox