public inbox for [email protected]
help / color / mirror / Atom feedFrom: Erik Wienhold <[email protected]>
To: Maiquel Grassi <[email protected]>
Cc: Nathan Bossart <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: Psql meta-command conninfo+
Date: Wed, 7 Feb 2024 10:54:21 +0100
Message-ID: <2quadime4klthrjwamiqmwqizfptoabi74dfjzzs3cjba4j6tp@lqzijrwi6i2o> (raw)
In-Reply-To: <CP8P284MB2496A17A9852265A0F363A6AEC452@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM>
References: <CP8P284MB24965CB63DAC00FC0EA4A475EC462@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM>
<20240206181919.GA3853632@nathanxps13>
<aevq2dxmw2xm2rc3nh2wdcozunipco447mf4rpm7efvqvz4wk2@mo3zmf2ulbzu>
<CP8P284MB2496B51FC5ED9BD6527D459DEC462@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM>
<20240206210605.GA3903769@nathanxps13>
<20240206211205.GA3903996@nathanxps13>
<CP8P284MB24965479BA59DF5C2CC01CA0EC462@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM>
<20240206215022.GA3452@nathanxps13>
<CP8P284MB2496A17A9852265A0F363A6AEC452@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM>
On 2024-02-07 05:13 +0100, Maiquel Grassi wrote:
> On Tue, Feb 06, 2024 at 09:45:54PM +0000, Maiquel Grassi wrote:
> > My initial idea has always been that they should continue to appear
> > because \conninfo+ should show all the things that \conninfo shows and
> > add more information. I think that's the purpose of the 'plus.' Now we're
> > on a better path than the initial one. We can still add the socket
> > directory and the host.
>
> Agreed.
>
> --//--
>
> I believe it's resolved reasonably well this way:
>
> SELECT
> pg_catalog.current_database() AS "Database",
> current_user AS "User",
> pg_catalog.current_setting('server_version') AS "Server Version",
> CASE
> WHEN pg_catalog.inet_server_addr() IS NULL
> THEN 'NULL'
> ELSE pg_catalog.inet_server_addr()::text
> END AS "Server Address",
Should be NULL instead of string 'NULL'. So the entire CASE expression
is redundant and you can just return pg_catalog.inet_server_addr().
> pg_catalog.current_setting('port') AS "Port",
> CASE
> WHEN pg_catalog.inet_client_addr() IS NULL
> THEN 'NULL'
> ELSE pg_catalog.inet_client_addr()::text
> END AS "Client Address",
> CASE
> WHEN pg_catalog.inet_client_port() IS NULL
> THEN 'NULL'
> ELSE pg_catalog.inet_client_port()::text
> END AS "Client Port",
Same here.
> pg_catalog.pg_backend_pid() AS "Session PID",
> CASE
> WHEN pg_catalog.current_setting('unix_socket_directories') = ''
> THEN 'NULL'
> ELSE pg_catalog.current_setting('unix_socket_directories')
> END AS "Socket Directory",
The CASE expression can be simplified to:
nullif(pg_catalog.current_setting('unix_socket_directories'), '')
> CASE
> WHEN
> pg_catalog.inet_server_addr() IS NULL
> AND pg_catalog.inet_client_addr() IS NULL
> THEN 'NULL'
> WHEN
> pg_catalog.inet_server_addr() = pg_catalog.inet_client_addr()
> THEN 'localhost'
Is it safe to assume localhost here? \conninfo prints localhost only
when I connect with psql -hlocalhost:
$ psql -hlocalhost postgres
psql (16.1)
postgres=# \conninfo
You are connected to database "postgres" as user "ewie" on host "localhost" (address "::1") at port "5432".
postgres=# \q
$ psql -h127.0.0.1 postgres
psql (16.1)
postgres=# \conninfo
You are connected to database "postgres" as user "ewie" on host "127.0.0.1" at port "5432".
> ELSE pg_catalog.inet_server_addr()::text
> END AS "Host";
--
Erik
view thread (43+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Psql meta-command conninfo+
In-Reply-To: <2quadime4klthrjwamiqmwqizfptoabi74dfjzzs3cjba4j6tp@lqzijrwi6i2o>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox