Re: strem replication standby lag check

From: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
To: desmodemone <desmodemone(at)gmail(dot)com>
Cc: yhe <yinghe0101(at)yahoo(dot)com>, "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: strem replication standby lag check
Date: 2014-01-21 02:32:02
Message-ID: CAL_0b1vy1MezdWNvJaNTBKR0ZOxeULwgTtnA9KejKdvm9eAuJQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

> 2014/1/17 yhe <yinghe0101(at)yahoo(dot)com>
>> any way I can do that without a dblink?
>>

On Mon, Jan 20, 2014 at 4:33 AM, desmodemone <desmodemone(at)gmail(dot)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(dot)ru(at)gmail(dot)com

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message 杨涛涛 2014-01-21 10:13:38 回复: pg_ctl promote
Previous Message desmodemone 2014-01-20 12:33:48 Re: strem replication standby lag check