how to tell master from replica

Started by Scott Ribeover 12 years ago5 messagesgeneral
Jump to latest
#1Scott Ribe
scott_ribe@elevated-dev.com

Assuming a master & replica set up using streaming replication, hot standby, 9.3.

I'd like to have a single script on both machines distinguish whether it's running on the machine with the master or replica, and take different actions accordingly.

Is the way to do this to check for the presence of wal sender process vs wal receiver process? Or is there a query that could executed against sys tables to find current running config of the local postmaster?

--
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#2bricklen
bricklen@gmail.com
In reply to: Scott Ribe (#1)
Re: how to tell master from replica

On Wed, Sep 25, 2013 at 4:53 PM, Scott Ribe <scott_ribe@elevated-dev.com>wrote:

Assuming a master & replica set up using streaming replication, hot
standby, 9.3.

I'd like to have a single script on both machines distinguish whether it's
running on the machine with the master or replica, and take different
actions accordingly.

Is the way to do this to check for the presence of wal sender process vs
wal receiver process? Or is there a query that could executed against sys
tables to find current running config of the local postmaster?

Would pg_is_in_backup() do the job?

http://www.postgresql.org/docs/9.3/static/functions-admin.html#FUNCTIONS-ADMIN-BACKUP

#3Michael Paquier
michael@paquier.xyz
In reply to: Scott Ribe (#1)
Re: how to tell master from replica

On Thu, Sep 26, 2013 at 8:53 AM, Scott Ribe <scott_ribe@elevated-dev.com> wrote:

Assuming a master & replica set up using streaming replication, hot standby, 9.3.

I'd like to have a single script on both machines distinguish whether it's running on the machine with the master or replica, and take different actions accordingly.

Is the way to do this to check for the presence of wal sender process vs wal receiver process? Or is there a query that could executed against sys tables to find current running config of the local postmaster?

"SELECT pg_is_in_recovery();" can be used to make the difference
between a master and a slave.
--
Michael

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#4bricklen
bricklen@gmail.com
In reply to: bricklen (#2)
Re: how to tell master from replica

On Wed, Sep 25, 2013 at 5:11 PM, bricklen <bricklen@gmail.com> wrote:

On Wed, Sep 25, 2013 at 4:53 PM, Scott Ribe <scott_ribe@elevated-dev.com>wrote:

Assuming a master & replica set up using streaming replication, hot
standby, 9.3.

I'd like to have a single script on both machines distinguish whether
it's running on the machine with the master or replica, and take different
actions accordingly.

Is the way to do this to check for the presence of wal sender process vs
wal receiver process? Or is there a query that could executed against sys
tables to find current running config of the local postmaster?

Would pg_is_in_backup() do the job?

http://www.postgresql.org/docs/9.3/static/functions-admin.html#FUNCTIONS-ADMIN-BACKUP

Sorry, meant "pg_is_in_recovery()". (Michael's response tipped me off)

#5Scott Ribe
scott_ribe@elevated-dev.com
In reply to: Michael Paquier (#3)
Re: how to tell master from replica

On Sep 25, 2013, at 6:13 PM, Michael Paquier <michael.paquier@gmail.com> wrote:

"SELECT pg_is_in_recovery();" can be used to make the difference
between a master and a slave.

Exactly what I need; thanks.

--
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general