Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V6Z3O-00035I-46 for pgsql-general@arkaria.postgresql.org; Tue, 06 Aug 2013 04:39:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V6Z3N-0001E4-7i for pgsql-general@arkaria.postgresql.org; Tue, 06 Aug 2013 04:39:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V6Z3L-0001Dw-Tw for pgsql-general@postgresql.org; Tue, 06 Aug 2013 04:39:24 +0000 Received: from mail-pd0-x229.google.com ([2607:f8b0:400e:c02::229]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V6Z3J-000074-1W for pgsql-general@postgresql.org; Tue, 06 Aug 2013 04:39:23 +0000 Received: by mail-pd0-f169.google.com with SMTP id y11so4112974pdj.28 for ; Mon, 05 Aug 2013 21:39:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:mime-version:content-type:from:in-reply-to:date:cc :message-id:references:to; bh=Fv46vSd0EYVB0D+BEMFMSmxXrySPAp8FG14oE9x15jg=; b=eP9i6Cs07OSSYuXhZ91qmKL8/nqOkDerUlKupxJDT0vG59EXbUq4vrH1keg2TWxULz JVMk+pM9QqaNLXfbL+j8hWz4uHhS0fvSbn4uT8k3H1k9AEdU6rPX/GuVmn7stcmQ5Du2 oaj/8QtJK8Pr+jdF9atALjYIyqwoOmettBAydG5iHVHYSQdXRhNKrfGeFrRTBGaYZmOQ IUGKRIprO26Xo6ybG9Zal54DDk8dDDlyKBBtwezLUM2XPcKEW5mu/feBhC1lj2PpVTC4 mAPkpC9n21yRDp+0CTFw4uA/yaGpHC3gcbcfaKQRRcR8bK0BdTh97dZDXAdk0PuzwUbd c+Qg== X-Received: by 10.66.246.106 with SMTP id xv10mr1023861pac.100.1375763959233; Mon, 05 Aug 2013 21:39:19 -0700 (PDT) Received: from [192.168.0.102] (014136185055.ctinets.com. [14.136.185.55]) by mx.google.com with ESMTPSA id ue9sm1425810pab.7.2013.08.05.21.39.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 Aug 2013 21:39:18 -0700 (PDT) Subject: Re: pg_stat_replication became empty suddenly Mime-Version: 1.0 (Apple Message framework v1085) Content-Type: multipart/alternative; boundary=Apple-Mail-34-172280841 From: "ascot.moss@gmail.com" In-Reply-To: Date: Tue, 6 Aug 2013 12:39:15 +0800 Cc: ascot.moss@gmail.com Message-Id: <57DC0F7E-C959-462D-874F-3EEA49702EC8@gmail.com> References: <8810.1375247630@sss.pgh.pa.us> <2EB17B60-33A2-4855-A176-0E8DD16ED7E1@gmail.com> <10906.1375273486@sss.pgh.pa.us> To: PostgreSQL general X-Mailer: Apple Mail (2.1085) X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org --Apple-Mail-34-172280841 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi, I found the problem should be because I tried to clean RAM cache in the = slave by running "sync; echo 3 > /proc/sys/vm/drop_caches'=20 that caused the "receiver" of slave gone away. ps -ef | grep receiver postgres 6182 6178 0 12:11 ? 00:00:06 postgres: wal = receiver process streaming D/FB8DA000 =20 sync; echo 3 > /proc/sys/vm/drop_caches ps -ef | grep receiver root 8804 30447 0 12:29 pts/2 00:00:00 grep --color=3Dauto = receiver regards On 6 Aug 2013, at 10:44 AM, ascot.moss@gmail.com wrote: > Hi, >=20 > I am doing some stress tests to a pair of PG servers to monitor the = pg_stat_replication, during the test, the pg_stat_replication suddenly = became empty.=20 >=20 > PG version: 9.2.4 > O/S: Ubuntu: 12.04 >=20 > Since I need to monitor the replication lag from time to time, if the = pg_stat_replication becomes empty, the lag calculation in the slave will = be wrong. > Please advise if this is a bug. >=20 > regards >=20 >=20 >=20 >=20 > How to reproduce: >=20 > session 1: Master server - try to insert a large number of records = into a test table=20 > postgres=3D# drop table test;CREATE TABLE test (id INTEGER PRIMARY = KEY); INSERT INTO test VALUES (generate_series(1,100000000)); EXPLAIN = ANALYZE SELECT COUNT(*) FROM test; >=20 > 2) session 2: Master server - check the byte_lag from time to time > postgres=3D# SELECT > sent_offset - ( > replay_offset - (sent_xlog - replay_xlog) * 255 * 16 ^ 6 ) AS = byte_lag > FROM ( > SELECT > client_addr, > ('x' || lpad(split_part(sent_location, '/', 1), 8, = '0'))::bit(32)::bigint AS sent_xlog, > ('x' || lpad(split_part(replay_location, '/', 1), 8, = '0'))::bit(32)::bigint AS replay_xlog, > ('x' || lpad(split_part(sent_location, '/', 2), 8, = '0'))::bit(32)::bigint AS sent_offset, > ('x' || lpad(split_part(replay_location, '/', 2), 8, = '0'))::bit(32)::bigint AS replay_offset > FROM pg_stat_replication > ) AS s; > byte_lag=20 > ---------- > 2097216 > (1 row) >=20 > postgres=3D# SELECT >=20 > sent_offset - ( > replay_offset - (sent_xlog - replay_xlog) * 255 * 16 ^ 6 ) AS = byte_lag > FROM ( > SELECT > client_addr, > ('x' || lpad(split_part(sent_location, '/', 1), 8, = '0'))::bit(32)::bigint AS sent_xlog, > ('x' || lpad(split_part(replay_location, '/', 1), 8, = '0'))::bit(32)::bigint AS replay_xlog, > ('x' || lpad(split_part(sent_location, '/', 2), 8, = '0'))::bit(32)::bigint AS sent_offset, > ('x' || lpad(split_part(replay_location, '/', 2), 8, = '0'))::bit(32)::bigint AS replay_offset > FROM pg_stat_replication > ) AS s; > byte_lag=20 > ---------- > (0 rows) >=20 >=20 > 3) session 3: Slave server -=20 > postgres=3D# SELECT CASE WHEN pg_last_xlog_receive_location() =3D = pg_last_xlog_replay_location() THEN 0 ELSE EXTRACT (EPOCH FROM now() - = pg_last_xact_replay_timestamp()) END AS log_delay; > log_delay=20 > ----------- > 0 > (1 row) >=20 > postgres=3D# SELECT CASE WHEN pg_last_xlog_receive_location() =3D = pg_last_xlog_replay_location() THEN 0 ELSE EXTRACT (EPOCH FROM now() - = pg_last_xact_replay_timestamp()) END AS log_delay; > log_delay=20 > ----------- > 4.873282 > (1 row) >=20 > . > . > . > postgres=3D# SELECT CASE WHEN pg_last_xlog_receive_location() =3D = pg_last_xlog_replay_location() THEN 0 ELSE EXTRACT (EPOCH FROM now() - = pg_last_xact_replay_timestamp()) END AS log_delay; > log_delay =20 > ------------- > 4070.325329 > (1 row) >=20 >=20 --Apple-Mail-34-172280841 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii sync; echo 3 > = /proc/sys/vm/drop_caches' 
that caused the = "receiver" of slave gone away.

ps -ef | = grep receiver
postgres  6182  6178 =  0 12:11 ?        00:00:06 postgres: wal = receiver process   streaming D/FB8DA000   =  
sync; echo 3 = > /proc/sys/vm/drop_caches
ps -ef | grep = receiver
root      8804 30447  0 12:29 = pts/2    00:00:00 grep --color=3Dauto = receiver

regards

On= 6 Aug 2013, at 10:44 AM, ascot.moss@gmail.com = wrote:

Hi,

I = am doing some stress tests to a pair of PG servers to monitor = the pg_stat_replication, during the test, = the pg_stat_replication suddenly became = empty. 

PG version: 9.2.4
O/S: = Ubuntu: 12.04

Since I need to monitor the = replication lag from time to time, if the pg_stat_replication = becomes empty, the lag calculation in the slave will be = wrong.
Please advise if this is a = bug.

regards


<= div>

How to = reproduce:

session 1: Master server - try = to insert a large number of records into a test = table 
postgres=3D# drop table test;CREATE TABLE = test (id INTEGER PRIMARY KEY); INSERT INTO test VALUES = (generate_series(1,100000000));  EXPLAIN ANALYZE SELECT COUNT(*) = FROM test;

2) session 2: Master server - check = the byte_lag from time to time
postgres=3D# = SELECT
    sent_offset - (
    =     replay_offset - (sent_xlog - replay_xlog) * 255 * 16 ^ 6 ) = AS byte_lag
