Re: pg_stat_replication in 9.3

From: Andy Colson <andy(at)squeakycode(dot)net>
To: Torsten Förtsch <torsten(dot)foertsch(at)gmx(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: pg_stat_replication in 9.3
Date: 2014-09-14 14:24:19
Message-ID: 5415A513.6010806@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 09/14/2014 07:03 AM, Torsten Förtsch wrote:
> Hi,
>
> I noticed a strange behaviour regarding pg_stat_replication in 9.3. If
> called from psql using the \watch command, I see all my replicas. From
> time to time one of them drops out and reconnects in a short period of
> time, typically ~30 sec.
>
> If I use the same select in plpgsql like:
>
> FOR r in SELECT application_name,
> client_addr,
> flush_location, clock_timestamp() AS lmd
> FROM pg_stat_replication
> ORDER BY application_name, client_addr
> LOOP
> RAISE NOTICE 'aname=%, ca=%, lmd=%, loc=%, cur=%, lag=%',
> r.application_name, r.client_addr, r.lmd,
> r.flush_location,
> pg_current_xlog_location(),
> pg_size_pretty(
> pg_xlog_location_diff(
> pg_current_xlog_location(),
> r.flush_location
> )
> );
> END LOOP;
>
> I see one of the replicas dropping out but never coming back again while
> in a parallel session using psql and \watch it indeed does come back.
>
> Is that intended?
>
> Torsten
>
>

I wonder if its a transaction thing? Maybe \watch is using a transaction for each (or isn't using transactions at all), whereas the plpgsql is one long transaction?

Also if one of your replicas is far away, it doesn't really surprise me that it might loose connection every once and a while. On the other hand, if the box is on the same subnet, right next to the master, and it was loosing connection, that would be a bad thing.

So, how far away is the replica? And does 'ps ax|grep postgr' show 'idle' or 'idle in transaction' on the \watch and the plpgsql?

-Andy

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Torsten Förtsch 2014-09-14 14:59:07 Re: pg_stat_replication in 9.3
Previous Message Tom Lane 2014-09-14 13:54:14 Re: 2 left joins causes seqscan