Adding %S to psql: Showing the Current search_path in Your Prompt
One of the small but satisfying joys of contributing to PostgreSQL is when you get to add something that makes everyday developer life a little smoother — a quality-of-life improvement that you’ll use dozens of times a day without even noticing.
This week I contributed such a patch to psql, PostgreSQL’s interactive
terminal: a new prompt escape called %S, which displays the current
search_path directly in your prompt.
In PostgreSQL, the search_path determines the order in which schemas are
searched when you reference a table, function, or type without schema
qualification.
For example:
SET search_path TO public, extensions;
SELECT * FROM users;
In this case, PostgreSQL will first look for users in public, then in
extensions.
It’s an important session-level setting, but one that can silently affect your queries — especially if you work with multiple schemas, extensions, or temporary tables.
Until now, there was no easy way to see the current search_path in your
psql prompt. You could run:
SHOW search_path;
…or rely on muscle memory — but when jumping between connections, scripts, or environments, that can be error-prone.
With this patch, you can now include %S in your PROMPT1, PROMPT2, or
PROMPT3 definitions to show the active search path.
For example, in your ~/.psqlrc:
\set PROMPT1 '%n@%/%R%# [%S] '
Now, every time you connect, you’ll see something like:
florents@testdb=> [public, extensions]
Change the path:
SET search_path TO myschema;
and your prompt updates instantly:
florents@testdb=> [myschema]
If you work with multiple schemas — for example, multitenant setups, extension
development, or testing environments — having the search_path visible right in
your prompt can prevent subtle bugs and wrong-schema inserts.
It’s a small patch, but one that makes every session just a little more transparent.
This feature works with PostgreSQL 18 and later should be available in PostgreSQL 19; expected to be released in September 2026.
Behaviour note: 
The %S escape depends on the server sending the search_path parameter status 
— that requires that search_path be marked with the GUC_REPORT flag (commit 28a1121). 
That flag was added in the PostgreSQL 18 development series, 
so the feature really takes effect only when connected to a server built from PostgreSQL 18 or later. 
On older server versions (which don’t report search_path), 
psql will substitute a ? in place of %S.
Thanks to the reviewers for their feedback and suggestions on this patch, to Nathan Bossart for reviewing & comitting it, and to Lauri Siltanen for proposing it.