Re: Psql meta-command conninfo+
Hi, I have attached a new patch that incorporates the approach suggested by David. The documentation has also been updated. $ bin/psql "port=5430 sslmode=disable dbname=postgres" -x -h localhost psql (18devel) Type "help" for help. postgres=# \conninfo+ Connection Information -[ RECORD 1 ]+-- Database | postgres Client User | hunaid Host | localhost Host Address | 127.0.0.1 Port | 5430 Options | Current Status -[ RECORD 1 ]+-- Protocol Version | 3 Password Used| false GSSAPI Authenticated | false Backend PID | 26268 Server Parameter Settings -[ RECORD 1 ]-+--- Superuser | true Client Encoding | UTF8 Server Encoding | UTF8 Session Authorization | hunaid Connection Encryption -[ RECORD 1 ]--+-- SSL Connection | false $ bin/psql "port=5430 sslmode=require dbname=postgres" -x -h localhost psql (18devel) SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: postgresql) Type "help" for help. postgres=# \conninfo+ E Connection Encryption -[ RECORD 1 ]--+--- SSL Connection | true Library| OpenSSL Protocol | TLSv1.3 Key Bits | 256 Cipher | TLS_AES_256_GCM_SHA384 Compression| off ALPN | postgresql I’m unsure if we need to expand the documentation further. I would appreciate your suggestions on this. Regards, Hunaid Sohail On Mon, Oct 7, 2024 at 9:31 PM David G. Johnston wrote: > On Sun, Oct 6, 2024 at 11:17 PM Hunaid Sohail > wrote: > >> >> PQpass - no need >> > > I would include this as presence/absence. > > I concur on all of the rest. > > >> >> For PQparameterStatus, some parameters are already used. >> server_version and application_name were already discussed and removed in >> v12 and v29 respectively. Do we need other parameters? >> > > Ok, I'll need to go read the reasoning for why they are deemed unneeded > and form an opinion one way or the other. > > >> >>> Within that framework having \conninfo[+[CSE][…]] be the command - >>> printing out only the table specified would be the behavior (specifying no >>> suffix letters prints all three) - would be an option. >>> >> >> 3 separate tables without suffix? >> > > Yes, the tables need headers specific to their categories. > > I do like the idea of having 4 though, placing settings into their own. > Premised on having all or most of the available parameters being on the > table. If it only ends up being a few of them then keeping those in > the status table makes sense. > > David J. > >> From 5fc7a9b2a80933641b67c30b5909a0aed810f0cd Mon Sep 17 00:00:00 2001 From: Hunaid Sohail Date: Wed, 30 Oct 2024 10:44:21 +0500 Subject: [PATCH v36] Add psql meta command conninfo+ --- doc/src/sgml/ref/psql-ref.sgml | 23 ++- src/bin/psql/command.c | 328 +++-- src/bin/psql/help.c| 2 +- 3 files changed, 328 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index b825ca96a2..c620bcd94e 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -1060,11 +1060,26 @@ INSERT INTO tbls1 VALUES ($1, $2) \parse stmt1 -\conninfo +\conninfo[+[C|S|P|E]] - -Outputs information about the current database connection. - + +Outputs information about the current database connection. +When + is appended, all details about the +connection are displayed in table format. +The modifiers can be: + + C: Displays connection information, including: + Database, Client User, Host, Host Address, Port, and Options. + S: Displays the current connection status, including: + Protocol Version, Password Used, GSSAPI Authenticated, and Backend PID. + P: Displays parameter settings of the server, including: + Superuser, Client Encoding, Server Encoding, and Session Authorization. + E: Displays connection encryption details, including: + SSL Connection, Library, Protocol, Key Bits, Cipher, Compression, and ALPN. + +If no modifier is specified, all available details are displayed in separate tables. +If connection is not using SSL, related encryption details are not displayed. + diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 328d78c73f..8a5b8d1ea9 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -72,7 +72,8 @@ static backslashResult exec_command_cd(PsqlScanState scan_state, bool active_bra const char *cmd); static backslashResult exec_command_close(PsqlScanState scan_state, bool active_branch, const char *cmd); -static backslashResult exec_command_conninfo(PsqlScanState scan_state, bool active_b
Re: Psql meta-command conninfo+
On Sun, Oct 6, 2024 at 11:17 PM Hunaid Sohail wrote: > > PQpass - no need > I would include this as presence/absence. I concur on all of the rest. > > For PQparameterStatus, some parameters are already used. > server_version and application_name were already discussed and removed in > v12 and v29 respectively. Do we need other parameters? > Ok, I'll need to go read the reasoning for why they are deemed unneeded and form an opinion one way or the other. > >> Within that framework having \conninfo[+[CSE][…]] be the command - >> printing out only the table specified would be the behavior (specifying no >> suffix letters prints all three) - would be an option. >> > > 3 separate tables without suffix? > Yes, the tables need headers specific to their categories. I do like the idea of having 4 though, placing settings into their own. Premised on having all or most of the available parameters being on the table. If it only ends up being a few of them then keeping those in the status table makes sense. David J. >
Re: Psql meta-command conninfo+
Hi David, Thank you for your feedback. On Fri, Oct 4, 2024 at 11:56 AM David G. Johnston < david.g.johns...@gmail.com> wrote: > It seems to me a more useful definition for what this command should print > out is basically the entire contents of: > > https://www.postgresql.org/docs/current/libpq-status.html > > That page has three sections: > Connection Invariants > Current Status > Encryption (TLS) > > I would suggest that we thus produce three tables - one for each. In the > case of SSL, a message saying “not used” instead of a table full of blanks > probably suffices, though I’d lean to print all of what is available at all > times. > We can try this approach. I would also like to have other's opinions on this approach. Most functions are already used, while some are not required (IMO). I have listed all the functions from the doc link you provided, along with my brief comments based on the latest patch (v35). PQdb - already used PQuser - already used PQpass - no need PQhost - already used PQhostaddr - already used PQport - already used PQtty - no need PQoptions - can be used PQstatus - no need PQtransactionStatus - can be used PQparameterStatus - already used PQprotocolVersion - already used PQserverVersion - no need PQerrorMessage - no need PQsocket - no need PQbackendPID - already used PQconnectionNeedsPassword - no need PQconnectionUsedPassword - can be used PQconnectionUsedGSSAPI - already used PQsslInUse - already used PQsslAttribute - only key_bits attribute not used PQsslAttributeNames - no need PQsslStruct - no need PQgetssl - no need For PQparameterStatus, some parameters are already used. server_version and application_name were already discussed and removed in v12 and v29 respectively. Do we need other parameters? > Within that framework having \conninfo[+[CSE][…]] be the command - > printing out only the table specified would be the behavior (specifying no > suffix letters prints all three) - would be an option. > 3 separate tables without suffix? If others are okay with this, I can work on this approach and will provide a patch before the next CF. Regards, Hunaid Sohail
Re: Psql meta-command conninfo+
On Thursday, October 3, 2024, Hunaid Sohail wrote: > > > Authenticated User: The name of the user returned by PQuser(), indicating > the user who initiated or authenticated the current database connection. > Session User: The session user's name, which is initially the same as the > authenticated user but can be changed with SET SESSION AUTHORIZATION. See > the session_user() function in > for more details. > > It seems to me a more useful definition for what this command should print out is basically the entire contents of: https://www.postgresql.org/docs/current/libpq-status.html That page has three sections: Connection Invariants Current Status Encryption (TLS) I would suggest that we thus produce three tables - one for each. In the case of SSL, a message saying “not used” instead of a table full of blanks probably suffices, though I’d lean to print all of what is available at all times. Within that framework having \conninfo[+[CSE][…]] be the command - printing out only the table specified would be the behavior (specifying no suffix letters prints all three) - would be an option. We could add a fourth table - Parameters (P) - for the various outputs of PQparameterStatus; thus making the Current Status section a bit more manageable There are obviously some things psql wouldn’t expose (like password) - we should probably list them explicitly in an exception list, and maybe note as much on the libpq page. Separately, I don’t see a reason to even show “Authenticated User” unless it is different than Session User - which means only in the rare case of a superuser invoking set session authorization. It also isn’t guaranteed to be authenticated, which the docs do try to make a point of, so “Client User” would be more appropriate. David J.
Re: Psql meta-command conninfo+
Hi, On Thu, Oct 3, 2024 at 1:39 PM Maiquel Grassi wrote: > >I thought it would be nice to have a description that tells how both > >Session and Authenticated users differ. IMHO *only* a reference to > >PQuser() doesn't say much, but others might be ok with it. So let's see > >what the other reviewers say. > > Hi everyone, > I believe the difference between Session and Authenticated > users should indeed be made clearer, while still keeping > PQuser() in the description. > Based on my readings from the documentation [1] and [2], we can update user descriptions as follows: Authenticated User: The name of the user returned by PQuser(), indicating the user who initiated or authenticated the current database connection. Session User: The session user's name, which is initially the same as the authenticated user but can be changed with SET SESSION AUTHORIZATION. See the session_user() function in for more details. Let me know if this is fine, then I can provide a new patch. [1] https://www.postgresql.org/docs/current/functions-info.html [2] https://www.postgresql.org/docs/current/sql-set-session-authorization.html Regards, Hunaid Sohail
RE: Psql meta-command conninfo+
>I thought it would be nice to have a description that tells how both >Session and Authenticated users differ. IMHO *only* a reference to >PQuser() doesn't say much, but others might be ok with it. So let's see >what the other reviewers say. Hi everyone, I believe the difference between Session and Authenticated users should indeed be made clearer, while still keeping PQuser() in the description. Other than that, I think the patch is as expected, meeting the initial proposal/idea of this meta-command and thread. I would like a committer who followed the development to volunteer for a thorough technical review so that the patch can move forward to a release candidate for a commit. Regards, Maiquel Grassi.
Re: Psql meta-command conninfo+
On 02.10.24 06:48, Hunaid Sohail wrote: > Should I revert to the v34 docs for Session User, or is it fine as is? What I tried to say is that the current description is a bit vague --- specially "Authenticated User". > Authenticated User: The name of the user returned by PQuser() > Session User: The session user's name. I thought it would be nice to have a description that tells how both Session and Authenticated users differ. IMHO *only* a reference to PQuser() doesn't say much, but others might be ok with it. So let's see what the other reviewers say. -- Jim
Re: Psql meta-command conninfo+
Hi, On Tue, Oct 1, 2024 at 10:50 AM Jim Jones wrote: > Right. I meant "Session User" > > > Authenticated User: The name of the user returned by PQuser() > > Session User: The session user's name. > Should I revert to the v34 docs for Session User, or is it fine as is? Session User: The session user's name; see the session_user() function in for more details. Any other changes required? Regards, Hunaid Sohail
Re: Psql meta-command conninfo+
On 01.10.24 06:27, Hunaid Sohail wrote: > There are two users in the conninfo+: 'session' and 'authenticated'. > Both are documented. Right. I meant "Session User" > Authenticated User: The name of the user returned by PQuser() > Session User: The session user's name. Thanks -- Jim
Re: Psql meta-command conninfo+
Hi, On Mon, Sep 30, 2024 at 11:16 PM Jim Jones wrote: > On 26.09.24 09:15, Hunaid Sohail wrote: > > This patch renames "Current User" to "Authenticated User" as suggested > > by me in my last email. I have also updated the documentation > accordingly. > > Could you perhaps in the documentation elaborate a bit more on the > difference between "Current User" and "Authenticated User"? IMHO a > couple of words on how exactly they differ would be very helpful, as > they show the same user in many cases. > There is no "Current User" in the conninfo+; as I mentioned, I have renamed it to "Authenticated User". There are two users in the conninfo+: 'session' and 'authenticated'. Both are documented. > Although a bit redundant, I'd argue that "SSL Compression" is better > than just "Compression". > Noted. Regards, Hunaid Sohail
Re: Psql meta-command conninfo+
Hi On 26.09.24 09:15, Hunaid Sohail wrote: > This patch renames "Current User" to "Authenticated User" as suggested > by me in my last email. I have also updated the documentation accordingly. Could you perhaps in the documentation elaborate a bit more on the difference between "Current User" and "Authenticated User"? IMHO a couple of words on how exactly they differ would be very helpful, as they show the same user in many cases. > Authenticated User: The name of the user returned by PQuser() > Session User: The session user's name. Although a bit redundant, I'd argue that "SSL Compression" is better than just "Compression". Other than that, it looks much better now: $ /usr/local/postgres-dev/bin/psql -x "\ host=server.uni-muenster.de hostaddr=192.168.178.27 user=jim dbname=db port=54322 sslmode=verify-full sslrootcert=server-certificates/server.crt sslcert=jim-certificates/jim.crt sslkey=jim-certificates/jim.key" psql (18devel) SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: postgresql) Type "help" for help. db=# SET client_encoding TO 'LATIN1'; SET db=# \conninfo+ Connection Information -[ RECORD 1 ]+--- Database | db Authenticated User | jim Session User | jim Host | server.uni-muenster.de Host Address | 192.168.178.27 Port | 54322 Protocol Version | 3 SSL Connection | true SSL Protocol | TLSv1.3 SSL Cipher | TLS_AES_256_GCM_SHA384 Compression | off ALPN | postgresql GSSAPI Authenticated | false Client Encoding | LATIN1 Server Encoding | UTF8 Backend PID | 874890 Thanks!
Re: Psql meta-command conninfo+
Hi, This patch renames "Current User" to "Authenticated User" as suggested by me in my last email. I have also updated the documentation accordingly. On Tue, Sep 17, 2024 at 4:53 PM Hunaid Sohail wrote: > We can update the docs as follows: > Authenticated User: The name of the user returned by PQuser(). > Session User: The session user's name. > Moreover, as Álvaro suggested, I made some modifications to the code structure and moved verbose code into a separate function. Please let me know if you have any questions or further suggestions. Regards, Hunaid Sohail v35-0001-Add-psql-meta-command-conninfo.patch Description: Binary data
Re: Psql meta-command conninfo+
Hi, On Mon, Sep 16, 2024 at 8:31 PM Tom Lane wrote: > Alvaro Herrera writes: > > On 2024-Sep-16, Jim Jones wrote: > >> * The value of "Current User" does not match the function current_user() > >> --- as one might expcect. It is a little confusing, as there is no > >> mention of "Current User" in the docs. In case this is the intended > >> behaviour, could you please add it to the docs? > > > It is intended. As Peter said[1], what we wanted was to display > > client-side info, so PQuser() is the right thing to do. Now maybe > > "Current User" is not the perfect column header, but at least the > > definition seems consistent with the desired end result. > > Seems like "Session User" would be closer to being accurate, since > PQuser()'s result does not change when you do SET ROLE etc. > > > Now, I think > > the current docs saying to look at session_user() are wrong, they should > > point to the libpq docs for the function instead; something like "The > > name of the current user, as returned by PQuser()" and so on. > > Sure, but this does not excuse choosing a misleading column name > when there are better choices readily available. > Maybe we can rename "Current User" to "Authenticated User" just like the previous author because it is a user returned by PQuser(). For the "Session User", I believe it is working as expected, since session_user can be changed with SET SESSION AUTHORIZATION. ``` $ bin/psql "port=5430 sslmode=disable dbname=postgres" -x -h localhost postgres=# \conninfo+ Connection Information -[ RECORD 1 ]+-- Database | postgres Current User | hunaid Session User | hunaid Host | localhost Host Address | 127.0.0.1 Port | 5430 Protocol Version | 3 SSL Connection | false GSSAPI Authenticated | false Client Encoding | UTF8 Server Encoding | UTF8 Backend PID | 1337 postgres=# set SESSION AUTHORIZATION postgres; SET postgres=# \conninfo+ Connection Information -[ RECORD 1 ]+-- Database | postgres Current User | hunaid Session User | postgres Host | localhost Host Address | 127.0.0.1 Port | 5430 Protocol Version | 3 SSL Connection | false GSSAPI Authenticated | false Client Encoding | UTF8 Server Encoding | UTF8 Backend PID | 1337 ``` We can update the docs as follows: Authenticated User: The name of the user returned by PQuser(). Session User: The session user's name. Opinions? Regards, Hunaid Sohail
Re: Psql meta-command conninfo+
Alvaro Herrera writes: > On 2024-Sep-16, Jim Jones wrote: >> * The value of "Current User" does not match the function current_user() >> --- as one might expcect. It is a little confusing, as there is no >> mention of "Current User" in the docs. In case this is the intended >> behaviour, could you please add it to the docs? > It is intended. As Peter said[1], what we wanted was to display > client-side info, so PQuser() is the right thing to do. Now maybe > "Current User" is not the perfect column header, but at least the > definition seems consistent with the desired end result. Seems like "Session User" would be closer to being accurate, since PQuser()'s result does not change when you do SET ROLE etc. > Now, I think > the current docs saying to look at session_user() are wrong, they should > point to the libpq docs for the function instead; something like "The > name of the current user, as returned by PQuser()" and so on. Sure, but this does not excuse choosing a misleading column name when there are better choices readily available. regards, tom lane
Re: Psql meta-command conninfo+
On 2024-Sep-16, Jim Jones wrote: > * The value of "Current User" does not match the function current_user() > --- as one might expcect. It is a little confusing, as there is no > mention of "Current User" in the docs. In case this is the intended > behaviour, could you please add it to the docs? It is intended. As Peter said[1], what we wanted was to display client-side info, so PQuser() is the right thing to do. Now maybe "Current User" is not the perfect column header, but at least the definition seems consistent with the desired end result. Now, I think the current docs saying to look at session_user() are wrong, they should point to the libpq docs for the function instead; something like "The name of the current user, as returned by PQuser()" and so on. Otherwise, in the cases where these things differ, it is going to be hard to explain. [1] https://postgr.es/m/f4fc729d-7903-4d58-995d-6cd146049...@eisentraut.org > * "SSL Connection" says "yes", but the docs say: "True if the current > connection to the server uses SSL, and false otherwise.". Is it supposed > to be like this? I haven't checked other similar doc entries.. Yeah, I think we should print what a boolean value would look like from SQL, so "true" rather than "yes". I think the code structure is hard to follow. It would be simpler if it was a bunch of /* Database */ printTableAddHeader(&cont, _("Database"), true, 'l'); printTableAddCell(&cont, db, false, false); ... /* Port */ printTableAddHeader(&cont, _("Por"), true, 'l'); printTableAddCell(&cont, PQport(pset.db), false, false); /* ... */ And so on. I don't think the printTable() API forces you to set all headers first followed by all cells. -- Álvaro HerreraBreisgau, Deutschland — https://www.EnterpriseDB.com/
Re: Psql meta-command conninfo+
On 16.09.24 08:51, Hunaid Sohail wrote: > I have attached a new patch that now prints all info in tabular format > for \conninfo+. I have also made the table output dynamic, so if the > connection uses SSL, the columns in the table will expand accordingly. > It looks much cleaner now. > I have also updated the documentation. The CF bot is still giving some warnings: command.c:886:79: error: ‘alpn’ may be used uninitialized [-Werror=maybe-uninitialized] 886 | printTableAddCell(&cont, (alpn && alpn[0] != '\0') ? alpn : _("none"), false, false); | ^~~ command.c:803:50: note: ‘alpn’ was declared here 803 | *alpn; | ^~~~ command.c:885:82: error: ‘compression’ may be used uninitialized [-Werror=maybe-uninitialized] 885 | printTableAddCell(&cont, (compression && strcmp(compression, "off") != 0) ? _("on") : _("off"), false, false); | ^~ command.c:802:50: note: ‘compression’ was declared here 802 | *compression, | ^~~ command.c:884:41: error: ‘cipher’ may be used uninitialized [-Werror=maybe-uninitialized] 884 | printTableAddCell(&cont, cipher ? cipher : _("unknown"), false, false); | ^~ command.c:801:50: note: ‘cipher’ was declared here 801 | *cipher, | ^~ command.c:883:41: error: ‘protocol’ may be used uninitialized [-Werror=maybe-uninitialized] 883 | printTableAddCell(&cont, protocol ? protocol : _("unknown"), false, false); | ^~ command.c:800:42: note: ‘protocol’ was declared here 800 | char *protocol, | ^~~~ I have a few questions regarding this example: $ /usr/local/postgres-dev/bin/psql -x "\ host=server.uni-muenster.de hostaddr=192.168.178.27 user=jim dbname=db port=5432 sslmode=verify-full sslrootcert=server-certificates/server.crt sslcert=jim-certificates/jim.crt sslkey=jim-certificates/jim.key" psql (18devel) SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: postgresql) Type "help" for help. db=# SET ROLE foo; SET db=> SELECT current_user, session_user; -[ RECORD 1 ]+ current_user | foo session_user | jim db=> \conninfo+ Connection Information -[ RECORD 1 ]+--- Database | db Current User | jim Session User | jim Host | server.uni-muenster.de Host Address | 192.168.178.27 Port | 5432 Protocol Version | 3 SSL Connection | yes SSL Protocol | TLSv1.3 Cipher | TLS_AES_256_GCM_SHA384 Compression | off ALPN | postgresql GSSAPI Authenticated | no Client Encoding | UTF8 Server Encoding | UTF8 Backend PID | 315187 * The value of "Current User" does not match the function current_user() --- as one might expcect. It is a little confusing, as there is no mention of "Current User" in the docs. In case this is the intended behaviour, could you please add it to the docs? * "SSL Connection" says "yes", but the docs say: "True if the current connection to the server uses SSL, and false otherwise.". Is it supposed to be like this? I haven't checked other similar doc entries.. -- Jim
Re: Psql meta-command conninfo+
Hi, On Sat, Sep 14, 2024 at 10:50 PM Tom Lane wrote: > Alvaro Herrera writes: > > I don't understand why this is is printing half the information in > > free-form plain text and the other half in tabular format. All these > > items that you have in the free-form text lines should be part of the > > table, I think. > > +1, that was my reaction as well. I can see the point of showing > those items the same way as plain \conninfo does, but I think > we're better off just making \conninfo+ produce a table and nothing > else. > I have attached a new patch that now prints all info in tabular format for \conninfo+. I have also made the table output dynamic, so if the connection uses SSL, the columns in the table will expand accordingly. ``` $ bin/psql "port=5430 sslmode=require dbname=postgres" -x -h localhost postgres=# \conninfo+ Connection Information -[ RECORD 1 ]+--- Database | postgres Current User | hunaid Session User | hunaid Host | localhost Host Address | 127.0.0.1 Port | 5430 Protocol Version | 3 SSL Connection | yes SSL Protocol | TLSv1.3 Cipher | TLS_AES_256_GCM_SHA384 Compression | off ALPN | postgresql GSSAPI Authenticated | no Client Encoding | UTF8 Server Encoding | UTF8 Backend PID | 88803 $ bin/psql "port=5430 sslmode=disable dbname=postgres" -x -h localhost postgres=# \conninfo+ Connection Information -[ RECORD 1 ]+-- Database | postgres Current User | hunaid Session User | hunaid Host | localhost Host Address | 127.0.0.1 Port | 5430 Protocol Version | 3 SSL Connection | no GSSAPI Authenticated | no Client Encoding | UTF8 Server Encoding | UTF8 Backend PID | 88900 $ bin/psql "port=5430 sslmode=disable dbname=postgres" -x postgres=# \conninfo+ Connection Information -[ RECORD 1 ]+- Database | postgres Current User | hunaid Session User | hunaid Socket Directory | /tmp Port | 5430 Protocol Version | 3 SSL Connection | no GSSAPI Authenticated | no Client Encoding | UTF8 Server Encoding | UTF8 Backend PID | 89035 ``` I have also updated the documentation. Regards, Hunaid Sohail v34-0001-Add-psql-meta-command-conninfo.patch Description: Binary data
Re: Psql meta-command conninfo+
Alvaro Herrera writes: > I don't understand why this is is printing half the information in > free-form plain text and the other half in tabular format. All these > items that you have in the free-form text lines should be part of the > table, I think. +1, that was my reaction as well. I can see the point of showing those items the same way as plain \conninfo does, but I think we're better off just making \conninfo+ produce a table and nothing else. regards, tom lane
Re: Psql meta-command conninfo+
On 2024-Sep-14, Hunaid Sohail wrote: > I agree that both messages should be printed together. IMO the message > "You are connected to database..." should be printed at the top, no? > Because it shows important info that the user may be interested to see > first. Then we can combine the ssl message. > > postgres=# \x > Expanded display is on. > postgres=# \conninfo+ > You are connected to database "postgres" as user "hunaid" on host > "localhost" (address "127.0.0.1") at port "5430". > SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, > compression: off, ALPN: postgresql) > Connection Information > -[ RECORD 1 ]+--- > Protocol Version | 3 > SSL Connection | yes > GSSAPI Authenticated | no > Client Encoding | UTF8 > Server Encoding | UTF8 > Session User | hunaid > Backend PID | 109092 I don't understand why this is is printing half the information in free-form plain text and the other half in tabular format. All these items that you have in the free-form text lines should be part of the table, I think. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ #error "Operator lives in the wrong universe" ("Use of cookies in real-time system development", M. Gleixner, M. Mc Guire)
Re: Psql meta-command conninfo+
Hi Jim, On Fri, Sep 13, 2024 at 4:27 PM Jim Jones wrote: > I just noticed that messages' order has been slightly changed. The > message "You are connected to database "postgres" as user "hunaid" via > socket in "/tmp" at port "5430" used to be printed after the table, and > now it is printed before. > > $ /usr/local/postgres-dev/bin/psql -x "\ > hostaddr=0 > user=jim dbname=postgres > port=54322" -c "\conninfo+" > > You are connected to database "postgres" as user "jim" on host "0" > (address "0.0.0.0") at port "54322". > Connection Information > -[ RECORD 1 ]+ > Protocol Version | 3 > SSL Connection | no > GSSAPI Authenticated | no > Client Encoding | UTF8 > Server Encoding | UTF8 > Session User | jim > Backend PID | 2419033 > > It is IMHO a little strange because the "SSL connection" info keeps > being printed in the end. I would personally prefer if they're printed > together --- preferably after the table. But I'm not sure if there's any > convention for that. > I agree that both messages should be printed together. IMO the message "You are connected to database..." should be printed at the top, no? Because it shows important info that the user may be interested to see first. Then we can combine the ssl message. postgres=# \x Expanded display is on. postgres=# \conninfo+ You are connected to database "postgres" as user "hunaid" on host "localhost" (address "127.0.0.1") at port "5430". SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: postgresql) Connection Information -[ RECORD 1 ]+--- Protocol Version | 3 SSL Connection | yes GSSAPI Authenticated | no Client Encoding | UTF8 Server Encoding | UTF8 Session User | hunaid Backend PID | 109092 > Also, there are a few compilation warnings regarding const qualifiers: > Noted. I will fix them in the next patch. Regards, Hunaid Sohail
Re: Psql meta-command conninfo+
On 13.09.24 06:49, Hunaid Sohail wrote: > > $ bin/psql --port=5430 postgres > psql (18devel) > Type "help" for help. > > postgres=# \conninfo+ > You are connected to database "postgres" as user "hunaid" via socket > in "/tmp" at port "5430". > Connection Information > Protocol Version | SSL Connection | GSSAPI Authenticated | Client > Encoding | Server Encoding | Session User | Backend P > ID > --++--+-+-+--+-- > --- > 3 | no | no | UTF8 > | UTF8 | hunaid | 55598 > (1 row) Nice. I just noticed that messages' order has been slightly changed. The message "You are connected to database "postgres" as user "hunaid" via socket in "/tmp" at port "5430" used to be printed after the table, and now it is printed before. $ /usr/local/postgres-dev/bin/psql -x "\ hostaddr=0 user=jim dbname=postgres port=54322" -c "\conninfo+" You are connected to database "postgres" as user "jim" on host "0" (address "0.0.0.0") at port "54322". Connection Information -[ RECORD 1 ]+ Protocol Version | 3 SSL Connection | no GSSAPI Authenticated | no Client Encoding | UTF8 Server Encoding | UTF8 Session User | jim Backend PID | 2419033 It is IMHO a little strange because the "SSL connection" info keeps being printed in the end. I would personally prefer if they're printed together --- preferably after the table. But I'm not sure if there's any convention for that. $ /usr/local/postgres-dev/bin/psql -x "\ host=server.uni-muenster.de hostaddr=127.0.0.1 user=jim dbname=postgres port=54322 sslmode=verify-full sslrootcert=server-certificates/server.crt sslcert=jim-certificates/jim.crt sslkey=jim-certificates/jim.key" -c "\conninfo+" You are connected to database "postgres" as user "jim" on host "server.uni-muenster.de" (address "127.0.0.1") at port "54322". Connection Information -[ RECORD 1 ]+ Protocol Version | 3 SSL Connection | yes GSSAPI Authenticated | no Client Encoding | UTF8 Server Encoding | UTF8 Session User | jim Backend PID | 2421556 SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: postgresql) Also, there are a few compilation warnings regarding const qualifiers: command.c:810:49: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] 810 | client_encoding = PQparameterStatus(pset.db, "client_encoding"); | ^ command.c:811:49: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] 811 | server_encoding = PQparameterStatus(pset.db, "server_encoding"); | ^ command.c:812:46: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] 812 | session_user = PQparameterStatus(pset.db, "session_authorization"); -- Jim
Re: Psql meta-command conninfo+
Hi, On Thu, Sep 12, 2024 at 4:08 PM Jim Jones wrote: > It may look like this, but it is a single record --- mind the header "-[ > RECORD 1 ]+-". > psql was called in expanded mode: > > > $ /home/pgsql-17devel/bin/psql -x -p 5432 > > "-x" or "--expanded" > > Example: > > $ psql postgres -xc "SELECT 'foo' col1, 'bar' col2" > -[ RECORD 1 ] > col1 | foo > col2 | bar > I guess I missed the expanded mode. I have attached a new patch. Please check the output now. ``` $ bin/psql --port=5430 postgres psql (18devel) Type "help" for help. postgres=# \conninfo+ You are connected to database "postgres" as user "hunaid" via socket in "/tmp" at port "5430". Connection Information Protocol Version | SSL Connection | GSSAPI Authenticated | Client Encoding | Server Encoding | Session User | Backend P ID --++--+-+-+--+-- --- 3| no | no | UTF8 | UTF8| hunaid | 55598 (1 row) postgres=# \x Expanded display is on. postgres=# \conninfo+ You are connected to database "postgres" as user "hunaid" via socket in "/tmp" at port "5430". Connection Information -[ RECORD 1 ]+--- Protocol Version | 3 SSL Connection | no GSSAPI Authenticated | no Client Encoding | UTF8 Server Encoding | UTF8 Session User | hunaid Backend PID | 55598 ``` Regards, Hunaid Sohail From b011b1cc780fee4030147070db84dcc62edd10a9 Mon Sep 17 00:00:00 2001 From: Hunaid Sohail Date: Fri, 13 Sep 2024 09:37:10 +0500 Subject: [PATCH v33] Add psql meta command conninfo+ --- doc/src/sgml/ref/psql-ref.sgml | 26 +++-- src/bin/psql/command.c | 67 +++--- src/bin/psql/help.c| 2 +- 3 files changed, 85 insertions(+), 10 deletions(-) diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 3fd9959ed1..3f8d72b42e 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -1060,11 +1060,29 @@ INSERT INTO tbls1 VALUES ($1, $2) \parse stmt1 -\conninfo +\conninfo[+] - -Outputs information about the current database connection. - + +Outputs a string displaying information about the current +database connection. When + is appended, +more details about the connection are displayed in table +format: + + Protocol Version: The version of the PostgreSQL protocol used for +this connection. + SSL Connection: True if the current connection to the server +uses SSL, and false otherwise. + GSSAPI Authenticated: True if GSSAPI is in use, or false if +GSSAPI is not in use on this connection. + Client Encoding: The encoding used by the client for this connection. + Server Encoding: The encoding used by the server for this connection. + Session User: The session user's name; +see the session_user() function in + for more details. + Backend PID: The process ID of the backend for the +connection. + + diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 4dfc7b2d85..7ad28287c1 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -72,7 +72,8 @@ static backslashResult exec_command_cd(PsqlScanState scan_state, bool active_bra const char *cmd); static backslashResult exec_command_close(PsqlScanState scan_state, bool active_branch, const char *cmd); -static backslashResult exec_command_conninfo(PsqlScanState scan_state, bool active_branch); +static backslashResult exec_command_conninfo(PsqlScanState scan_state, bool active_branch, + const char *cmd); static backslashResult exec_command_copy(PsqlScanState scan_state, bool active_branch); static backslashResult exec_command_copyright(PsqlScanState scan_state, bool active_branch); static backslashResult exec_command_crosstabview(PsqlScanState scan_state, bool active_branch); @@ -328,8 +329,8 @@ exec_command(const char *cmd, status = exec_command_cd(scan_state, active_branch, cmd); else if (strcmp(cmd, "close") == 0) status = exec_command_close(scan_state, active_branch, cmd); - else if (strcmp(cmd, "conninfo") == 0) - status = exec_command_conninfo(scan_state, active_branch); + else if (strcmp(cmd, "conninfo") == 0 || strcmp(cmd, "conninfo+") == 0) + status = exec_command_conninfo(scan_state, active_branch, cmd); else if (pg_strcasecmp(cmd, "copy") == 0) status = exec_command_copy(scan_state, active_branch); else if (strcmp(cmd, "copyright") == 0) @@ -739,11 +740,14 @@ exec_command_close(PsqlScanState scan_stat
Re: Psql meta-command conninfo+
On 11.09.24 13:35, Hunaid Sohail wrote: > Hi Jim, > > On Wed, Sep 11, 2024 at 3:03 PM Jim Jones > wrote: > > Thanks for working on this. > > Any particular reason for the design change? In v28 it returned a > table > with a single row and multiple columns --- one column per > attribute. But > now it returns multiple rows. In this case, I was expecting 1 row > with 7 > columns instead of 7 rows with 2 columns. > > > I am not sure which design you are referring to. > I haven't applied the v28 patch but the original author in thread [1] > provided sample output. The output is in tabular form with 2 columns > and multiple rows. > > [1] > https://www.postgresql.org/message-id/CP8P284MB249615AED23882E1E185C8ABEC3C2%40CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM > > It may look like this, but it is a single record --- mind the header "-[ RECORD 1 ]+-". psql was called in expanded mode: > $ /home/pgsql-17devel/bin/psql -x -p 5432 "-x" or "--expanded" Example: $ psql postgres -xc "SELECT 'foo' col1, 'bar' col2" -[ RECORD 1 ] col1 | foo col2 | bar -- Jim
Re: Psql meta-command conninfo+
Hi Jim, On Wed, Sep 11, 2024 at 3:03 PM Jim Jones wrote: > Thanks for working on this. > > Any particular reason for the design change? In v28 it returned a table > with a single row and multiple columns --- one column per attribute. But > now it returns multiple rows. In this case, I was expecting 1 row with 7 > columns instead of 7 rows with 2 columns. > I am not sure which design you are referring to. I haven't applied the v28 patch but the original author in thread [1] provided sample output. The output is in tabular form with 2 columns and multiple rows. [1] https://www.postgresql.org/message-id/CP8P284MB249615AED23882E1E185C8ABEC3C2%40CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM Regards, Hunaid Sohail
Re: Psql meta-command conninfo+
On 11.09.24 10:16, Hunaid Sohail wrote: I have made the requested changes. Now output is returned in tabular form. Indentation/whitespace issues are fixed. $bin/psql --port=5430 postgres postgres=# \conninfo+ You are connected to database "postgres" as user "hunaid" via socket in "/tmp" at port "5430". Connection Information Parameter | Value --+ Protocol Version | 3 SSL Connection | no GSSAPI Authenticated | no Client Encoding | UTF8 Server Encoding | UTF8 Session User | hunaid Backend PID | 121800 (7 rows) Thanks for working on this. Any particular reason for the design change? In v28 it returned a table with a single row and multiple columns --- one column per attribute. But now it returns multiple rows. In this case, I was expecting 1 row with 7 columns instead of 7 rows with 2 columns. Jim
Re: Psql meta-command conninfo+
Hi, On Tue, Sep 10, 2024 at 9:16 PM Alvaro Herrera wrote: > On 2024-Sep-10, Jim Jones wrote: > > > Is \conninfo+ no longer supposed to return the results in tabular form? > > At least it wasn't the case till v28. > > I suspect the reason it's no longer a table is that it was previously a > query (which is easily printed as a table by calling printQuery) and now > it's just a client-side thing, and Hunaid didn't know how to handle that > as a table. The good news is, it should be really easy to do > printTableInit(), then a bunch of printTableAddHeader() and > printTableAddCell(), end with printTable(). I think the tabular format > is better for sure. > I have made the requested changes. Now output is returned in tabular form. Indentation/whitespace issues are fixed. $bin/psql --port=5430 postgres postgres=# \conninfo+ You are connected to database "postgres" as user "hunaid" via socket in "/tmp" at port "5430". Connection Information Parameter | Value --+ Protocol Version | 3 SSL Connection | no GSSAPI Authenticated | no Client Encoding | UTF8 Server Encoding | UTF8 Session User | hunaid Backend PID | 121800 (7 rows) Regards, Hunaid Sohail v32-0001-Add-psql-meta-command-conninfo.patch Description: Binary data
Re: Psql meta-command conninfo+
On 2024-Sep-10, Jim Jones wrote: > Is \conninfo+ no longer supposed to return the results in tabular form? > At least it wasn't the case till v28. I suspect the reason it's no longer a table is that it was previously a query (which is easily printed as a table by calling printQuery) and now it's just a client-side thing, and Hunaid didn't know how to handle that as a table. The good news is, it should be really easy to do printTableInit(), then a bunch of printTableAddHeader() and printTableAddCell(), end with printTable(). I think the tabular format is better for sure. -- Álvaro HerreraBreisgau, Deutschland — https://www.EnterpriseDB.com/ "La primera ley de las demostraciones en vivo es: no trate de usar el sistema. Escriba un guión que no toque nada para no causar daños." (Jakob Nielsen)
Re: Psql meta-command conninfo+
On 10.09.24 06:32, Hunaid Sohail wrote: > > I have attached a rebased patch. Thanks. Is \conninfo+ no longer supposed to return the results in tabular form? At least it wasn't the case till v28. $ /usr/local/postgres-dev/bin/psql -d postgres -h 0 -c "\conninfo+" You are connected to database "postgres" as user "jim" on host "0" (address "0.0.0.0") at port "5432". Protocol Version: 3 SSL Connection: no GSSAPI Authenticated: no Client Encoding: UTF8 Server Encoding: UTF8 Session User: jim Backend PID: 579041 $ /usr/local/postgres-dev/bin/psql -d postgres -h 127.0.0.1 -c "\conninfo+" You are connected to database "postgres" as user "jim" on host "127.0.0.1" at port "5432". Protocol Version: 3 SSL Connection: no GSSAPI Authenticated: no Client Encoding: UTF8 Server Encoding: UTF8 Session User: jim Backend PID: 579087 Sorry if I missed that in the thread. v31 has a couple of small indentation problems: /home/jim/patches/conninfo/v31-0001-Add-psql-meta-command-conninfo-plus.patch:87: indent with spaces. show_verbose = strchr(cmd, '+') ? true : false; /home/jim/patches/conninfo/v31-0001-Add-psql-meta-command-conninfo-plus.patch:106: trailing whitespace. Checking patch doc/src/sgml/ref/psql-ref.sgml... Checking patch src/bin/psql/command.c... Checking patch src/bin/psql/help.c... Applied patch doc/src/sgml/ref/psql-ref.sgml cleanly. Applied patch src/bin/psql/command.c cleanly. Applied patch src/bin/psql/help.c cleanly. warning: 2 lines add whitespace errors. -- Jim
Re: Psql meta-command conninfo+
Hi, I have attached a rebased patch. Regards, Hunaid Sohail On Mon, Sep 9, 2024 at 6:22 PM Jim Jones wrote: > Hi Hunaid > > On 02.08.24 14:11, Hunaid Sohail wrote: > > > > I have also edited the documentation and added it to the patch. Please > > let me know if any changes are required. > > > > I just wanted to review this patch again but v30 does not apply > > === Applying patches on top of PostgreSQL commit ID > d8df7ac5c04cd17bf13bd3123dcfcaf8007c6280 === > /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is > obsolete. Please consider migrating to /etc/jail.conf. > === applying patch ./v30-0001-psql-meta-command-conninfo-plus.patch > patch unexpectedly ends in middle of line > gpatch: Only garbage was found in the patch input. > > > I will set the status to "Waiting on Author". > > -- > Jim > > v31-0001-Add-psql-meta-command-conninfo-plus.patch Description: Binary data
Re: Psql meta-command conninfo+
Hi Hunaid On 02.08.24 14:11, Hunaid Sohail wrote: > > I have also edited the documentation and added it to the patch. Please > let me know if any changes are required. > I just wanted to review this patch again but v30 does not apply === Applying patches on top of PostgreSQL commit ID d8df7ac5c04cd17bf13bd3123dcfcaf8007c6280 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. === applying patch ./v30-0001-psql-meta-command-conninfo-plus.patch patch unexpectedly ends in middle of line gpatch: Only garbage was found in the patch input. I will set the status to "Waiting on Author". -- Jim
Re: Psql meta-command conninfo+
Hi, I have read the entire thread discussion. I understood the importance of this enhancement related to /conninfo+ meta command. I really appreciate the efforts of Maiquel and suggestions made by the reviewers. According to best of my understanding, libpq API should be used instead of creating server query for conninfo+ meta command. Building on the patch (v29) provided by Maiquel, I made changes to retrieve some extra information related to connection from libpq API. Extra information includes: - Protocol Version - SSL Connection - GSSAPI Authenticated - Client Encoding - Server Encoding - Session User - Backend PID Output of \conninfo+: 1. $ bin/psql --port=5430 postgres -h localhost psql (18devel) Type "help" for help. postgres=# \conninfo+ You are connected to database "postgres" as user "hunaid" on host "localhost" (address "127.0.0.1") at port "5430". Protocol Version: 3 SSL Connection: no GSSAPI Authenticated: no Client Encoding: UTF8 Server Encoding: UTF8 Session User: hunaid Backend PID: 163816 I have also edited the documentation and added it to the patch. Please let me know if any changes are required. Regards, Hunaid Sohail On Wed, Jun 5, 2024 at 5:32â¯PM Maiquel Grassi wrote: > From a quick skim of the latest messages in this thread, it sounds like > there are a couple of folks who think \conninfo (and consequently > \conninfo+) should only report values from the libpq API. I think they > would prefer server-side information to be provided via a system view or > maybe an entirely new psql meta-command. > > IIUC a new system view would more-or-less just gather information from > other system views and functions. A view would be nice because it could be > used outside psql, but I'm not sure to what extent we are comfortable > adding system views built on other system views. Something like > \sessioninfo (as proposed by Sami) would look more similar to what you have > in your latest patch, i.e., we'd teach psql about a complicated query for > gathering all this disparate information. > > IMHO a good way to help move this forward is to try implementing it as a > system view so that we can compare the two approaches. I've had luck in > the past with implementing something a couple different ways to help drive > consensus. > > --//-- > > Great Nathan, we can follow that path of the view. I leave it open for > anyone in the thread who has been following from the beginning to start the > development of the view. Even you, if you have the interest and time to do > it. At this exact moment, I am involved in a "my baby born" project, so I > am unable to stop to look into this. If someone wants to start, I would > appreciate it. > Regards, > Maiquel Grassi. > ÿþd i f f - - g i t a / d o c / s r c / s g m l / r e f / p s q l - r e f . s g m l b / d o c / s r c / s g m l / r e f / p s q l - r e f . s g m l i n d e x 0 7 4 1 9 a 3 b 9 2 . . f b 3 d 5 2 f b 1 6 1 0 0 6 4 4 - - - a / d o c / s r c / s g m l / r e f / p s q l - r e f . s g m l + + + b / d o c / s r c / s g m l / r e f / p s q l - r e f . s g m l @ @ - 1 0 3 0 , 1 1 + 1 0 3 0 , 2 9 @ @ I N S E R T I N T O t b l 1 V A L U E S ( $ 1 , $ 2 ) \ b i n d ' f i r s t v a l u e ' ' s e c o n d v a l u e ' \ g <