pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jonathan S. Katz <jkatz@postgresql.org>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: Joe Conway <mail@joeconway.com>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Mark Dilger <mark.dilger@enterprisedb.com>
Subject: Re: How about a psql backslash command to show GUCs?
Date: Wed, 06 Apr 2022 23:02:54 -0400
Message-ID: <3221981.1649300574@sss.pgh.pa.us> (raw)
In-Reply-To: <6693b128-b9e5-fd5e-e8d2-b331dac52cb8@postgresql.org>
References: <202204061758.leffczewl4kd@alvherre.pgsql>
	<ae4c3347-d1c7-394f-9a7e-425af6f89a80@joeconway.com>
	<3123259.1649270440@sss.pgh.pa.us>
	<38891fd8-dceb-c956-ec5c-61c1a3e9486d@postgresql.org>
	<3201870.1649294165@sss.pgh.pa.us>
	<CAKFQuwaqBF_QoQC8aoqBiY4ggvBU6fR0k6CjeTQcoLy_9V4Sng@mail.gmail.com>
	<6693b128-b9e5-fd5e-e8d2-b331dac52cb8@postgresql.org>

"Jonathan S. Katz" <jkatz@postgresql.org> writes:
> +1 for \dconf

Here's a draft patch using \dconf.  No tests or docs yet.

			regards, tom lane

Attachments:

