Skip to content

Instantly share code, notes, and snippets.

@qdw
Created March 15, 2011 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qdw/870109 to your computer and use it in GitHub Desktop.
Save qdw/870109 to your computer and use it in GitHub Desktop.
# Include the role (MASTER versus SLAVE) in your bash prompt. For example:
#
# quinn@tao (MASTER) ~$
#
# I use this to remind myself which node is which during failover testing. Helpfully, this also
# tells you if both nodes think they're the master (or the slave). Either can happen if
# replication gets into a bad state.
#
# Assumptions:
# - psql is in your path.
# - You have your ~/.pgpass set up so that you can log in automatically.
export PS1="\u@\h ($(psql -Atc "SELECT CASE WHEN pg_is_in_recovery() THEN 'SLAVE' ELSE 'MASTER' END")) \w\\$ "
# Explanation:
# \u expands to your username.
# \h expands to the hostname (the host part only, not the FQDN).
# \w expands to the working directory.
# \\$ expands to # if you're root and $ otherwise.
# $(psql...) expands to the result of that command, i.e. MASTER or SLAVE.
# All else is literal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment