Add %r substitution for psql prompts to show recovery status - Mailing list pgsql-hackers

From Ian Barwick
Subject Add %r substitution for psql prompts to show recovery status
Date
Msg-id 3a40f835-116d-0f95-aede-d5236337bbf0@2ndquadrant.com
Whole thread Raw
Responses Re: Add %r substitution for psql prompts to show recovery status
Re: Add %r substitution for psql prompts to show recovery status
List pgsql-hackers
Hi

Attached patch adds an "%r" substitution for psql prompts to show
recovery status. Specifically it displays an "&" (ampersand) if
the server is in recovery, otherwise nothing, e.g.:

     postgres=&# SELECT foo;

Why is this useful? Because I find myself messing about with replication
clusters a lot, and it would be nice to have an at-a-glance confirmation
whether I'm connected to a standby or not.

Why an ampersand? Because it's not used for any other prompts, and
it can be used as a mnemonic: "and" -> "st'and'by" (clutching at
straws a bit there I admit, but best I could come up with).

Note this substitution sends a "pg_is_in_recovery()" query to the server
each time it's encountered; unless there's something I'm overlooking I
think that's the only reliable way to determine current recovery status.
A possible alternative would be only to check the status each time a new
database connection is made, but that wouldn't catch the case where the
server has been promoted.

Will submit to next commitfest.


Regards

Ian Barwick

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

Attachment

pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Re: User defined data types in Logical Replication
Next
From: Robert Haas
Date:
Subject: Re: pgsql: When VACUUM or ANALYZE skips a concurrently dropped table,log i