add-backslash-dconf-0.1.-patch (text/x-diff, 5.4K) download diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 079f4a1a76..bbf4a5a44e 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -780,7 +780,14 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd) success = describeTablespaces(pattern, show_verbose); break; case 'c': - success = listConversions(pattern, show_verbose, show_system); + if (strncmp(cmd, "dconf", 5) == 0) + success = describeConfigurationParameters(pattern, + show_verbose, + show_system); + else + success = listConversions(pattern, + show_verbose, + show_system); break; case 'C': success = listCasts(pattern, show_verbose); diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 4dddf08789..e55cfcb2f3 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -4430,6 +4430,68 @@ listConversions(const char *pattern, bool verbose, bool showSystem) return true; } +/* + * \dconf + * + * Describes configuration parameters. + */ +bool +describeConfigurationParameters(const char *pattern, bool verbose, + bool showSystem) +{ + PQExpBufferData buf; + PGresult *res; + printQueryOpt myopt = pset.popt; + + initPQExpBuffer(&buf); + printfPQExpBuffer(&buf, + "SELECT s.name AS \"%s\", s.setting AS \"%s\", " + "s.unit AS \"%s\", s.vartype AS \"%s\"", + gettext_noop("Parameter"), + gettext_noop("Setting"), + gettext_noop("Unit"), + gettext_noop("Type")); + + if (verbose) + { + appendPQExpBuffer(&buf, ", s.context AS \"%s\", ", + gettext_noop("Context")); + if (pset.sversion >= 150000) + printACLColumn(&buf, "p.paracl"); + else + appendPQExpBuffer(&buf, "NULL AS \"%s\"", + gettext_noop("Access privileges")); + } + + appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_settings s\n"); + + if (verbose && pset.sversion >= 150000) + appendPQExpBufferStr(&buf, + " LEFT JOIN pg_catalog.pg_parameter_acl p\n" + " ON pg_catalog.lower(s.name) = p.parname\n"); + + processSQLNamePattern(pset.db, &buf, pattern, + false, false, + NULL, "pg_catalog.lower(s.name)", NULL, + NULL); + + appendPQExpBufferStr(&buf, "ORDER BY 1;"); + + res = PSQLexec(buf.data); + termPQExpBuffer(&buf); + if (!res) + return false; + + myopt.nullPrint = NULL; + myopt.title = _("List of configuration parameters"); + myopt.translate_header = true; + + printQuery(res, &myopt, pset.queryFout, false, pset.logfile); + + PQclear(res); + return true; +} + /* * \dy * diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h index fd6079679c..4eb2710e27 100644 --- a/src/bin/psql/describe.h +++ b/src/bin/psql/describe.h @@ -76,6 +76,10 @@ extern bool listDomains(const char *pattern, bool verbose, bool showSystem); /* \dc */ extern bool listConversions(const char *pattern, bool verbose, bool showSystem); +/* \dconf */ +extern bool describeConfigurationParameters(const char *pattern, bool verbose, + bool showSystem); + /* \dC */ extern bool listCasts(const char *pattern, bool verbose); diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index b3971bce64..eff9d1a16e 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -166,7 +166,7 @@ slashUsage(unsigned short int pager) * Use "psql --help=commands | wc" to count correctly. It's okay to count * the USE_READLINE line even in builds without that. */ - output = PageOutput(137, pager ? &(pset.popt.topt) : NULL); + output = PageOutput(138, pager ? &(pset.popt.topt) : NULL); fprintf(output, _("General\n")); fprintf(output, _(" \\copyright show PostgreSQL usage and distribution terms\n")); @@ -231,6 +231,7 @@ slashUsage(unsigned short int pager) fprintf(output, _(" \\dAp[+] [AMPTRN [OPFPTRN]] list support functions of operator families\n")); fprintf(output, _(" \\db[+] [PATTERN] list tablespaces\n")); fprintf(output, _(" \\dc[S+] [PATTERN] list conversions\n")); + fprintf(output, _(" \\dconf[+] [PATTERN] list configuration parameters\n")); fprintf(output, _(" \\dC[+] [PATTERN] list casts\n")); fprintf(output, _(" \\dd[S] [PATTERN] show object descriptions not displayed elsewhere\n")); fprintf(output, _(" \\dD[S+] [PATTERN] list domains\n")); diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 32d0b4855f..015037d626 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -1690,7 +1690,7 @@ psql_completion(const char *text, int start, int end) "\\connect", "\\conninfo", "\\C", "\\cd", "\\copy", "\\copyright", "\\crosstabview", "\\d", "\\da", "\\dA", "\\dAc", "\\dAf", "\\dAo", "\\dAp", - "\\db", "\\dc", "\\dC", "\\dd", "\\ddp", "\\dD", + "\\db", "\\dc", "\\dconf", "\\dC", "\\dd", "\\ddp", "\\dD", "\\des", "\\det", "\\deu", "\\dew", "\\dE", "\\df", "\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl", "\\dL", "\\dm", "\\dn", "\\do", "\\dO", "\\dp", "\\dP", "\\dPi", "\\dPt", @@ -4539,6 +4539,8 @@ psql_completion(const char *text, int start, int end) COMPLETE_WITH_QUERY(Query_for_list_of_access_methods); else if (TailMatchesCS("\\db*")) COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces); + else if (TailMatchesCS("\\dconf*")) + COMPLETE_WITH_QUERY(Query_for_list_of_show_vars); else if (TailMatchesCS("\\dD*")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_domains); else if (TailMatchesCS("\\des*"))

view thread (71+ messages)  latest in thread

Message-ID: <3221981.1649300574@sss.pgh.pa.us>
Permalink:  ../3221981.1649300574@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3221981.1649300574@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jkatz@postgresql.org, david.g.johnston@gmail.com, mail@joeconway.com, alvherre@alvh.no-ip.org, mark.dilger@enterprisedb.com
  Subject: Re: How about a psql backslash command to show GUCs?
  In-Reply-To: <3221981.1649300574@sss.pgh.pa.us>
  References: <202204061758.leffczewl4kd@alvherre.pgsql> <ae4c3347-d1c7-394f-9a7e-425af6f89a80@joeconway.com> <3123259.1649270440@sss.pgh.pa.us> <38891fd8-dceb-c956-ec5c-61c1a3e9486d@postgresql.org> <3201870.1649294165@sss.pgh.pa.us> <CAKFQuwaqBF_QoQC8aoqBiY4ggvBU6fR0k6CjeTQcoLy_9V4Sng@mail.gmail.com> <6693b128-b9e5-fd5e-e8d2-b331dac52cb8@postgresql.org> <3221981.1649300574@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox