Re: Psql meta-command conninfo+

Jim Jones <jim.jones@uni-muenster.de>

From: Jim Jones <jim.jones@uni-muenster.de>
To: Maiquel Grassi <grassi@hotmail.com.br>, Pavel Luzanov <p.luzanov@postgrespro.ru>, Nathan Bossart <nathandbossart@gmail.com>
Cc: Erik Wienhold <ewie@ewie.name>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2024-02-08T19:37:38Z
Lists: pgsql-hackers
On 08.02.24 16:50, Maiquel Grassi wrote:
> Hi Jim,
> Thank you for your support on this patch!
> As I believe in its usability, I have been dedicating efforts to make
> it really interesting.
> I hadn't thought about the permissioning issue for
> "unix_socket_directories". I appreciate that.
> I thought about solving this situation using the same approach as
> \conninfo. I added the validation if (is_unixsock_path(host) &&
> !(hostaddr && *hostaddr)) in the SQL part along with an "append". In
> case of a negative result, another "append" adds NULL.
> Regarding the whitespace issue, before generating v8 patch file, I
> used pgindent to adjust each modified file. I believe it should be ok
> now. If you could verify, I'd be grateful.
> Below are the tests after adjusting for the permissioning issues:
>
> [postgres@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
>  Database | Authenticated User | System User | Current User | Session
> User | Session PID | Server Version | Server Address | Server Port |
> Client Address | Client Port | Socket Directory | Host
> ----------+--------------------+-------------+--------------+--------------+-------------+----------------+----------------+-------------+----------------+-------------+------------------+------
>  postgres | postgres           |             | postgres     | postgres
>     |       31479 | 17devel        |                | 5432        |  
>              |             | /tmp             |
> (1 row)
>
> postgres=# CREATE USER maiquel;
> CREATE ROLE
> postgres=# \q
> [postgres@localhost bin]$ ./psql -U maiquel -d postgres
> psql (17devel)
> Type "help" for help.
>
> postgres=> \conninfo
> You are connected to database "postgres" as user "maiquel" via socket
> in "/tmp" at port "5432".
> postgres=> \conninfo+
>                                                                      
>             Current Connection Information
>  Database | Authenticated User | System User | Current User | Session
> User | Session PID | Server Version | Server Address | Server Port |
> Client Address | Client Port | Socket Directory | Host
> ----------+--------------------+-------------+--------------+--------------+-------------+----------------+----------------+-------------+----------------+-------------+------------------+------
>  postgres | maiquel            |             | maiquel      | maiquel
>      |       31482 | 17devel        |                | 5432        |  
>              |             | /tmp             |
> (1 row)
>
> postgres=> \q
> [postgres@localhost bin]$ ./psql -h localhost -U maiquel -d postgres
> psql (17devel)
> Type "help" for help.
>
> postgres=> \conninfo
> You are connected to database "postgres" as user "maiquel" on host
> "localhost" (address "::1") at port "5432".
> postgres=> \conninfo+
>                                                                      
>               Current Connection Information
>  Database | Authenticated User | System User | Current User | Session
> User | Session PID | Server Version | Server Address | Server Port |
> Client Address | Client Port | Socket Directory |   Host
> ----------+--------------------+-------------+--------------+--------------+-------------+----------------+----------------+-------------+----------------+-------------+------------------+-----------
>  postgres | maiquel            |             | maiquel      | maiquel
>      |       31485 | 17devel        | ::1            | 5432        |
> ::1            |       47482 |                  | localhost
> (1 row)
>
> postgres=> \q
> [postgres@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
>  Database | Authenticated User | System User | Current User | Session
> User | Session PID | Server Version | Server Address | Server Port |
> Client Address | Client Port | Socket Directory |   Host
> ----------+--------------------+-------------+--------------+--------------+-------------+----------------+----------------+-------------+----------------+-------------+------------------+-----------
>  postgres | postgres           |             | postgres     | postgres
>     |       31488 | 17devel        | ::1            | 5432        |
> ::1            |       47484 |                  | localhost
> (1 row)
>
> Regards,
> Maiquel.

v8 no longer throws a permission denied error for non-superusers - it is
IMHO much nicer this way.

$ /usr/local/postgres-dev/bin/psql postgres -p 5432 -h 127.0.0.1 -U jim
psql (17devel)
Type "help" for help.

postgres=# \x
Expanded display is on.
postgres=# \conninfo+
Current Connection Information
-[ RECORD 1 ]------+----------
Database           | postgres
Authenticated User | jim
System User        |
Current User       | jim
Session User       | jim
Session PID        | 1321493
Server Version     | 17devel
Server Address     | 127.0.0.1
Server Port        | 5432
Client Address     | 127.0.0.1
Client Port        | 49366
Socket Directory   |
Host               | 127.0.0.1

postgres=# SET ROLE foo;
SET
postgres=> \conninfo+
Current Connection Information
-[ RECORD 1 ]------+----------
Database           | postgres
Authenticated User | jim
System User        |
Current User       | foo
Session User       | jim
Session PID        | 1321493
Server Version     | 17devel
Server Address     | 127.0.0.1
Server Port        | 5432
Client Address     | 127.0.0.1
Client Port        | 49366
Socket Directory   |
Host               | 127.0.0.1


The patch now applies cleanly.

One thing I just noticed. The psql autocomplete feature does not suggest
the new + option of \conninfo. For instance, when typing "\connin[TAB]"
it automatically autocompletes to "\conninfo ". I guess it should also
be included in this patch.

I can do a more thorough review of the code when you add the
documentation and tests to the patch.

Thanks!

-- 
Jim




Commits

  1. psql: Change new \conninfo to use SSL instead of TLS

  2. Change \conninfo to use tabular format

  3. Update extension lookup routines to use the syscache

  4. Improve COPY TO performance when server and client encodings match

  5. doc: Remove superfluous bracket in synopsis

  6. Remove psql support for server versions preceding 9.2.