Re: (replication) Detecting if server a slave, or a master in recovery

From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Toby Corkindale <toby(dot)corkindale(at)strategicdata(dot)com(dot)au>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: (replication) Detecting if server a slave, or a master in recovery
Date: 2011-09-12 07:13:29
Message-ID: CA+U5nMKYs3t31TkXtejKPn-JnUKJFbABA4=f57rOGkLqgWnXmA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Sep 12, 2011 at 7:54 AM, Toby Corkindale
<toby(dot)corkindale(at)strategicdata(dot)com(dot)au> wrote:

> What is the correct way to tell what mode a replicated Pg server is
> currently in, via a database connection?
>
> I can take a guess if it's the master or a slave by using the
> pg_current_xlog_location() and pg_last_xlog_replay_location() functions.
>
> However it occurs to me that a master server, which has been roughly
> rebooted and is replaying its WAL files will probably give the same response
> as a slave, when I call the current_xlog_location().
>
>
> What is the best method for determining whether you're connected to the
> master or slave database?

SELECT pg_is_in_recovery();

--
 Simon Riggs                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Toby Corkindale 2011-09-12 07:19:34 Re: (replication) Detecting if server a slave, or a master in recovery
Previous Message Toby Corkindale 2011-09-12 07:09:53 Re: (replication) Detecting if server a slave, or a master in recovery