Re: How about a psql backslash command to show GUCs? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: How about a psql backslash command to show GUCs?
Date
Msg-id 3221981.1649300574@sss.pgh.pa.us
Whole thread Raw
In response to Re: How about a psql backslash command to show GUCs?  ("Jonathan S. Katz" <jkatz@postgresql.org>)
Responses Re: How about a psql backslash command to show GUCs?  (Joe Conway <mail@joeconway.com>)
Re: How about a psql backslash command to show GUCs?  (Justin Pryzby <pryzby@telsasoft.com>)
List pgsql-hackers
"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

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*"))

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: Skipping logical replication transactions on subscriber side
Next
From: "wangw.fnst@fujitsu.com"
Date:
Subject: RE: Data is copied twice when specifying both child and parent table in publication