Waiting for PostgreSQL 19 – Add psql PROMPT variable for search_path.

On 28th of October 2025, Nathan Bossart committed patch:

Add psql PROMPT variable for search_path.
 
The new %S substitution shows the current value of search_path.
Note that this only works when connected to Postgres v18 or newer,
since search_path was first marked as GUC_REPORT in commit
28a1121fd9.  On older versions that don't report search_path, %S is
replaced with a question mark.
 
Suggested-by: Lauri Siltanen <lauri.siltanen@gmail.com>
Author: Florents Tselai <florents.tselai@gmail.com>
Reviewed-by: Jelte Fennema-Nio <postgres@jeltef.nl>
Reviewed-by: Jim Jones <jim.jones@uni-muenster.de>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/CANsM767JhTKCRagTaq5Lz52fVwLPVkhSpyD1C%2BOrridGv0SO0A%40mail.gmail.com

Not a lot of people customize their psql. But for others, like me, there is yet another thing we can do: put search_path in prompt.

Basically, it looks like this:

depesz=# \echo :PROMPT1
%/%R%x%#
 
depesz=# \set PROMPT1 '[%S] %/%R%x%# '
 
["$user", public] depesz=# set search_path = 'public, pg_catalog';
SET
 
["public, pg_catalog"] depesz=# set search_path = public, pg_catalog;
SET
 
[public, pg_catalog] depesz=#

All clear, easy to understand. Of course, it will mostly make sense if you actually use search_path – either by setting it manually, or by setting it for db, for user, or for user in db.

That will definitely come in handy – my $work has dbs with hundreds of schemas, and we change search_path every time we have to query some table, otherwise queries would get tedious to type pretty fast.

Thanks a lot to everyone involved 🙂

One thought on “Waiting for PostgreSQL 19 – Add psql PROMPT variable for search_path.”

  1. Yes, finally! I set up prompts in work, so people can see which server they are logged in, which environment it is (prod/staging/dev), but there was no easy way to show current search path.

    Having public in there is kind of unnecessary, so hopefully it will be possible to remove it.

Comments are closed.