FROM (
    = SELECT
        = client_addr,
        ('x' || = lpad(split_part(sent_location,   '/', 1), 8, '0'))::bit(32)::bigint = AS sent_xlog,
        ('x' || = lpad(split_part(replay_location, '/', 1), 8, '0'))::bit(32)::bigint AS = replay_xlog,
        ('x' || = lpad(split_part(sent_location,   '/', 2), 8, '0'))::bit(32)::bigint = AS sent_offset,
        ('x' || = lpad(split_part(replay_location, '/', 2), 8, '0'))::bit(32)::bigint AS = replay_offset
    FROM = pg_stat_replication
) AS = s;
byte_lag 
----------
2097216
(1 row)

postgres=3D# = SELECT

    sent_offset - = (
        replay_offset - (sent_xlog - = replay_xlog) * 255 * 16 ^ 6 ) AS byte_lag
FROM = (
    SELECT
        = client_addr,
        ('x' || = lpad(split_part(sent_location,   '/', 1), 8, '0'))::bit(32)::bigint = AS sent_xlog,
        ('x' || = lpad(split_part(replay_location, '/', 1), 8, '0'))::bit(32)::bigint AS = replay_xlog,
        ('x' || = lpad(split_part(sent_location,   '/', 2), 8, '0'))::bit(32)::bigint = AS sent_offset,
        ('x' || = lpad(split_part(replay_location, '/', 2), 8, '0'))::bit(32)::bigint AS = replay_offset
    FROM = pg_stat_replication
) AS = s;
byte_lag 
----------
(0 = rows)


3) session 3: = Slave server - 
postgres=3D# SELECT CASE WHEN = pg_last_xlog_receive_location() =3D pg_last_xlog_replay_location() =  THEN 0 ELSE EXTRACT (EPOCH FROM now() - = pg_last_xact_replay_timestamp()) END AS = log_delay;
 log_delay 
-----------
         0
(1 = row)

postgres=3D# SELECT CASE WHEN = pg_last_xlog_receive_location() =3D pg_last_xlog_replay_location() =  THEN 0 ELSE EXTRACT (EPOCH FROM now() - = pg_last_xact_replay_timestamp()) END AS = log_delay;
 log_delay 
-----------
  4.873282
(1 = row)

.
.
.
postgres=3D# SELECT CASE WHEN pg_last_xlog_receive_location() =3D = pg_last_xlog_replay_location()  THEN 0 ELSE EXTRACT (EPOCH FROM = now() - pg_last_xact_replay_timestamp()) END AS = log_delay;
  log_delay =  
-------------
 4070.325329
(1 = row)


= --Apple-Mail-34-172280841--