Re: [PATCH] Add support for displaying database service in psql prompt

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Noah Misch <noah@leadboat.com>
Cc: Michael Banck <mbanck@gmx.net>, Greg Sabino Mullane <htamfids@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-07-07T02:06:06Z
Lists: pgsql-hackers

Attachments

On Sun, Jul 06, 2025 at 09:13:19AM -0700, Noah Misch wrote:
> This new PQservice() function from commit 4b99fed75 came up in the annual
> exports.txt diff.  The standard in libpq has been to not clutter the API with
> new functions that simply retrieve one PQconninfoOption value.  PQconninfo()
> provides access to all those values in a generic way.  What do you think of
> making psql use PQconninfo() for this, then removing PQservice()?  The rest of
> the commit (adding the struct field, necessary for PQconninfo() to include the
> value) looks good.

Sure, I was not aware of such a policy.  Relying on PQconninfoOption
is less efficient because we would need to look through the whole set
of options when looking for the service name, and this needs one extra
allocation as PQconninfoFree() frees the values allocated.  With two
callers perhaps this inefficiency is OK to live with anyway.

What do you think about the attached, then?
--
Michael

Commits

  1. libpq: Remove PQservice()

  2. psql: Add more information about service name

  3. libpq: Add service name to PGconn and PQservice()