RE: Psql meta-command conninfo+

From: Maiquel Grassi <grassi(at)hotmail(dot)com(dot)br>
To: Erik Wienhold <ewie(at)ewie(dot)name>, Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: RE: Psql meta-command conninfo+
Date: 2024-02-06 20:52:09
Message-ID: CP8P284MB2496B51FC5ED9BD6527D459DEC462@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2024-02-06 19:19 +0100, Nathan Bossart wrote:
> On Tue, Feb 06, 2024 at 05:27:01PM +0000, Maiquel Grassi wrote:
> > postgres=# \conninfo+
> > Current Connection Information
> > Attribute | Value
> > ----------------+----------------
> > Database | postgres
> > User | postgres
> > Server Version | 16.1
> > Server Address | 192.168.0.5/32
> > Server Port | 5433
> > Client Address | 192.168.0.5/32
> > Client Port | 52716
> > Session PID | 21624
> > (8 rows)
>
> My first reaction is that this should instead return a single row with the
> same set of columns for any connection type (the not-applicable ones would
> just be set to NULL). That would match the other meta-commands like \l and
> \du, and you could still get an expanded display with \x if needed. Also,
> I think it would simplify the code a bit.

+1 for a single-row result and triggering expanded display with \x for
consistency with other commands.

--//--

I made the adjustment in the code and updated the patch. I believe this is the format suggested by you all. Would this be it?

[postgres(at)localhost bin]$ ./psql -h 192.168.0.220 -p 5433 -U postgres -d postgres
psql (17devel, server 16.1)
Type "help" for help.

postgres=# \conninfo
You are connected to database "postgres" as user "postgres" on host "192.168.0.220" at port "5433".
postgres=# \conninfo+
Current Connection Information
Attribute | Value
----------------+------------------
Database | postgres
User | postgres
Server Version | 16.1
Server Address | 192.168.0.220/32
Server Port | 5433
Client Address | 192.168.0.220/32
Client Port | 56606
Session PID | 2424
(8 rows)

[postgres(at)localhost bin]$ ./psql
psql (17devel)
Type "help" for help.

postgres=# \conninfo
You are connected to database "postgres" as user "postgres" via socket in "/tmp" at port "5432".
postgres=# \conninfo+
Current Connection Information
Attribute | Value
----------------+----------
Database | postgres
User | postgres
Server Version | 17devel
Server Address |
Server Port | 5432
Client Address |
Client Port |
Session PID | 30216
(8 rows)

[postgres(at)localhost bin]$ ./psql -h localhost
psql (17devel)
Type "help" for help.

postgres=# \conninfo
You are connected to database "postgres" as user "postgres" on host "localhost" (address "::1") at port "5432".
postgres=# \conninfo+
Current Connection Information
Attribute | Value
----------------+----------
Database | postgres
User | postgres
Server Version | 17devel
Server Address | ::1/128
Server Port | 5432
Client Address | ::1/128
Client Port | 46872
Session PID | 30220
(8 rows)

[postgres(at)localhost bin]$ ./psql -h 127.0.0.1
psql (17devel)
Type "help" for help.

postgres=# \conninfo
You are connected to database "postgres" as user "postgres" on host "127.0.0.1" at port "5432".
postgres=# \conninfo+
Current Connection Information
Attribute | Value
----------------+--------------
Database | postgres
User | postgres
Server Version | 17devel
Server Address | 127.0.0.1/32
Server Port | 5432
Client Address | 127.0.0.1/32
Client Port | 34924
Session PID | 30223
(8 rows)

Regards,
Maiquel O. Grassi.

Attachment Content-Type Size
v2-0001-psql-meta-command-conninfo-plus.patch application/octet-stream 7.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2024-02-06 20:53:05 Re: glibc qsort() vulnerability
Previous Message Nathan Bossart 2024-02-06 20:37:25 Re: Remove Start* macros from postmaster.c to ease understanding of code