public inbox for [email protected]
help / color / mirror / Atom feed[PATCH 8/8] default to --with-lz4
10+ messages / 5 participants
[nested] [flat]
* [PATCH 8/8] default to --with-lz4
@ 2021-03-10 09:14 Dilip Kumar <[email protected]>
0 siblings, 0 replies; 10+ messages in thread
From: Dilip Kumar @ 2021-03-10 09:14 UTC (permalink / raw)
this is meant to excercize the new feature in the CIs, and not meant to be merged
---
configure | 6 ++++--
configure.ac | 4 ++--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/configure b/configure
index 440d1e8ce5..b411ed1cb4 100755
--- a/configure
+++ b/configure
@@ -1575,7 +1575,7 @@ Optional Packages:
--with-system-tzdata=DIR
use system time zone data in DIR
--without-zlib do not use Zlib
- --with-lz4 build with LZ4 support
+ --without-lz4 build without LZ4 support
--with-gnu-ld assume the C compiler uses GNU ld [default=no]
--with-ssl=LIB use LIB for SSL/TLS support (openssl)
--with-openssl obsolete spelling of --with-ssl=openssl
@@ -8598,7 +8598,9 @@ $as_echo "#define USE_LZ4 1" >>confdefs.h
esac
else
- with_lz4=no
+ with_lz4=yes
+
+$as_echo "#define USE_LZ4 1" >>confdefs.h
fi
diff --git a/configure.ac b/configure.ac
index 780791ae8a..392784d55c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -990,8 +990,8 @@ AC_SUBST(with_zlib)
# LZ4
#
AC_MSG_CHECKING([whether to build with LZ4 support])
-PGAC_ARG_BOOL(with, lz4, no, [build with LZ4 support],
- [AC_DEFINE([USE_LZ4], 1, [Define to 1 to build with LZ4 support. (--with-lz4)])])
+PGAC_ARG_BOOL(with, lz4, yes, [build without LZ4 support],
+ [AC_DEFINE([USE_LZ4], 1, [Define to 1 to build without LZ4 support. (--without-lz4)])])
AC_MSG_RESULT([$with_lz4])
AC_SUBST(with_lz4)
--
2.17.0
--C94crkcyjafcjHxo--
^ permalink raw reply [nested|flat] 10+ messages in thread
* RE: Psql meta-command conninfo+
@ 2024-04-01 14:53 Maiquel Grassi <[email protected]>
2024-04-01 16:22 ` Re: Psql meta-command conninfo+ Alvaro Herrera <[email protected]>
0 siblings, 1 reply; 10+ messages in thread
From: Maiquel Grassi @ 2024-04-01 14:53 UTC (permalink / raw)
To: Alvaro Herrera <[email protected]>; +Cc: Imseih (AWS), Sami <[email protected]>; Nathan Bossart <[email protected]>; Jim Jones <[email protected]>; Pavel Luzanov <[email protected]>; Erik Wienhold <[email protected]>; pgsql-hackers
Hi!
(v24)
> I meant those columns to be just examples, but this should be applied to
> all the other columns in the output as well.
Applied the translation to all columns.
Regards,
Maiquel Grassi.
Attachments:
[application/octet-stream] v24-0001-psql-meta-command-conninfo-plus.patch (16.0K, ../../CP8P284MB24967A3224213796D569D4F2EC3F2@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM/3-v24-0001-psql-meta-command-conninfo-plus.patch)
download | inline diff:
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index cc7d797..107ece9 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1029,11 +1029,128 @@ INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g
</varlistentry>
<varlistentry id="app-psql-meta-command-conninfo">
- <term><literal>\conninfo</literal></term>
+ <term><literal>\conninfo[+]</literal></term>
<listitem>
<para>
- Outputs information about the current database connection.
+ Outputs a string displaying information about the current
+ database connection. When <literal>+</literal> is appended,
+ more details about the connection are displayed in table
+ format:
</para>
+
+ <para>
+ <literal>Database:</literal> The name of the current
+ database on this connection.
+ </para>
+
+ <para>
+ <literal>Authenticated User:</literal> The authenticated
+ user at the time of psql connection with the server.
+ </para>
+
+ <para>
+ <literal>Socket Directory:</literal> The socket directory of the connection.
+ NULL if the host or hostaddr are specified for the connection.
+ </para>
+
+ <para>
+ <literal>Host:</literal> The host of the connection, which refers to the
+ address or name of the machine where the server is running. When a socket
+ connection is established, it displays NULL.
+ </para>
+
+ <para>
+ <literal>Server Port:</literal> The IP port number on which the server
+ accepted the current connection, or NULL if the current connection is
+ via a Unix-domain socket.
+ </para>
+
+ <para>
+ <literal>Server Address:</literal> The IP address on which the server
+ accepted the current connection, or NULL if the current connection is
+ via a Unix-domain socket.
+ </para>
+
+ <para>
+ <literal>Client Address:</literal> The IP address of the current client,
+ or NULL if the current connection is via a Unix-domain socket.
+ </para>
+
+ <para>
+ <literal>Client Port:</literal> The IP port number of the current client,
+ or NULL if the current connection is via a Unix-domain socket.
+ </para>
+
+ <para>
+ <literal>Backend PID:</literal> The process ID of the server process
+ attached to the current session.
+ </para>
+
+ <para>
+ <literal>System User:</literal> Returns the authentication method
+ and the identity (if any) that the user presented during the
+ authentication cycle before they were assigned a database role. It
+ is represented as auth_method:identity or NULL if the user has not
+ been authenticated.
+ </para>
+
+ <para>
+ <literal>Current User:</literal> The user name of the current
+ execution context.
+ </para>
+
+ <para>
+ <literal>Session User:</literal> The session user's name.
+ </para>
+
+ <para>
+ <literal>Application Name:</literal> The application name, in the case
+ user sets the 'application_name' within a connection or in
+ the connection string.
+ </para>
+
+ <para>
+ <literal>SSL Connection:</literal> True if the current connection to the
+ server uses SSL, and false otherwise.
+ </para>
+
+ <para>
+ <literal>SSL Protocol:</literal> The name of the protocol used for the SSL
+ connection (e.g., TLSv1.0, TLSv1.1, TLSv1.2 or TLSv1.3).
+ </para>
+
+ <para>
+ <literal>SSL Cipher:</literal> Displays the name of the cipher used
+ for the SSL connection (e.g., DHE-RSA-AES256-SHA).
+ </para>
+
+ <para>
+ <literal>SLL Compression:</literal> On if SSL compression is in use, off
+ if not, or NULL if SSL is not in use on this connection.
+ </para>
+
+ <para>
+ <literal>GSSAPI Authenticated:</literal> True if GSSAPI is in use, or false
+ if GSSAPI is not in use on this connection.
+ </para>
+
+ <para>
+ <literal>GSSAPI Principal:</literal> "Principal" used to authenticate this
+ connection, or NULL if GSSAPI was not used to authenticate this connection.
+ This field is truncated if the principal is longer than NAMEDATALEN
+ (64 characters in a standard build).
+ </para>
+
+ <para>
+ <literal>GSSAPI Encrypted:</literal> True if GSSAPI encryption is in use on
+ this connection, or false if encryption is not in use.
+ </para>
+
+ <para>
+ <literal>GSSAPI Credentials Delegated:</literal> True if GSSAPI credentials
+ were delegated on this connection, or false if were not delegated.
+ </para>
+
</listitem>
</varlistentry>
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 9b0fa04..af389d4 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -68,7 +68,8 @@ static backslashResult exec_command_C(PsqlScanState scan_state, bool active_bran
static backslashResult exec_command_connect(PsqlScanState scan_state, bool active_branch);
static backslashResult exec_command_cd(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);
@@ -317,8 +318,8 @@ exec_command(const char *cmd,
status = exec_command_connect(scan_state, active_branch);
else if (strcmp(cmd, "cd") == 0)
status = exec_command_cd(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)
@@ -643,47 +644,79 @@ exec_command_cd(PsqlScanState scan_state, bool active_branch, const char *cmd)
}
/*
- * \conninfo -- display information about the current connection
+ * \conninfo, \conninfo+ -- display information about the current connection
*/
static backslashResult
-exec_command_conninfo(PsqlScanState scan_state, bool active_branch)
+exec_command_conninfo(PsqlScanState scan_state, bool active_branch, const char *cmd)
{
+ bool success = true;
+
if (active_branch)
{
char *db = PQdb(pset.db);
+ bool show_verbose;
+
+ show_verbose = strchr(cmd, '+') ? true : false;
- if (db == NULL)
- printf(_("You are currently not connected to a database.\n"));
+ /*
+ * \conninfo+
+ */
+ if (show_verbose)
+ success = listConnectionInformation();
+
+ /*
+ * \conninfo
+ */
else
{
- char *host = PQhost(pset.db);
- char *hostaddr = PQhostaddr(pset.db);
+ PGresult *res;
+ PQExpBufferData buf;
- if (is_unixsock_path(host))
- {
- /* hostaddr overrides host */
- if (hostaddr && *hostaddr)
- printf(_("You are connected to database \"%s\" as user \"%s\" on address \"%s\" at port \"%s\".\n"),
- db, PQuser(pset.db), hostaddr, PQport(pset.db));
- else
- printf(_("You are connected to database \"%s\" as user \"%s\" via socket in \"%s\" at port \"%s\".\n"),
- db, PQuser(pset.db), host, PQport(pset.db));
- }
+ initPQExpBuffer(&buf);
+
+ printfPQExpBuffer(&buf,
+ "SELECT inet_server_addr();");
+
+ res = PSQLexec(buf.data);
+
+ termPQExpBuffer(&buf);
+
+ if (!res)
+ return PSQL_CMD_ERROR;
else
{
- if (hostaddr && *hostaddr && strcmp(host, hostaddr) != 0)
- printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" (address \"%s\") at port \"%s\".\n"),
- db, PQuser(pset.db), host, hostaddr, PQport(pset.db));
+ char *host = PQhost(pset.db);
+ char *hostaddr = PQhostaddr(pset.db);
+
+ if (is_unixsock_path(host))
+ {
+ /* hostaddr overrides host */
+ if (hostaddr && *hostaddr)
+ printf(_("You are connected to database \"%s\" as user \"%s\" on address \"%s\" at port \"%s\".\n"),
+ db, PQuser(pset.db), PQgetvalue(res, 0, 0), PQport(pset.db));
+ else
+ printf(_("You are connected to database \"%s\" as user \"%s\" via socket in \"%s\" at port \"%s\".\n"),
+ db, PQuser(pset.db), host, PQport(pset.db));
+ }
else
- printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" at port \"%s\".\n"),
- db, PQuser(pset.db), host, PQport(pset.db));
+ {
+ if (hostaddr && *hostaddr && strcmp(host, hostaddr) != 0)
+ printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" (address \"%s\") at port \"%s\".\n"),
+ db, PQuser(pset.db), host, PQgetvalue(res, 0, 0), PQport(pset.db));
+ else
+ printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" at port \"%s\".\n"),
+ db, PQuser(pset.db), host, PQport(pset.db));
+ }
+ PQclear(res);
+ printSSLInfo();
+ printGSSInfo();
}
- printSSLInfo();
- printGSSInfo();
}
}
+ else
+ ignore_slash_options(scan_state);
- return PSQL_CMD_SKIP_LINE;
+ return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR;
}
/*
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 6433497..820a717 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -26,6 +26,7 @@
#include "fe_utils/mbprint.h"
#include "fe_utils/print.h"
#include "fe_utils/string_utils.h"
+#include "libpq/pqcomm.h"
#include "settings.h"
#include "variables.h"
@@ -901,6 +902,174 @@ error_return:
return false;
}
+/*
+ * listConnectionInformation
+ *
+ * for \conninfo+
+ */
+bool
+listConnectionInformation(void)
+{
+ PGresult *res;
+ PQExpBufferData buf;
+ printQueryOpt myopt = pset.popt;
+
+ char *host = PQhost(pset.db);
+ char *hostaddr = PQhostaddr(pset.db);
+
+ initPQExpBuffer(&buf);
+
+ printfPQExpBuffer(&buf,
+ "SELECT\n"
+ " pg_catalog.current_database() AS \"%s\",\n"
+ " '%s' AS \"%s\",\n",
+ _("Database"),
+ PQuser(pset.db),
+ _("Authenticated User"));
+ if (is_unixsock_path(host) && !(hostaddr && *hostaddr))
+ appendPQExpBuffer(&buf,
+ " '%s' AS \"%s\",\n",
+ host,
+ _("Socket Directory"));
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n",
+ _("Socket Directory"));
+ appendPQExpBuffer(&buf,
+ " CASE\n"
+ " WHEN\n"
+ " pg_catalog.inet_server_addr() IS NULL\n"
+ " AND pg_catalog.inet_client_addr() IS NULL\n"
+ " THEN NULL\n"
+ " ELSE '%s'\n"
+ " END AS \"%s\",\n",
+ _("Host"),
+ host);
+ appendPQExpBuffer(&buf,
+ " pg_catalog.current_setting('port') AS \"%s\",\n"
+ " pg_catalog.inet_server_addr() AS \"%s\",\n"
+ " pg_catalog.inet_client_addr() AS \"%s\",\n"
+ " pg_catalog.inet_client_port() AS \"%s\",\n"
+ " pg_catalog.pg_backend_pid() AS \"%s\",\n",
+ _("Server Port"),
+ _("Server Address"),
+ _("Client Address"),
+ _("Client Port"),
+ _("Backend PID"));
+ if (pset.sversion >= 160000)
+ appendPQExpBuffer(&buf,
+ " pg_catalog.system_user() AS \"%s\",\n",
+ _("System User"));
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n",
+ _("System User"));
+ appendPQExpBuffer(&buf,
+ " pg_catalog.current_user() AS \"%s\",\n"
+ " pg_catalog.session_user() AS \"%s\",\n"
+ " pg_catalog.current_setting('application_name') AS \"%s\",\n",
+ _("Current User"),
+ _("Session User"),
+ _("Application Name"));
+ if (pset.sversion >= 90500)
+ {
+ if (pset.sversion < 140000)
+ appendPQExpBuffer(&buf,
+ " ssl.ssl AS \"%s\",\n"
+ " ssl.version AS \"%s\",\n"
+ " ssl.cipher AS \"%s\",\n"
+ " ssl.compression AS \"%s\",\n",
+ _("SSL Connection"),
+ _("SSL Protocol"),
+ _("SSL Cipher"),
+ _("SSL Compression"));
+ if (pset.sversion >= 140000)
+ appendPQExpBuffer(&buf,
+ " ssl.ssl AS \"%s\",\n"
+ " ssl.version AS \"%s\",\n"
+ " ssl.cipher AS \"%s\",\n"
+ " NULL AS \"%s\",\n",
+ _("SSL Connection"),
+ _("SSL Protocol"),
+ _("SSL Cipher"),
+ _("SSL Compression"));
+ }
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n",
+ _("SSL Connection"),
+ _("SSL Protocol"),
+ _("SSL Cipher"),
+ _("SSL Compression"));
+ if (pset.sversion >= 120000)
+ {
+ if (pset.sversion >= 160000)
+ appendPQExpBuffer(&buf,
+ " gssapi.gss_authenticated AS \"%s\",\n"
+ " gssapi.principal AS \"%s\",\n"
+ " gssapi.\"encrypted\" AS \"%s\",\n"
+ " gssapi.credentials_delegated AS \"%s\"\n",
+ _("GSSAPI Authenticated"),
+ _("GSSAPI Principal"),
+ _("GSSAPI Encrypted"),
+ _("GSSAPI Credentials Delegated"));
+ if (pset.sversion < 160000)
+ appendPQExpBuffer(&buf,
+ " gssapi.gss_authenticated AS \"%s\",\n"
+ " gssapi.principal AS \"%s\",\n"
+ " gssapi.\"encrypted\" AS \"%s\",\n"
+ " NULL AS \"%s\"\n",
+ _("GSSAPI Authenticated"),
+ _("GSSAPI Principal"),
+ _("GSSAPI Encrypted"),
+ _("GSSAPI Credentials Delegated"));
+ }
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\"\n",
+ _("GSSAPI Authenticated"),
+ _("GSSAPI Principal"),
+ _("GSSAPI Encrypted"),
+ _("GSSAPI Credentials Delegated"));
+ if (pset.sversion >= 90500 && pset.sversion < 120000)
+ appendPQExpBuffer(&buf,
+ "FROM\n"
+ " pg_catalog.pg_stat_ssl ssl\n"
+ "WHERE\n"
+ " ssl.pid = pg_catalog.pg_backend_pid()\n"
+ ";");
+ if (pset.sversion >= 120000)
+ appendPQExpBuffer(&buf,
+ "FROM\n"
+ " pg_catalog.pg_stat_ssl ssl\n"
+ "LEFT JOIN\n"
+ " pg_catalog.pg_stat_gssapi gssapi ON ssl.pid = gssapi.pid\n"
+ "WHERE\n"
+ " ssl.pid = pg_catalog.pg_backend_pid()\n"
+ ";");
+ if (pset.sversion < 90500)
+ appendPQExpBuffer(&buf,
+ ";");
+
+ res = PSQLexec(buf.data);
+ termPQExpBuffer(&buf);
+ if (!res)
+ return false;
+
+ myopt.title = _("Current Connection Information");
+ myopt.translate_header = true;
+
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
+
+ PQclear(res);
+ return true;
+}
/*
* listAllDbs
diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h
index 273f974..8a4e83f 100644
--- a/src/bin/psql/describe.h
+++ b/src/bin/psql/describe.h
@@ -64,6 +64,9 @@ extern bool listTSDictionaries(const char *pattern, bool verbose);
/* \dFt */
extern bool listTSTemplates(const char *pattern, bool verbose);
+/* \conninfo */
+extern bool listConnectionInformation(void);
+
/* \l */
extern bool listAllDbs(const char *pattern, bool verbose);
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 4e79a81..2c5426d 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -310,7 +310,7 @@ slashUsage(unsigned short int pager)
else
HELP0(" \\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}\n"
" connect to new database (currently no connection)\n");
- HELP0(" \\conninfo display information about current connection\n");
+ HELP0(" \\conninfo[+] display information about current connection\n");
HELP0(" \\encoding [ENCODING] show or set client encoding\n");
HELP0(" \\password [USERNAME] securely change the password for a user\n");
HELP0("\n");
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Psql meta-command conninfo+
2024-04-01 14:53 RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
@ 2024-04-01 16:22 ` Alvaro Herrera <[email protected]>
2024-04-01 17:45 ` Re: Psql meta-command conninfo+ Imseih (AWS), Sami <[email protected]>
2024-04-01 19:51 ` RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
0 siblings, 2 replies; 10+ messages in thread
From: Alvaro Herrera @ 2024-04-01 16:22 UTC (permalink / raw)
To: Maiquel Grassi <[email protected]>; +Cc: Imseih (AWS), Sami <[email protected]>; Nathan Bossart <[email protected]>; Jim Jones <[email protected]>; Pavel Luzanov <[email protected]>; Erik Wienhold <[email protected]>; pgsql-hackers
Hello
Yeah, that's what I meant about the translations, thanks.
Two more comments,
- You don't need a two-level conditional here
if (pset.sversion >= 90500)
{
if (pset.sversion < 140000)
appendPQExpBuffer(&buf,
" ssl.ssl AS \"%s\",\n"
" ssl.version AS \"%s\",\n"
" ssl.cipher AS \"%s\",\n"
" ssl.compression AS \"%s\",\n",
_("SSL Connection"),
_("SSL Protocol"),
_("SSL Cipher"),
_("SSL Compression"));
if (pset.sversion >= 140000)
appendPQExpBuffer(&buf,
" ssl.ssl AS \"%s\",\n"
" ssl.version AS \"%s\",\n"
" ssl.cipher AS \"%s\",\n"
" NULL AS \"%s\",\n",
_("SSL Connection"),
_("SSL Protocol"),
_("SSL Cipher"),
_("SSL Compression"));
}
else
appendPQExpBuffer(&buf,
" NULL AS \"%s\",\n"
" NULL AS \"%s\",\n"
" NULL AS \"%s\",\n"
" NULL AS \"%s\",\n",
_("SSL Connection"),
_("SSL Protocol"),
_("SSL Cipher"),
_("SSL Compression"));
Instead you can just do something like
if (pset.version >= 140000)
one thing;
else if (pset.version > 90500)
second thing;
else
third thing;
This also appears where you add the GSSAPI columns; and it's also in the
final part where you append the FROM clause, though it looks a bit
different there.
- You have three lines to output a semicolon at the end of the query
based on version number. Remove the first two, and just have a final
one where the semicolon is added unconditionally.
- I don't think one <para> for each item in the docs is reasonable.
There's too much vertical whitespace in the output. Maybe do this
instead:
[...]
database connection. When <literal>+</literal> is appended,
more details about the connection are displayed in table
format:
<simplelist>
<member>
<term>Database:</term> The name of the current
database on this connection.
</member>
<member>
<term>Authenticated User:</term> The authenticated
user at the time of psql connection with the server.
</member>
...
</simplelist>
- This text is wrong to start with "Returns the":
System User: Returns the authentication method and the identity (if
any) that the user presented during the authentication cycle before
they were assigned a database role. It is represented as
auth_method:identity or NULL if the user has not been authenticated.
That minor point aside, I disagree with Sami about repeating the docs
for system_user() here. I would just say "The authentication data
provided for this connection; see the function system_user() for more
details." with a link to the appropriate section of the docs. Making
us edit this doc if we ever modify the behavior of the function is not
great.
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"We're here to devour each other alive" (Hobbes)
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Psql meta-command conninfo+
2024-04-01 14:53 RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-01 16:22 ` Re: Psql meta-command conninfo+ Alvaro Herrera <[email protected]>
@ 2024-04-01 17:45 ` Imseih (AWS), Sami <[email protected]>
1 sibling, 0 replies; 10+ messages in thread
From: Imseih (AWS), Sami @ 2024-04-01 17:45 UTC (permalink / raw)
To: Alvaro Herrera <[email protected]>; Maiquel Grassi <[email protected]>; +Cc: Nathan Bossart <[email protected]>; Jim Jones <[email protected]>; Pavel Luzanov <[email protected]>; Erik Wienhold <[email protected]>; pgsql-hackers
> That minor point aside, I disagree with Sami about repeating the docs
> for system_user() here. I would just say "The authentication data
> provided for this connection; see the function system_user() for more
> details."
+1. FWIW; Up the thread [1], I did mention we should link to the functions page,
but did not have a very strong opinion on that.
I do like your suggestion and the same should be done for "Current User"
and "Session User" as well.
[1] https://www.postgresql.org/message-id/640B2586-EECF-44C0-B474-CA8510F8EAFC%40amazon.com
Regards,
Sami
^ permalink raw reply [nested|flat] 10+ messages in thread
* RE: Psql meta-command conninfo+
2024-04-01 14:53 RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-01 16:22 ` Re: Psql meta-command conninfo+ Alvaro Herrera <[email protected]>
@ 2024-04-01 19:51 ` Maiquel Grassi <[email protected]>
2024-04-01 21:29 ` Re: Psql meta-command conninfo+ Imseih (AWS), Sami <[email protected]>
1 sibling, 1 reply; 10+ messages in thread
From: Maiquel Grassi @ 2024-04-01 19:51 UTC (permalink / raw)
To: Alvaro Herrera <[email protected]>; +Cc: Imseih (AWS), Sami <[email protected]>; Nathan Bossart <[email protected]>; Jim Jones <[email protected]>; Pavel Luzanov <[email protected]>; Erik Wienhold <[email protected]>; pgsql-hackers
Amigos, boa tarde!
(v25)
> if (pset.version >= 140000)
> one thing;
> else if (pset.version > 90500)
> second thing;
> else
> third thing;
>
> This also appears where you add the GSSAPI columns; and it's also in the
> final part where you append the FROM clause, though it looks a bit
> different there.
>
> - You have three lines to output a semicolon at the end of the query
> based on version number. Remove the first two, and just have a final
> one where the semicolon is added unconditionally.
Adjustment made.
> - I don't think one <para> for each item in the docs is reasonable.
> There's too much vertical whitespace in the output. Maybe do this
> instead:
>
> [...]
> database connection. When <literal>+</literal> is appended,
> more details about the connection are displayed in table
> format:
>
> <simplelist>
> <member>
> <term>Database:</term> The name of the current
> database on this connection.
> </member>
>
> <member>
> <term>Authenticated User:</term> The authenticated
> user at the time of psql connection with the server.
> </member>
>
> ...
> </simplelist>
Adjustment made. But I think it needs a review glance.
> - This text is wrong to start with "Returns the":
>
> System User: Returns the authentication method and the identity (if
> any) that the user presented during the authentication cycle before
> they were assigned a database role. It is represented as
> auth_method:identity or NULL if the user has not been authenticated.
>
> That minor point aside, I disagree with Sami about repeating the docs
> for system_user() here. I would just say "The authentication data
> provided for this connection; see the function system_user() for more
> details." with a link to the appropriate section of the docs. Making
> us edit this doc if we ever modify the behavior of the function is not
> great.
Here I considered your suggestion (Sami and Álvaro's). However, I haven't yet
added the links for the functions system_user(), current_user(), and session_user().
I'm not sure how to do it. Any suggestion on how to create/add the link?
Regards,
Maiquel Grassi.
Attachments:
[application/octet-stream] v25-0001-psql-meta-command-conninfo-plus.patch (15.7K, ../../CP8P284MB2496932B19ABB2394DECF69FEC3F2@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM/3-v25-0001-psql-meta-command-conninfo-plus.patch)
download | inline diff:
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index cc7d797..81d4e6d 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1029,12 +1029,121 @@ INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g
</varlistentry>
<varlistentry id="app-psql-meta-command-conninfo">
- <term><literal>\conninfo</literal></term>
- <listitem>
- <para>
- Outputs information about the current database connection.
- </para>
- </listitem>
+ <term><literal>\conninfo[+]</literal></term>
+ <listitem>
+ Outputs a string displaying information about the current
+ database connection. When <literal>+</literal> is appended,
+ more details about the connection are displayed in table
+ format:
+
+ <simplelist>
+ <member>
+ <term>Database:</term> The database name of the connection.
+ </member>
+
+ <member>
+ <term>Authenticated User:</term> The authenticated database
+ user of the connection.
+ </member>
+
+ <member>
+ <term>Socket Directory:</term> The Unix socket directory of
+ the connection. NULL if host or hostaddr are specified.
+ </member>
+
+ <member>
+ <term>Host:</term> The host name or address of the connection.
+ NULL if a Unix socket is used.
+ </member>
+
+ <member>
+ <term>Server Port:</term> The IP address of the connection.
+ NULL if a Unix socket is used.
+ </member>
+
+ <member>
+ <term>Server Address:</term> The IP address of the host name.
+ NULL if a Unix socket is used.
+ </member>
+
+ <member>
+ <term>Client Address:</term> The IP address of the client connected
+ to this backend. NULL if a Unix socket is used.
+ </member>
+
+ <member>
+ <term>Client Port:</term> The port of the client connected to this
+ backend. NULL if a Unix socket is used.
+ </member>
+
+ <member>
+ <term>Backend PID:</term> The process id of the backend for the connection.
+ </member>
+
+ <member>
+ <term>System User:</term> The authentication data provided for this
+ connection; see the function system_user() for more details.
+ </member>
+
+ <member>
+ <term>Current User:</term> The user name of the current
+ execution context; see the function current_user() for more details.
+ </member>
+
+ <member>
+ <term>Session User:</term> The session user's name; see the
+ function session_user() for more details.
+ </member>
+
+ <member>
+ <term>Application Name:</term> <literal>psql</literal> is the
+ default for a psql connection unless otherwise specified in
+ the <xref linkend="guc-application-name"/> configuration parameter.
+ </member>
+
+ <member>
+ <term>SSL Connection:</term> True if the current connection to the
+ server uses SSL, and false otherwise.
+ </member>
+
+ <member>
+ <term>SSL Protocol:</term> The name of the protocol used for the SSL
+ connection (e.g., TLSv1.0, TLSv1.1, TLSv1.2 or TLSv1.3).
+ </member>
+
+ <member>
+ <term>SSL Cipher:</term> Displays the name of the cipher used
+ for the SSL connection (e.g., DHE-RSA-AES256-SHA).
+ </member>
+
+ <member>
+ <term>SLL Compression:</term> On if SSL compression is in use, off
+ if not, or NULL if SSL is not in use on this connection.
+ </member>
+
+ <member>
+ <term>GSSAPI Authenticated:</term> True if GSSAPI is in use, or false
+ if GSSAPI is not in use on this connection.
+ </member>
+
+ <member>
+ <term>GSSAPI Principal:</term> "Principal" used to authenticate this
+ connection, or NULL if GSSAPI was not used to authenticate this connection.
+ This field is truncated if the principal is longer than NAMEDATALEN
+ (64 characters in a standard build).
+ </member>
+
+ <member>
+ <term>GSSAPI Encrypted:</term> True if GSSAPI encryption is in use on
+ this connection, or false if encryption is not in use.
+ </member>
+
+ <member>
+ <term>GSSAPI Credentials Delegated:</term> True if GSSAPI credentials
+ were delegated on this connection, or false if were not delegated.
+ </member>
+ </simplelist>
+ </listitem>
</varlistentry>
<varlistentry id="app-psql-meta-commands-copy">
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 9b0fa04..af389d4 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -68,7 +68,8 @@ static backslashResult exec_command_C(PsqlScanState scan_state, bool active_bran
static backslashResult exec_command_connect(PsqlScanState scan_state, bool active_branch);
static backslashResult exec_command_cd(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);
@@ -317,8 +318,8 @@ exec_command(const char *cmd,
status = exec_command_connect(scan_state, active_branch);
else if (strcmp(cmd, "cd") == 0)
status = exec_command_cd(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)
@@ -643,47 +644,79 @@ exec_command_cd(PsqlScanState scan_state, bool active_branch, const char *cmd)
}
/*
- * \conninfo -- display information about the current connection
+ * \conninfo, \conninfo+ -- display information about the current connection
*/
static backslashResult
-exec_command_conninfo(PsqlScanState scan_state, bool active_branch)
+exec_command_conninfo(PsqlScanState scan_state, bool active_branch, const char *cmd)
{
+ bool success = true;
+
if (active_branch)
{
char *db = PQdb(pset.db);
+ bool show_verbose;
+
+ show_verbose = strchr(cmd, '+') ? true : false;
- if (db == NULL)
- printf(_("You are currently not connected to a database.\n"));
+ /*
+ * \conninfo+
+ */
+ if (show_verbose)
+ success = listConnectionInformation();
+
+ /*
+ * \conninfo
+ */
else
{
- char *host = PQhost(pset.db);
- char *hostaddr = PQhostaddr(pset.db);
+ PGresult *res;
+ PQExpBufferData buf;
- if (is_unixsock_path(host))
- {
- /* hostaddr overrides host */
- if (hostaddr && *hostaddr)
- printf(_("You are connected to database \"%s\" as user \"%s\" on address \"%s\" at port \"%s\".\n"),
- db, PQuser(pset.db), hostaddr, PQport(pset.db));
- else
- printf(_("You are connected to database \"%s\" as user \"%s\" via socket in \"%s\" at port \"%s\".\n"),
- db, PQuser(pset.db), host, PQport(pset.db));
- }
+ initPQExpBuffer(&buf);
+
+ printfPQExpBuffer(&buf,
+ "SELECT inet_server_addr();");
+
+ res = PSQLexec(buf.data);
+
+ termPQExpBuffer(&buf);
+
+ if (!res)
+ return PSQL_CMD_ERROR;
else
{
- if (hostaddr && *hostaddr && strcmp(host, hostaddr) != 0)
- printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" (address \"%s\") at port \"%s\".\n"),
- db, PQuser(pset.db), host, hostaddr, PQport(pset.db));
+ char *host = PQhost(pset.db);
+ char *hostaddr = PQhostaddr(pset.db);
+
+ if (is_unixsock_path(host))
+ {
+ /* hostaddr overrides host */
+ if (hostaddr && *hostaddr)
+ printf(_("You are connected to database \"%s\" as user \"%s\" on address \"%s\" at port \"%s\".\n"),
+ db, PQuser(pset.db), PQgetvalue(res, 0, 0), PQport(pset.db));
+ else
+ printf(_("You are connected to database \"%s\" as user \"%s\" via socket in \"%s\" at port \"%s\".\n"),
+ db, PQuser(pset.db), host, PQport(pset.db));
+ }
else
- printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" at port \"%s\".\n"),
- db, PQuser(pset.db), host, PQport(pset.db));
+ {
+ if (hostaddr && *hostaddr && strcmp(host, hostaddr) != 0)
+ printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" (address \"%s\") at port \"%s\".\n"),
+ db, PQuser(pset.db), host, PQgetvalue(res, 0, 0), PQport(pset.db));
+ else
+ printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" at port \"%s\".\n"),
+ db, PQuser(pset.db), host, PQport(pset.db));
+ }
+ PQclear(res);
+ printSSLInfo();
+ printGSSInfo();
}
- printSSLInfo();
- printGSSInfo();
}
}
+ else
+ ignore_slash_options(scan_state);
- return PSQL_CMD_SKIP_LINE;
+ return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR;
}
/*
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 6433497..6170c88 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -26,6 +26,7 @@
#include "fe_utils/mbprint.h"
#include "fe_utils/print.h"
#include "fe_utils/string_utils.h"
+#include "libpq/pqcomm.h"
#include "settings.h"
#include "variables.h"
@@ -901,6 +902,165 @@ error_return:
return false;
}
+/*
+ * listConnectionInformation
+ *
+ * for \conninfo+
+ */
+bool
+listConnectionInformation(void)
+{
+ PGresult *res;
+ PQExpBufferData buf;
+ printQueryOpt myopt = pset.popt;
+
+ char *host = PQhost(pset.db);
+ char *hostaddr = PQhostaddr(pset.db);
+
+ initPQExpBuffer(&buf);
+
+ printfPQExpBuffer(&buf,
+ "SELECT\n"
+ " pg_catalog.current_database() AS \"%s\",\n"
+ " '%s' AS \"%s\",\n",
+ _("Database"),
+ PQuser(pset.db),
+ _("Authenticated User"));
+ if (is_unixsock_path(host) && !(hostaddr && *hostaddr))
+ appendPQExpBuffer(&buf,
+ " '%s' AS \"%s\",\n",
+ host,
+ _("Socket Directory"));
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n",
+ _("Socket Directory"));
+ appendPQExpBuffer(&buf,
+ " CASE\n"
+ " WHEN\n"
+ " pg_catalog.inet_server_addr() IS NULL\n"
+ " AND pg_catalog.inet_client_addr() IS NULL\n"
+ " THEN NULL\n"
+ " ELSE '%s'\n"
+ " END AS \"%s\",\n",
+ _("Host"),
+ host);
+ appendPQExpBuffer(&buf,
+ " pg_catalog.current_setting('port') AS \"%s\",\n"
+ " pg_catalog.inet_server_addr() AS \"%s\",\n"
+ " pg_catalog.inet_client_addr() AS \"%s\",\n"
+ " pg_catalog.inet_client_port() AS \"%s\",\n"
+ " pg_catalog.pg_backend_pid() AS \"%s\",\n",
+ _("Server Port"),
+ _("Server Address"),
+ _("Client Address"),
+ _("Client Port"),
+ _("Backend PID"));
+ if (pset.sversion >= 160000)
+ appendPQExpBuffer(&buf,
+ " pg_catalog.system_user() AS \"%s\",\n",
+ _("System User"));
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n",
+ _("System User"));
+ appendPQExpBuffer(&buf,
+ " pg_catalog.current_user() AS \"%s\",\n"
+ " pg_catalog.session_user() AS \"%s\",\n"
+ " pg_catalog.current_setting('application_name') AS \"%s\",\n",
+ _("Current User"),
+ _("Session User"),
+ _("Application Name"));
+ if (pset.sversion >= 140000)
+ appendPQExpBuffer(&buf,
+ " ssl.ssl AS \"%s\",\n"
+ " ssl.version AS \"%s\",\n"
+ " ssl.cipher AS \"%s\",\n"
+ " NULL AS \"%s\",\n",
+ _("SSL Connection"),
+ _("SSL Protocol"),
+ _("SSL Cipher"),
+ _("SSL Compression"));
+ else if (pset.sversion >= 90500)
+ appendPQExpBuffer(&buf,
+ " ssl.ssl AS \"%s\",\n"
+ " ssl.version AS \"%s\",\n"
+ " ssl.cipher AS \"%s\",\n"
+ " ssl.compression AS \"%s\",\n",
+ _("SSL Connection"),
+ _("SSL Protocol"),
+ _("SSL Cipher"),
+ _("SSL Compression"));
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n",
+ _("SSL Connection"),
+ _("SSL Protocol"),
+ _("SSL Cipher"),
+ _("SSL Compression"));
+ if (pset.sversion >= 160000)
+ appendPQExpBuffer(&buf,
+ " gssapi.gss_authenticated AS \"%s\",\n"
+ " gssapi.principal AS \"%s\",\n"
+ " gssapi.\"encrypted\" AS \"%s\",\n"
+ " gssapi.credentials_delegated AS \"%s\"\n",
+ _("GSSAPI Authenticated"),
+ _("GSSAPI Principal"),
+ _("GSSAPI Encrypted"),
+ _("GSSAPI Credentials Delegated"));
+ else if (pset.sversion >= 120000)
+ appendPQExpBuffer(&buf,
+ " gssapi.gss_authenticated AS \"%s\",\n"
+ " gssapi.principal AS \"%s\",\n"
+ " gssapi.\"encrypted\" AS \"%s\",\n"
+ " NULL AS \"%s\"\n",
+ _("GSSAPI Authenticated"),
+ _("GSSAPI Principal"),
+ _("GSSAPI Encrypted"),
+ _("GSSAPI Credentials Delegated"));
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\"\n",
+ _("GSSAPI Authenticated"),
+ _("GSSAPI Principal"),
+ _("GSSAPI Encrypted"),
+ _("GSSAPI Credentials Delegated"));
+ if (pset.sversion >= 120000)
+ appendPQExpBuffer(&buf,
+ "FROM\n"
+ " pg_catalog.pg_stat_ssl ssl\n"
+ "LEFT JOIN\n"
+ " pg_catalog.pg_stat_gssapi gssapi ON ssl.pid = gssapi.pid\n"
+ "WHERE\n"
+ " ssl.pid = pg_catalog.pg_backend_pid()\n");
+ if (pset.sversion >= 90500 && pset.sversion < 120000)
+ appendPQExpBuffer(&buf,
+ "FROM\n"
+ " pg_catalog.pg_stat_ssl ssl\n"
+ "WHERE\n"
+ " ssl.pid = pg_catalog.pg_backend_pid()\n");
+ appendPQExpBuffer(&buf,
+ ";");
+
+ res = PSQLexec(buf.data);
+ termPQExpBuffer(&buf);
+ if (!res)
+ return false;
+
+ myopt.title = _("Current Connection Information");
+ myopt.translate_header = true;
+
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
+
+ PQclear(res);
+ return true;
+}
/*
* listAllDbs
diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h
index 273f974..8a4e83f 100644
--- a/src/bin/psql/describe.h
+++ b/src/bin/psql/describe.h
@@ -64,6 +64,9 @@ extern bool listTSDictionaries(const char *pattern, bool verbose);
/* \dFt */
extern bool listTSTemplates(const char *pattern, bool verbose);
+/* \conninfo */
+extern bool listConnectionInformation(void);
+
/* \l */
extern bool listAllDbs(const char *pattern, bool verbose);
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 4e79a81..2c5426d 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -310,7 +310,7 @@ slashUsage(unsigned short int pager)
else
HELP0(" \\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}\n"
" connect to new database (currently no connection)\n");
- HELP0(" \\conninfo display information about current connection\n");
+ HELP0(" \\conninfo[+] display information about current connection\n");
HELP0(" \\encoding [ENCODING] show or set client encoding\n");
HELP0(" \\password [USERNAME] securely change the password for a user\n");
HELP0("\n");
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Psql meta-command conninfo+
2024-04-01 14:53 RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-01 16:22 ` Re: Psql meta-command conninfo+ Alvaro Herrera <[email protected]>
2024-04-01 19:51 ` RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
@ 2024-04-01 21:29 ` Imseih (AWS), Sami <[email protected]>
2024-04-03 10:01 ` RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
0 siblings, 1 reply; 10+ messages in thread
From: Imseih (AWS), Sami @ 2024-04-01 21:29 UTC (permalink / raw)
To: Maiquel Grassi <[email protected]>; Alvaro Herrera <[email protected]>; +Cc: Nathan Bossart <[email protected]>; Jim Jones <[email protected]>; Pavel Luzanov <[email protected]>; Erik Wienhold <[email protected]>; pgsql-hackers
> Here I considered your suggestion (Sami and Álvaro's). However, I haven't yet
> added the links for the functions system_user(), current_user(), and session_user().
> 'm not sure how to do it. Any suggestion on how to create/add the link?
Here is an example [1] where the session information functions are referenced.
The public doc for this example is in [2].
Something similar can be done here. For example:
The session user's name; see the <function>session_user()</function> function in
<xref linkend="functions-info-session-table"/> for more details.
[1] https://github.com/postgres/postgres/blob/master/doc/src/sgml/system-views.sgml#L1663-L1664
[2] https://www.postgresql.org/docs/16/view-pg-locks.html
Regards,
Sami
^ permalink raw reply [nested|flat] 10+ messages in thread
* RE: Psql meta-command conninfo+
2024-04-01 14:53 RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-01 16:22 ` Re: Psql meta-command conninfo+ Alvaro Herrera <[email protected]>
2024-04-01 19:51 ` RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-01 21:29 ` Re: Psql meta-command conninfo+ Imseih (AWS), Sami <[email protected]>
@ 2024-04-03 10:01 ` Maiquel Grassi <[email protected]>
2024-04-03 17:38 ` Re: Psql meta-command conninfo+ Imseih (AWS), Sami <[email protected]>
0 siblings, 1 reply; 10+ messages in thread
From: Maiquel Grassi @ 2024-04-03 10:01 UTC (permalink / raw)
To: Imseih (AWS), Sami <[email protected]>; Alvaro Herrera <[email protected]>; +Cc: Nathan Bossart <[email protected]>; Jim Jones <[email protected]>; Pavel Luzanov <[email protected]>; Erik Wienhold <[email protected]>; pgsql-hackers
Hello Sami,
(v26)
> Here is an example [1] where the session information functions are referenced.
> The public doc for this example is in [2].
> Something similar can be done here. For example:
> The session user's name; see the <function>session_user()</function> function in
> <xref linkend="functions-info-session-table"/> for more details.
I updated the patch.
Thank you for this help.
Regards,
Maiquel Grassi.
Attachments:
[application/octet-stream] v26-0001-psql-meta-command-conninfo-plus.patch (15.9K, ../../CP8P284MB24966A436D371CE347E97CFFEC3D2@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM/3-v26-0001-psql-meta-command-conninfo-plus.patch)
download | inline diff:
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index cc7d797..a793f53 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1029,12 +1029,124 @@ INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g
</varlistentry>
<varlistentry id="app-psql-meta-command-conninfo">
- <term><literal>\conninfo</literal></term>
- <listitem>
- <para>
- Outputs information about the current database connection.
- </para>
- </listitem>
+ <term><literal>\conninfo[+]</literal></term>
+ <listitem>
+ Outputs a string displaying information about the current
+ database connection. When <literal>+</literal> is appended,
+ more details about the connection are displayed in table
+ format:
+
+ <simplelist>
+ <member>
+ <term>Database:</term> The database name of the connection.
+ </member>
+
+ <member>
+ <term>Authenticated User:</term> The authenticated database
+ user of the connection.
+ </member>
+
+ <member>
+ <term>Socket Directory:</term> The Unix socket directory of
+ the connection. NULL if host or hostaddr are specified.
+ </member>
+
+ <member>
+ <term>Host:</term> The host name or address of the connection.
+ NULL if a Unix socket is used.
+ </member>
+
+ <member>
+ <term>Server Port:</term> The IP address of the connection.
+ NULL if a Unix socket is used.
+ </member>
+
+ <member>
+ <term>Server Address:</term> The IP address of the host name.
+ NULL if a Unix socket is used.
+ </member>
+
+ <member>
+ <term>Client Address:</term> The IP address of the client connected
+ to this backend. NULL if a Unix socket is used.
+ </member>
+
+ <member>
+ <term>Client Port:</term> The port of the client connected to this
+ backend. NULL if a Unix socket is used.
+ </member>
+
+ <member>
+ <term>Backend PID:</term> The process id of the backend for the connection.
+ </member>
+
+ <member>
+ <term>System User:</term> The authentication data provided for this
+ connection; see the <function>system_user()</function> function in
+ <xref linkend="functions-info-session-table"/> for more details.
+ </member>
+
+ <member>
+ <term>Current User:</term> The user name of the current execution context;
+ see the <function>current_user()</function> function in
+ <xref linkend="functions-info-session-table"/> for more details.
+ </member>
+
+ <member>
+ <term>Session User:</term> The session user's name; see the
+ <function>session_user()</function> function in <xref linkend="functions-info-session-table"/>
+ for more details.
+ </member>
+
+ <member>
+ <term>Application Name:</term> <literal>psql</literal> is the
+ default for a psql connection unless otherwise specified in
+ the <xref linkend="guc-application-name"/> configuration parameter.
+ </member>
+
+ <member>
+ <term>SSL Connection:</term> True if the current connection to the
+ server uses SSL, and false otherwise.
+ </member>
+
+ <member>
+ <term>SSL Protocol:</term> The name of the protocol used for the SSL
+ connection (e.g., TLSv1.0, TLSv1.1, TLSv1.2 or TLSv1.3).
+ </member>
+
+ <member>
+ <term>SSL Cipher:</term> Displays the name of the cipher used
+ for the SSL connection (e.g., DHE-RSA-AES256-SHA).
+ </member>
+
+ <member>
+ <term>SLL Compression:</term> On if SSL compression is in use, off
+ if not, or NULL if SSL is not in use on this connection.
+ </member>
+
+ <member>
+ <term>GSSAPI Authenticated:</term> True if GSSAPI is in use, or false
+ if GSSAPI is not in use on this connection.
+ </member>
+
+ <member>
+ <term>GSSAPI Principal:</term> "Principal" used to authenticate this
+ connection, or NULL if GSSAPI was not used to authenticate this connection.
+ This field is truncated if the principal is longer than NAMEDATALEN
+ (64 characters in a standard build).
+ </member>
+
+ <member>
+ <term>GSSAPI Encrypted:</term> True if GSSAPI encryption is in use on
+ this connection, or false if encryption is not in use.
+ </member>
+
+ <member>
+ <term>GSSAPI Credentials Delegated:</term> True if GSSAPI credentials
+ were delegated on this connection, or false if were not delegated.
+ </member>
+ </simplelist>
+ </listitem>
</varlistentry>
<varlistentry id="app-psql-meta-commands-copy">
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index c005624..43ce50e 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -68,7 +68,8 @@ static backslashResult exec_command_C(PsqlScanState scan_state, bool active_bran
static backslashResult exec_command_connect(PsqlScanState scan_state, bool active_branch);
static backslashResult exec_command_cd(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);
@@ -318,8 +319,8 @@ exec_command(const char *cmd,
status = exec_command_connect(scan_state, active_branch);
else if (strcmp(cmd, "cd") == 0)
status = exec_command_cd(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)
@@ -644,47 +645,79 @@ exec_command_cd(PsqlScanState scan_state, bool active_branch, const char *cmd)
}
/*
- * \conninfo -- display information about the current connection
+ * \conninfo, \conninfo+ -- display information about the current connection
*/
static backslashResult
-exec_command_conninfo(PsqlScanState scan_state, bool active_branch)
+exec_command_conninfo(PsqlScanState scan_state, bool active_branch, const char *cmd)
{
+ bool success = true;
+
if (active_branch)
{
char *db = PQdb(pset.db);
+ bool show_verbose;
+
+ show_verbose = strchr(cmd, '+') ? true : false;
- if (db == NULL)
- printf(_("You are currently not connected to a database.\n"));
+ /*
+ * \conninfo+
+ */
+ if (show_verbose)
+ success = listConnectionInformation();
+
+ /*
+ * \conninfo
+ */
else
{
- char *host = PQhost(pset.db);
- char *hostaddr = PQhostaddr(pset.db);
+ PGresult *res;
+ PQExpBufferData buf;
- if (is_unixsock_path(host))
- {
- /* hostaddr overrides host */
- if (hostaddr && *hostaddr)
- printf(_("You are connected to database \"%s\" as user \"%s\" on address \"%s\" at port \"%s\".\n"),
- db, PQuser(pset.db), hostaddr, PQport(pset.db));
- else
- printf(_("You are connected to database \"%s\" as user \"%s\" via socket in \"%s\" at port \"%s\".\n"),
- db, PQuser(pset.db), host, PQport(pset.db));
- }
+ initPQExpBuffer(&buf);
+
+ printfPQExpBuffer(&buf,
+ "SELECT inet_server_addr();");
+
+ res = PSQLexec(buf.data);
+
+ termPQExpBuffer(&buf);
+
+ if (!res)
+ return PSQL_CMD_ERROR;
else
{
- if (hostaddr && *hostaddr && strcmp(host, hostaddr) != 0)
- printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" (address \"%s\") at port \"%s\".\n"),
- db, PQuser(pset.db), host, hostaddr, PQport(pset.db));
+ char *host = PQhost(pset.db);
+ char *hostaddr = PQhostaddr(pset.db);
+
+ if (is_unixsock_path(host))
+ {
+ /* hostaddr overrides host */
+ if (hostaddr && *hostaddr)
+ printf(_("You are connected to database \"%s\" as user \"%s\" on address \"%s\" at port \"%s\".\n"),
+ db, PQuser(pset.db), PQgetvalue(res, 0, 0), PQport(pset.db));
+ else
+ printf(_("You are connected to database \"%s\" as user \"%s\" via socket in \"%s\" at port \"%s\".\n"),
+ db, PQuser(pset.db), host, PQport(pset.db));
+ }
else
- printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" at port \"%s\".\n"),
- db, PQuser(pset.db), host, PQport(pset.db));
+ {
+ if (hostaddr && *hostaddr && strcmp(host, hostaddr) != 0)
+ printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" (address \"%s\") at port \"%s\".\n"),
+ db, PQuser(pset.db), host, PQgetvalue(res, 0, 0), PQport(pset.db));
+ else
+ printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" at port \"%s\".\n"),
+ db, PQuser(pset.db), host, PQport(pset.db));
+ }
+ PQclear(res);
+ printSSLInfo();
+ printGSSInfo();
}
- printSSLInfo();
- printGSSInfo();
}
}
+ else
+ ignore_slash_options(scan_state);
- return PSQL_CMD_SKIP_LINE;
+ return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR;
}
/*
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 6433497..6170c88 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -26,6 +26,7 @@
#include "fe_utils/mbprint.h"
#include "fe_utils/print.h"
#include "fe_utils/string_utils.h"
+#include "libpq/pqcomm.h"
#include "settings.h"
#include "variables.h"
@@ -901,6 +902,165 @@ error_return:
return false;
}
+/*
+ * listConnectionInformation
+ *
+ * for \conninfo+
+ */
+bool
+listConnectionInformation(void)
+{
+ PGresult *res;
+ PQExpBufferData buf;
+ printQueryOpt myopt = pset.popt;
+
+ char *host = PQhost(pset.db);
+ char *hostaddr = PQhostaddr(pset.db);
+
+ initPQExpBuffer(&buf);
+
+ printfPQExpBuffer(&buf,
+ "SELECT\n"
+ " pg_catalog.current_database() AS \"%s\",\n"
+ " '%s' AS \"%s\",\n",
+ _("Database"),
+ PQuser(pset.db),
+ _("Authenticated User"));
+ if (is_unixsock_path(host) && !(hostaddr && *hostaddr))
+ appendPQExpBuffer(&buf,
+ " '%s' AS \"%s\",\n",
+ host,
+ _("Socket Directory"));
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n",
+ _("Socket Directory"));
+ appendPQExpBuffer(&buf,
+ " CASE\n"
+ " WHEN\n"
+ " pg_catalog.inet_server_addr() IS NULL\n"
+ " AND pg_catalog.inet_client_addr() IS NULL\n"
+ " THEN NULL\n"
+ " ELSE '%s'\n"
+ " END AS \"%s\",\n",
+ _("Host"),
+ host);
+ appendPQExpBuffer(&buf,
+ " pg_catalog.current_setting('port') AS \"%s\",\n"
+ " pg_catalog.inet_server_addr() AS \"%s\",\n"
+ " pg_catalog.inet_client_addr() AS \"%s\",\n"
+ " pg_catalog.inet_client_port() AS \"%s\",\n"
+ " pg_catalog.pg_backend_pid() AS \"%s\",\n",
+ _("Server Port"),
+ _("Server Address"),
+ _("Client Address"),
+ _("Client Port"),
+ _("Backend PID"));
+ if (pset.sversion >= 160000)
+ appendPQExpBuffer(&buf,
+ " pg_catalog.system_user() AS \"%s\",\n",
+ _("System User"));
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n",
+ _("System User"));
+ appendPQExpBuffer(&buf,
+ " pg_catalog.current_user() AS \"%s\",\n"
+ " pg_catalog.session_user() AS \"%s\",\n"
+ " pg_catalog.current_setting('application_name') AS \"%s\",\n",
+ _("Current User"),
+ _("Session User"),
+ _("Application Name"));
+ if (pset.sversion >= 140000)
+ appendPQExpBuffer(&buf,
+ " ssl.ssl AS \"%s\",\n"
+ " ssl.version AS \"%s\",\n"
+ " ssl.cipher AS \"%s\",\n"
+ " NULL AS \"%s\",\n",
+ _("SSL Connection"),
+ _("SSL Protocol"),
+ _("SSL Cipher"),
+ _("SSL Compression"));
+ else if (pset.sversion >= 90500)
+ appendPQExpBuffer(&buf,
+ " ssl.ssl AS \"%s\",\n"
+ " ssl.version AS \"%s\",\n"
+ " ssl.cipher AS \"%s\",\n"
+ " ssl.compression AS \"%s\",\n",
+ _("SSL Connection"),
+ _("SSL Protocol"),
+ _("SSL Cipher"),
+ _("SSL Compression"));
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n",
+ _("SSL Connection"),
+ _("SSL Protocol"),
+ _("SSL Cipher"),
+ _("SSL Compression"));
+ if (pset.sversion >= 160000)
+ appendPQExpBuffer(&buf,
+ " gssapi.gss_authenticated AS \"%s\",\n"
+ " gssapi.principal AS \"%s\",\n"
+ " gssapi.\"encrypted\" AS \"%s\",\n"
+ " gssapi.credentials_delegated AS \"%s\"\n",
+ _("GSSAPI Authenticated"),
+ _("GSSAPI Principal"),
+ _("GSSAPI Encrypted"),
+ _("GSSAPI Credentials Delegated"));
+ else if (pset.sversion >= 120000)
+ appendPQExpBuffer(&buf,
+ " gssapi.gss_authenticated AS \"%s\",\n"
+ " gssapi.principal AS \"%s\",\n"
+ " gssapi.\"encrypted\" AS \"%s\",\n"
+ " NULL AS \"%s\"\n",
+ _("GSSAPI Authenticated"),
+ _("GSSAPI Principal"),
+ _("GSSAPI Encrypted"),
+ _("GSSAPI Credentials Delegated"));
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\"\n",
+ _("GSSAPI Authenticated"),
+ _("GSSAPI Principal"),
+ _("GSSAPI Encrypted"),
+ _("GSSAPI Credentials Delegated"));
+ if (pset.sversion >= 120000)
+ appendPQExpBuffer(&buf,
+ "FROM\n"
+ " pg_catalog.pg_stat_ssl ssl\n"
+ "LEFT JOIN\n"
+ " pg_catalog.pg_stat_gssapi gssapi ON ssl.pid = gssapi.pid\n"
+ "WHERE\n"
+ " ssl.pid = pg_catalog.pg_backend_pid()\n");
+ if (pset.sversion >= 90500 && pset.sversion < 120000)
+ appendPQExpBuffer(&buf,
+ "FROM\n"
+ " pg_catalog.pg_stat_ssl ssl\n"
+ "WHERE\n"
+ " ssl.pid = pg_catalog.pg_backend_pid()\n");
+ appendPQExpBuffer(&buf,
+ ";");
+
+ res = PSQLexec(buf.data);
+ termPQExpBuffer(&buf);
+ if (!res)
+ return false;
+
+ myopt.title = _("Current Connection Information");
+ myopt.translate_header = true;
+
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
+
+ PQclear(res);
+ return true;
+}
/*
* listAllDbs
diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h
index 273f974..8a4e83f 100644
--- a/src/bin/psql/describe.h
+++ b/src/bin/psql/describe.h
@@ -64,6 +64,9 @@ extern bool listTSDictionaries(const char *pattern, bool verbose);
/* \dFt */
extern bool listTSTemplates(const char *pattern, bool verbose);
+/* \conninfo */
+extern bool listConnectionInformation(void);
+
/* \l */
extern bool listAllDbs(const char *pattern, bool verbose);
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 4e79a81..2c5426d 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -310,7 +310,7 @@ slashUsage(unsigned short int pager)
else
HELP0(" \\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}\n"
" connect to new database (currently no connection)\n");
- HELP0(" \\conninfo display information about current connection\n");
+ HELP0(" \\conninfo[+] display information about current connection\n");
HELP0(" \\encoding [ENCODING] show or set client encoding\n");
HELP0(" \\password [USERNAME] securely change the password for a user\n");
HELP0("\n");
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Psql meta-command conninfo+
2024-04-01 14:53 RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-01 16:22 ` Re: Psql meta-command conninfo+ Alvaro Herrera <[email protected]>
2024-04-01 19:51 ` RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-01 21:29 ` Re: Psql meta-command conninfo+ Imseih (AWS), Sami <[email protected]>
2024-04-03 10:01 ` RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
@ 2024-04-03 17:38 ` Imseih (AWS), Sami <[email protected]>
2024-04-04 14:57 ` RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
0 siblings, 1 reply; 10+ messages in thread
From: Imseih (AWS), Sami @ 2024-04-03 17:38 UTC (permalink / raw)
To: Maiquel Grassi <[email protected]>; Alvaro Herrera <[email protected]>; +Cc: Nathan Bossart <[email protected]>; Jim Jones <[email protected]>; Pavel Luzanov <[email protected]>; Erik Wienhold <[email protected]>; pgsql-hackers
Building the docs fail for v26. The error is:
ref/psql-ref.sgml:1042: element member: validity error : Element term is not declared in member list of possible children
</member>
^
I am able to build up to v24 before the <para> was replaced with <listitem><member>
I tested building with a modified structure as below; the <listitem> is a <para>
that has a <simplelist> within it. Each field is a simple list member and
the the name of the fields should be <literal>.
<varlistentry id="app-psql-meta-command-conninfo">
<term><literal>\conninfo[+]</literal></term>
<listitem>
<para>
Outputs a string displaying information about the current
database connection. When <literal>+</literal> is appended,
more details about the connection are displayed in table
format:
<simplelist>
<member><literal>Database:</literal>The database name of the connection.</member>
<member><literal>Authenticated User:</literal>The authenticated database user of the connection.</member>
<member><literal>Current User:</literal>The user name of the current execution context;
see the <function>current_user()</function> function in
<xref linkend="functions-info-session-table"/> for more details.</member>
</simplelist>
</para>
</listitem>
</varlistentry>
Regards,
Sami
^ permalink raw reply [nested|flat] 10+ messages in thread
* RE: Psql meta-command conninfo+
2024-04-01 14:53 RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-01 16:22 ` Re: Psql meta-command conninfo+ Alvaro Herrera <[email protected]>
2024-04-01 19:51 ` RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-01 21:29 ` Re: Psql meta-command conninfo+ Imseih (AWS), Sami <[email protected]>
2024-04-03 10:01 ` RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-03 17:38 ` Re: Psql meta-command conninfo+ Imseih (AWS), Sami <[email protected]>
@ 2024-04-04 14:57 ` Maiquel Grassi <[email protected]>
2024-04-04 15:19 ` Re: Psql meta-command conninfo+ Peter Eisentraut <[email protected]>
0 siblings, 1 reply; 10+ messages in thread
From: Maiquel Grassi @ 2024-04-04 14:57 UTC (permalink / raw)
To: Imseih (AWS), Sami <[email protected]>; Alvaro Herrera <[email protected]>; +Cc: Nathan Bossart <[email protected]>; Jim Jones <[email protected]>; Pavel Luzanov <[email protected]>; Erik Wienhold <[email protected]>; pgsql-hackers
Hi folks,
(v28)
I made a modification to a variable in the 'host' column in the archive 'describe.c'.
Test:
[postgres@localhost ~]$ /home/pgsql-17devel/bin/psql -x -p 5432
psql (17devel, server 15.6)
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
-[ RECORD 1 ]----------------+---------
Database | postgres
Authenticated User | postgres
Socket Directory | /tmp
Host |
Server Port | 5432
Server Address |
Client Address |
Client Port |
Backend PID | 26728
System User |
Current User | postgres
Session User | postgres
Application Name | psql
SSL Connection | f
SSL Protocol |
SSL Cipher |
SSL Compression |
GSSAPI Authenticated | f
GSSAPI Principal |
GSSAPI Encrypted | f
GSSAPI Credentials Delegated |
postgres=# \q
[postgres@localhost ~]$ /home/pgsql-17devel/bin/psql -x -p 5000
psql (17devel)
Type "help" for help.
postgres=# \conninfo
You are connected to database "postgres" as user "postgres" via socket in "/tmp" at port "5000".
postgres=# \conninfo+
Current Connection Information
-[ RECORD 1 ]----------------+---------
Database | postgres
Authenticated User | postgres
Socket Directory | /tmp
Host |
Server Port | 5000
Server Address |
Client Address |
Client Port |
Backend PID | 26730
System User |
Current User | postgres
Session User | postgres
Application Name | psql
SSL Connection | f
SSL Protocol |
SSL Cipher |
SSL Compression |
GSSAPI Authenticated | f
GSSAPI Principal |
GSSAPI Encrypted | f
GSSAPI Credentials Delegated | f
Regards,
Maiquel Grassi.
Attachments:
[application/octet-stream] v28-0001-psql-meta-command-conninfo-plus.patch (15.5K, ../../CP8P284MB249615AED23882E1E185C8ABEC3C2@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM/3-v28-0001-psql-meta-command-conninfo-plus.patch)
download | inline diff:
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index cc7d797..06defd0 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1029,12 +1029,64 @@ INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g
</varlistentry>
<varlistentry id="app-psql-meta-command-conninfo">
- <term><literal>\conninfo</literal></term>
- <listitem>
- <para>
- Outputs information about the current database connection.
- </para>
- </listitem>
+ <term><literal>\conninfo[+]</literal></term>
+ <listitem>
+ <para>
+ Outputs a string displaying information about the current
+ database connection. When <literal>+</literal> is appended,
+ more details about the connection are displayed in table
+ format:
+ <simplelist>
+ <member><literal>Database:</literal> The database name of the connection.</member>
+ <member><literal>Authenticated User:</literal> The authenticated database user of
+ the connection.</member>
+ <member><literal>Socket Directory:</literal> The Unix socket directory of the connection.
+ NULL if host or hostaddr are specified.</member>
+ <member><literal>Host:</literal> The host name or address of the connection. NULL if
+ a Unix socket is used.</member>
+ <member><literal>Server Port:</literal> The IP address of the connection. NULL if a
+ Unix socket is used.</member>
+ <member><literal>Server Address:</literal> The IP address of the host name. NULL if a
+ Unix socket is used.</member>
+ <member><literal>Client Address:</literal> The IP address of the client connected to
+ this backend. NULL if a Unix socket is used.</member>
+ <member><literal>Client Port:</literal> The port of the client connected to this
+ backend. NULL if a Unix socket is used.</member>
+ <member><literal>Backend PID:</literal> The process id of the backend for the
+ connection.</member>
+ <member><literal>System User:</literal> The authentication data provided for this
+ connection; see the <function>system_user()</function> function in
+ <xref linkend="functions-info-session-table"/> for more details.</member>
+ <member><literal>Current User:</literal> The user name of the current execution context;
+ see the <function>current_user()</function> function in
+ <xref linkend="functions-info-session-table"/> for more details.</member>
+ <member><literal>Session User:</literal> The session user's name;
+ see the <function>session_user()</function> function in
+ <xref linkend="functions-info-session-table"/> for more details.</member>
+ <member><literal>Application Name:</literal> <literal>psql</literal> is the default for
+ a psql connection unless otherwise specified in the
+ <xref linkend="guc-application-name"/> configuration parameter.</member>
+ <member><literal>SSL Connection:</literal> True if the current connection to the server
+ uses SSL, and false otherwise.</member>
+ <member><literal>SSL Protocol:</literal> The name of the protocol used for the SSL
+ connection (e.g., TLSv1.0, TLSv1.1, TLSv1.2 or TLSv1.3).</member>
+ <member><literal>SSL Cipher:</literal> Displays the name of the cipher used for the SSL
+ connection (e.g., DHE-RSA-AES256-SHA).</member>
+ <member><literal>SLL Compression:</literal> On if SSL compression is in use, off if not,
+ or NULL if SSL is not in use on this connection.</member>
+ <member><literal>GSSAPI Authenticated:</literal> True if GSSAPI is in use, or false if
+ GSSAPI is not in use on this connection.</member>
+ <member><literal>GSSAPI Principal:</literal> "Principal" used to authenticate this
+ connection, or NULL if GSSAPI was not used to authenticate this connection. This
+ field is truncated if the principal is longer than NAMEDATALEN (64 characters in
+ a standard build).</member>
+ <member><literal>GSSAPI Encrypted:</literal> True if GSSAPI encryption is in use on
+ this connection, or false if encryption is not in use.</member>
+ <member><literal>GSSAPI Credentials Delegated:</literal> True if GSSAPI credentials
+ were delegated on this connection, or false if were not delegated.</member>
+ </simplelist>
+ </para>
+ </listitem>
</varlistentry>
<varlistentry id="app-psql-meta-commands-copy">
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index c005624..43ce50e 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -68,7 +68,8 @@ static backslashResult exec_command_C(PsqlScanState scan_state, bool active_bran
static backslashResult exec_command_connect(PsqlScanState scan_state, bool active_branch);
static backslashResult exec_command_cd(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);
@@ -318,8 +319,8 @@ exec_command(const char *cmd,
status = exec_command_connect(scan_state, active_branch);
else if (strcmp(cmd, "cd") == 0)
status = exec_command_cd(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)
@@ -644,47 +645,79 @@ exec_command_cd(PsqlScanState scan_state, bool active_branch, const char *cmd)
}
/*
- * \conninfo -- display information about the current connection
+ * \conninfo, \conninfo+ -- display information about the current connection
*/
static backslashResult
-exec_command_conninfo(PsqlScanState scan_state, bool active_branch)
+exec_command_conninfo(PsqlScanState scan_state, bool active_branch, const char *cmd)
{
+ bool success = true;
+
if (active_branch)
{
char *db = PQdb(pset.db);
+ bool show_verbose;
+
+ show_verbose = strchr(cmd, '+') ? true : false;
- if (db == NULL)
- printf(_("You are currently not connected to a database.\n"));
+ /*
+ * \conninfo+
+ */
+ if (show_verbose)
+ success = listConnectionInformation();
+
+ /*
+ * \conninfo
+ */
else
{
- char *host = PQhost(pset.db);
- char *hostaddr = PQhostaddr(pset.db);
+ PGresult *res;
+ PQExpBufferData buf;
- if (is_unixsock_path(host))
- {
- /* hostaddr overrides host */
- if (hostaddr && *hostaddr)
- printf(_("You are connected to database \"%s\" as user \"%s\" on address \"%s\" at port \"%s\".\n"),
- db, PQuser(pset.db), hostaddr, PQport(pset.db));
- else
- printf(_("You are connected to database \"%s\" as user \"%s\" via socket in \"%s\" at port \"%s\".\n"),
- db, PQuser(pset.db), host, PQport(pset.db));
- }
+ initPQExpBuffer(&buf);
+
+ printfPQExpBuffer(&buf,
+ "SELECT inet_server_addr();");
+
+ res = PSQLexec(buf.data);
+
+ termPQExpBuffer(&buf);
+
+ if (!res)
+ return PSQL_CMD_ERROR;
else
{
- if (hostaddr && *hostaddr && strcmp(host, hostaddr) != 0)
- printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" (address \"%s\") at port \"%s\".\n"),
- db, PQuser(pset.db), host, hostaddr, PQport(pset.db));
+ char *host = PQhost(pset.db);
+ char *hostaddr = PQhostaddr(pset.db);
+
+ if (is_unixsock_path(host))
+ {
+ /* hostaddr overrides host */
+ if (hostaddr && *hostaddr)
+ printf(_("You are connected to database \"%s\" as user \"%s\" on address \"%s\" at port \"%s\".\n"),
+ db, PQuser(pset.db), PQgetvalue(res, 0, 0), PQport(pset.db));
+ else
+ printf(_("You are connected to database \"%s\" as user \"%s\" via socket in \"%s\" at port \"%s\".\n"),
+ db, PQuser(pset.db), host, PQport(pset.db));
+ }
else
- printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" at port \"%s\".\n"),
- db, PQuser(pset.db), host, PQport(pset.db));
+ {
+ if (hostaddr && *hostaddr && strcmp(host, hostaddr) != 0)
+ printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" (address \"%s\") at port \"%s\".\n"),
+ db, PQuser(pset.db), host, PQgetvalue(res, 0, 0), PQport(pset.db));
+ else
+ printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" at port \"%s\".\n"),
+ db, PQuser(pset.db), host, PQport(pset.db));
+ }
+ PQclear(res);
+ printSSLInfo();
+ printGSSInfo();
}
- printSSLInfo();
- printGSSInfo();
}
}
+ else
+ ignore_slash_options(scan_state);
- return PSQL_CMD_SKIP_LINE;
+ return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR;
}
/*
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 6433497..9d74105 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -26,6 +26,7 @@
#include "fe_utils/mbprint.h"
#include "fe_utils/print.h"
#include "fe_utils/string_utils.h"
+#include "libpq/pqcomm.h"
#include "settings.h"
#include "variables.h"
@@ -901,6 +902,165 @@ error_return:
return false;
}
+/*
+ * listConnectionInformation
+ *
+ * for \conninfo+
+ */
+bool
+listConnectionInformation(void)
+{
+ PGresult *res;
+ PQExpBufferData buf;
+ printQueryOpt myopt = pset.popt;
+
+ char *host = PQhost(pset.db);
+ char *hostaddr = PQhostaddr(pset.db);
+
+ initPQExpBuffer(&buf);
+
+ printfPQExpBuffer(&buf,
+ "SELECT\n"
+ " pg_catalog.current_database() AS \"%s\",\n"
+ " '%s' AS \"%s\",\n",
+ _("Database"),
+ PQuser(pset.db),
+ _("Authenticated User"));
+ if (is_unixsock_path(host) && !(hostaddr && *hostaddr))
+ appendPQExpBuffer(&buf,
+ " '%s' AS \"%s\",\n",
+ host,
+ _("Socket Directory"));
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n",
+ _("Socket Directory"));
+ appendPQExpBuffer(&buf,
+ " CASE\n"
+ " WHEN\n"
+ " pg_catalog.inet_server_addr() IS NULL\n"
+ " AND pg_catalog.inet_client_addr() IS NULL\n"
+ " THEN NULL\n"
+ " ELSE '%s'\n"
+ " END AS \"%s\",\n",
+ host,
+ _("Host"));
+ appendPQExpBuffer(&buf,
+ " pg_catalog.current_setting('port') AS \"%s\",\n"
+ " pg_catalog.inet_server_addr() AS \"%s\",\n"
+ " pg_catalog.inet_client_addr() AS \"%s\",\n"
+ " pg_catalog.inet_client_port() AS \"%s\",\n"
+ " pg_catalog.pg_backend_pid() AS \"%s\",\n",
+ _("Server Port"),
+ _("Server Address"),
+ _("Client Address"),
+ _("Client Port"),
+ _("Backend PID"));
+ if (pset.sversion >= 160000)
+ appendPQExpBuffer(&buf,
+ " pg_catalog.system_user() AS \"%s\",\n",
+ _("System User"));
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n",
+ _("System User"));
+ appendPQExpBuffer(&buf,
+ " pg_catalog.current_user() AS \"%s\",\n"
+ " pg_catalog.session_user() AS \"%s\",\n"
+ " pg_catalog.current_setting('application_name') AS \"%s\",\n",
+ _("Current User"),
+ _("Session User"),
+ _("Application Name"));
+ if (pset.sversion >= 140000)
+ appendPQExpBuffer(&buf,
+ " ssl.ssl AS \"%s\",\n"
+ " ssl.version AS \"%s\",\n"
+ " ssl.cipher AS \"%s\",\n"
+ " NULL AS \"%s\",\n",
+ _("SSL Connection"),
+ _("SSL Protocol"),
+ _("SSL Cipher"),
+ _("SSL Compression"));
+ else if (pset.sversion >= 90500)
+ appendPQExpBuffer(&buf,
+ " ssl.ssl AS \"%s\",\n"
+ " ssl.version AS \"%s\",\n"
+ " ssl.cipher AS \"%s\",\n"
+ " ssl.compression AS \"%s\",\n",
+ _("SSL Connection"),
+ _("SSL Protocol"),
+ _("SSL Cipher"),
+ _("SSL Compression"));
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n",
+ _("SSL Connection"),
+ _("SSL Protocol"),
+ _("SSL Cipher"),
+ _("SSL Compression"));
+ if (pset.sversion >= 160000)
+ appendPQExpBuffer(&buf,
+ " gssapi.gss_authenticated AS \"%s\",\n"
+ " gssapi.principal AS \"%s\",\n"
+ " gssapi.\"encrypted\" AS \"%s\",\n"
+ " gssapi.credentials_delegated AS \"%s\"\n",
+ _("GSSAPI Authenticated"),
+ _("GSSAPI Principal"),
+ _("GSSAPI Encrypted"),
+ _("GSSAPI Credentials Delegated"));
+ else if (pset.sversion >= 120000)
+ appendPQExpBuffer(&buf,
+ " gssapi.gss_authenticated AS \"%s\",\n"
+ " gssapi.principal AS \"%s\",\n"
+ " gssapi.\"encrypted\" AS \"%s\",\n"
+ " NULL AS \"%s\"\n",
+ _("GSSAPI Authenticated"),
+ _("GSSAPI Principal"),
+ _("GSSAPI Encrypted"),
+ _("GSSAPI Credentials Delegated"));
+ else
+ appendPQExpBuffer(&buf,
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\",\n"
+ " NULL AS \"%s\"\n",
+ _("GSSAPI Authenticated"),
+ _("GSSAPI Principal"),
+ _("GSSAPI Encrypted"),
+ _("GSSAPI Credentials Delegated"));
+ if (pset.sversion >= 120000)
+ appendPQExpBuffer(&buf,
+ "FROM\n"
+ " pg_catalog.pg_stat_ssl ssl\n"
+ "LEFT JOIN\n"
+ " pg_catalog.pg_stat_gssapi gssapi ON ssl.pid = gssapi.pid\n"
+ "WHERE\n"
+ " ssl.pid = pg_catalog.pg_backend_pid()\n");
+ if (pset.sversion >= 90500 && pset.sversion < 120000)
+ appendPQExpBuffer(&buf,
+ "FROM\n"
+ " pg_catalog.pg_stat_ssl ssl\n"
+ "WHERE\n"
+ " ssl.pid = pg_catalog.pg_backend_pid()\n");
+ appendPQExpBuffer(&buf,
+ ";");
+
+ res = PSQLexec(buf.data);
+ termPQExpBuffer(&buf);
+ if (!res)
+ return false;
+
+ myopt.title = _("Current Connection Information");
+ myopt.translate_header = true;
+
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
+
+ PQclear(res);
+ return true;
+}
/*
* listAllDbs
diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h
index 273f974..8a4e83f 100644
--- a/src/bin/psql/describe.h
+++ b/src/bin/psql/describe.h
@@ -64,6 +64,9 @@ extern bool listTSDictionaries(const char *pattern, bool verbose);
/* \dFt */
extern bool listTSTemplates(const char *pattern, bool verbose);
+/* \conninfo */
+extern bool listConnectionInformation(void);
+
/* \l */
extern bool listAllDbs(const char *pattern, bool verbose);
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 4e79a81..2c5426d 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -310,7 +310,7 @@ slashUsage(unsigned short int pager)
else
HELP0(" \\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}\n"
" connect to new database (currently no connection)\n");
- HELP0(" \\conninfo display information about current connection\n");
+ HELP0(" \\conninfo[+] display information about current connection\n");
HELP0(" \\encoding [ENCODING] show or set client encoding\n");
HELP0(" \\password [USERNAME] securely change the password for a user\n");
HELP0("\n");
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Psql meta-command conninfo+
2024-04-01 14:53 RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-01 16:22 ` Re: Psql meta-command conninfo+ Alvaro Herrera <[email protected]>
2024-04-01 19:51 ` RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-01 21:29 ` Re: Psql meta-command conninfo+ Imseih (AWS), Sami <[email protected]>
2024-04-03 10:01 ` RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-03 17:38 ` Re: Psql meta-command conninfo+ Imseih (AWS), Sami <[email protected]>
2024-04-04 14:57 ` RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
@ 2024-04-04 15:19 ` Peter Eisentraut <[email protected]>
0 siblings, 0 replies; 10+ messages in thread
From: Peter Eisentraut @ 2024-04-04 15:19 UTC (permalink / raw)
To: Maiquel Grassi <[email protected]>; Imseih (AWS), Sami <[email protected]>; Alvaro Herrera <[email protected]>; +Cc: Nathan Bossart <[email protected]>; Jim Jones <[email protected]>; Pavel Luzanov <[email protected]>; Erik Wienhold <[email protected]>; pgsql-hackers
The existing \conninfo command gets its values from libpq APIs. You are
changing all of this to make a server query, which is a totally
different thing. If we wanted to take a change like this, I don't think
it should be reusing the \conninfo command.
But I don't really see the point of this. The information you are
querying is already available in various system views. This proposal is
just a shorthand for a collection of various random things some people
like to see. Like, by what reason is application name included as
connection info? Why not any other session settings? What about
long-term maintenance: By what logic should things be added to this?
^ permalink raw reply [nested|flat] 10+ messages in thread
end of thread, other threads:[~2024-04-04 15:19 UTC | newest]
Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-03-10 09:14 [PATCH 8/8] default to --with-lz4 Dilip Kumar <[email protected]>
2024-04-01 14:53 RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-01 16:22 ` Re: Psql meta-command conninfo+ Alvaro Herrera <[email protected]>
2024-04-01 17:45 ` Re: Psql meta-command conninfo+ Imseih (AWS), Sami <[email protected]>
2024-04-01 19:51 ` RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-01 21:29 ` Re: Psql meta-command conninfo+ Imseih (AWS), Sami <[email protected]>
2024-04-03 10:01 ` RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-03 17:38 ` Re: Psql meta-command conninfo+ Imseih (AWS), Sami <[email protected]>
2024-04-04 14:57 ` RE: Psql meta-command conninfo+ Maiquel Grassi <[email protected]>
2024-04-04 15:19 ` Re: Psql meta-command conninfo+ Peter Eisentraut <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox