Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V6XFr-0006xa-DK for pgsql-general@arkaria.postgresql.org; Tue, 06 Aug 2013 02:44:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V6XFq-0006ja-TX for pgsql-general@arkaria.postgresql.org; Tue, 06 Aug 2013 02:44:10 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V6XFp-0006jS-Iz for pgsql-general@postgresql.org; Tue, 06 Aug 2013 02:44:09 +0000 Received: from mail-pb0-x22d.google.com ([2607:f8b0:400e:c01::22d]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V6XFm-0008UI-8h for pgsql-general@postgresql.org; Tue, 06 Aug 2013 02:44:09 +0000 Received: by mail-pb0-f45.google.com with SMTP id mc17so4121980pbc.4 for ; Mon, 05 Aug 2013 19:44:05 -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:x-mailer; bh=rXH+SYD8aIwp30dYv5tqegFaML7nEQHYYz/I3uVKJhQ=; b=dlf9bgWzu4JNAdq/Jp21DpJgPE7VLWC20VSklMqFsJ75GHgicnrRCoWHu641LDmb7+ 5Uo9Fp+j9R4TBcRE/7Et0TlC3UYVv/G+57duLTl+USqmMjcSoiuko5u5pIpOXQEHYyCK 4WdiiPPsiT3uiUoJZ1Ck8lDPyLbK8YbRcTLUmhMyAa0oIOif9gdSNkKZk+JNMazoxRLy /9xLH/i+juSHgnzCGYlTocSeA4RHfKxE2MsFtdK4OhtpWNYIzGuqR2VkVFSk49d0eZD2 yymnTRp1HFoTaJ84YjkSloQIYhTle9/9TKMjdMcFFpnthwLUeics+3/UiCc6WsNaNUKx 7W9A== X-Received: by 10.68.137.134 with SMTP id qi6mr25436716pbb.154.1375757045069; Mon, 05 Aug 2013 19:44:05 -0700 (PDT) Received: from [192.168.0.102] (014136185055.ctinets.com. [14.136.185.55]) by mx.google.com with ESMTPSA id ep4sm2096199pbd.35.2013.08.05.19.44.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 Aug 2013 19:44:04 -0700 (PDT) Subject: pg_stat_replication became empty suddenly Mime-Version: 1.0 (Apple Message framework v1085) Content-Type: multipart/alternative; boundary=Apple-Mail-33-165366207 From: "ascot.moss@gmail.com" In-Reply-To: Date: Tue, 6 Aug 2013 10:44:00 +0800 Cc: acscot.moss@gmail.com Message-Id: 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: -0.1 (/) 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-33-165366207 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 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.=20 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 How to reproduce: 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; 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) 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 ---------- (0 rows) 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) 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) . . . 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) --Apple-Mail-33-165366207 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii 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-33-165366207--