]> granicus.if.org Git - postgresql/blobdiff - src/bin/psql/describe.c
psql: Improve display of "for all tables" publications
[postgresql] / src / bin / psql / describe.c
index d1447fe723e90d6769bdcbd2ce128465e9aed1ac..1c268f0b08f916dab4e0ee2e56d157ee3145c9b1 100644 (file)
@@ -6,7 +6,7 @@
  * with servers of versions 7.4 and up.  It's okay to omit irrelevant
  * information for an old server, but not to fail outright.
  *
- * Copyright (c) 2000-2014, PostgreSQL Global Development Group
+ * Copyright (c) 2000-2017, PostgreSQL Global Development Group
  *
  * src/bin/psql/describe.c
  */
 
 #include <ctype.h>
 
+#include "catalog/pg_attribute.h"
+#include "catalog/pg_class.h"
 #include "catalog/pg_default_acl.h"
+#include "fe_utils/string_utils.h"
 
 #include "common.h"
 #include "describe.h"
-#include "dumputils.h"
-#include "mbprint.h"
-#include "print.h"
+#include "fe_utils/mbprint.h"
+#include "fe_utils/print.h"
 #include "settings.h"
 #include "variables.h"
 
@@ -106,7 +108,7 @@ describeAggregates(const char *pattern, bool verbose, bool showSystem)
 
        if (!showSystem && !pattern)
                appendPQExpBufferStr(&buf, "      AND n.nspname <> 'pg_catalog'\n"
-                                                 "      AND n.nspname <> 'information_schema'\n");
+                                                        "      AND n.nspname <> 'information_schema'\n");
 
        processSQLNamePattern(pset.db, &buf, pattern, true, false,
                                                  "n.nspname", "p.proname", NULL,
@@ -114,7 +116,7 @@ describeAggregates(const char *pattern, bool verbose, bool showSystem)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -123,7 +125,74 @@ describeAggregates(const char *pattern, bool verbose, bool showSystem)
        myopt.title = _("List of aggregate functions");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
+
+       PQclear(res);
+       return true;
+}
+
+/* \dA
+ * Takes an optional regexp to select particular access methods
+ */
+bool
+describeAccessMethods(const char *pattern, bool verbose)
+{
+       PQExpBufferData buf;
+       PGresult   *res;
+       printQueryOpt myopt = pset.popt;
+       static const bool translate_columns[] = {false, true, false, false};
+
+       if (pset.sversion < 90600)
+       {
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support access methods.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
+               return true;
+       }
+
+       initPQExpBuffer(&buf);
+
+       printfPQExpBuffer(&buf,
+                                         "SELECT amname AS \"%s\",\n"
+                                         "  CASE amtype"
+                                         " WHEN 'i' THEN '%s'"
+                                         " END AS \"%s\"",
+                                         gettext_noop("Name"),
+                                         gettext_noop("Index"),
+                                         gettext_noop("Type"));
+
+       if (verbose)
+       {
+               appendPQExpBuffer(&buf,
+                                                 ",\n  amhandler AS \"%s\",\n"
+                                         "  pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
+                                                 gettext_noop("Handler"),
+                                                 gettext_noop("Description"));
+       }
+
+       appendPQExpBufferStr(&buf,
+                                                "\nFROM pg_catalog.pg_am\n");
+
+       processSQLNamePattern(pset.db, &buf, pattern, false, false,
+                                                 NULL, "amname", NULL,
+                                                 NULL);
+
+       appendPQExpBufferStr(&buf, "ORDER BY 1;");
+
+       res = PSQLexec(buf.data);
+       termPQExpBuffer(&buf);
+       if (!res)
+               return false;
+
+       myopt.nullPrint = NULL;
+       myopt.title = _("List of access methods");
+       myopt.translate_header = true;
+       myopt.translate_columns = translate_columns;
+       myopt.n_translate_columns = lengthof(translate_columns);
+
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -141,8 +210,11 @@ describeTablespaces(const char *pattern, bool verbose)
 
        if (pset.sversion < 80000)
        {
-               psql_error("The server (version %d.%d) does not support tablespaces.\n",
-                                  pset.sversion / 10000, (pset.sversion / 100) % 100);
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support tablespaces.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
                return true;
        }
 
@@ -176,6 +248,11 @@ describeTablespaces(const char *pattern, bool verbose)
                                                  ",\n  spcoptions AS \"%s\"",
                                                  gettext_noop("Options"));
 
+       if (verbose && pset.sversion >= 90200)
+               appendPQExpBuffer(&buf,
+                                                 ",\n  pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\"",
+                                                 gettext_noop("Size"));
+
        if (verbose && pset.sversion >= 80200)
                appendPQExpBuffer(&buf,
                 ",\n  pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
@@ -190,7 +267,7 @@ describeTablespaces(const char *pattern, bool verbose)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -199,7 +276,7 @@ describeTablespaces(const char *pattern, bool verbose)
        myopt.title = _("List of tablespaces");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -229,7 +306,10 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
        PQExpBufferData buf;
        PGresult   *res;
        printQueryOpt myopt = pset.popt;
-       static const bool translate_columns[] = {false, false, false, false, true, true, true, false, false, false, false};
+       static const bool translate_columns[] = {false, false, false, false, true, true, true, false, true, false, false, false, false};
+
+       /* No "Parallel" column before 9.6 */
+       static const bool translate_columns_pre_96[] = {false, false, false, false, true, true, false, true, false, false, false, false};
 
        if (strlen(functypes) != strspn(functypes, "antwS+"))
        {
@@ -239,8 +319,11 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
 
        if (showWindow && pset.sversion < 80400)
        {
-               psql_error("\\df does not take a \"w\" option with server version %d.%d\n",
-                                  pset.sversion / 10000, (pset.sversion / 100) % 100);
+               char            sverbuf[32];
+
+               psql_error("\\df does not take a \"w\" option with server version %s\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
                return true;
        }
 
@@ -292,7 +375,7 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
                                                  "        END ||\n"
                                                  "        CASE\n"
                         "          WHEN COALESCE(p.proargnames[s.i], '') = '' THEN ''\n"
-                                                 "          ELSE p.proargnames[s.i] || ' ' \n"
+                                                 "          ELSE p.proargnames[s.i] || ' '\n"
                                                  "        END ||\n"
                          "        pg_catalog.format_type(p.proallargtypes[s.i], NULL)\n"
                                                  "      FROM\n"
@@ -341,28 +424,45 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
                                                  gettext_noop("Type"));
 
        if (verbose)
+       {
                appendPQExpBuffer(&buf,
-                                 ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\""
                                                  ",\n CASE\n"
                                                  "  WHEN p.provolatile = 'i' THEN '%s'\n"
                                                  "  WHEN p.provolatile = 's' THEN '%s'\n"
                                                  "  WHEN p.provolatile = 'v' THEN '%s'\n"
-                                                 " END as \"%s\""
-                                  ",\n  pg_catalog.pg_get_userbyid(p.proowner) as \"%s\",\n"
-                                                 "  l.lanname as \"%s\",\n"
-                                                 "  p.prosrc as \"%s\",\n"
-                                 "  pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
-                                                 gettext_noop("definer"),
-                                                 gettext_noop("invoker"),
-                                                 gettext_noop("Security"),
+                                                 " END as \"%s\"",
                                                  gettext_noop("immutable"),
                                                  gettext_noop("stable"),
                                                  gettext_noop("volatile"),
-                                                 gettext_noop("Volatility"),
+                                                 gettext_noop("Volatility"));
+               if (pset.sversion >= 90600)
+                       appendPQExpBuffer(&buf,
+                                                         ",\n CASE\n"
+                                                         "  WHEN p.proparallel = 'r' THEN '%s'\n"
+                                                         "  WHEN p.proparallel = 's' THEN '%s'\n"
+                                                         "  WHEN p.proparallel = 'u' THEN '%s'\n"
+                                                         " END as \"%s\"",
+                                                         gettext_noop("restricted"),
+                                                         gettext_noop("safe"),
+                                                         gettext_noop("unsafe"),
+                                                         gettext_noop("Parallel"));
+               appendPQExpBuffer(&buf,
+                                          ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\""
+                                ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"",
                                                  gettext_noop("Owner"),
+                                                 gettext_noop("definer"),
+                                                 gettext_noop("invoker"),
+                                                 gettext_noop("Security"));
+               appendPQExpBufferStr(&buf, ",\n ");
+               printACLColumn(&buf, "p.proacl");
+               appendPQExpBuffer(&buf,
+                                                 ",\n l.lanname as \"%s\""
+                                                 ",\n p.prosrc as \"%s\""
+                               ",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
                                                  gettext_noop("Language"),
                                                  gettext_noop("Source code"),
                                                  gettext_noop("Description"));
+       }
 
        appendPQExpBufferStr(&buf,
                                                 "\nFROM pg_catalog.pg_proc p"
@@ -449,11 +549,11 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
 
        if (!showSystem && !pattern)
                appendPQExpBufferStr(&buf, "      AND n.nspname <> 'pg_catalog'\n"
-                                                 "      AND n.nspname <> 'information_schema'\n");
+                                                        "      AND n.nspname <> 'information_schema'\n");
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -461,10 +561,18 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
        myopt.nullPrint = NULL;
        myopt.title = _("List of functions");
        myopt.translate_header = true;
-       myopt.translate_columns = translate_columns;
-       myopt.n_translate_columns = lengthof(translate_columns);
+       if (pset.sversion >= 90600)
+       {
+               myopt.translate_columns = translate_columns;
+               myopt.n_translate_columns = lengthof(translate_columns);
+       }
+       else
+       {
+               myopt.translate_columns = translate_columns_pre_96;
+               myopt.n_translate_columns = lengthof(translate_columns_pre_96);
+       }
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -506,7 +614,7 @@ describeTypes(const char *pattern, bool verbose, bool showSystem)
                appendPQExpBufferStr(&buf,
                                                         "  pg_catalog.array_to_string(\n"
                                                         "      ARRAY(\n"
-                                                        "                   SELECT e.enumlabel\n"
+                                                        "          SELECT e.enumlabel\n"
                                                         "          FROM pg_catalog.pg_enum e\n"
                                                         "          WHERE e.enumtypid = t.oid\n");
 
@@ -523,6 +631,12 @@ describeTypes(const char *pattern, bool verbose, bool showSystem)
                                                  "  ) AS \"%s\",\n",
                                                  gettext_noop("Elements"));
        }
+       if (verbose)
+       {
+               appendPQExpBuffer(&buf,
+                                        "  pg_catalog.pg_get_userbyid(t.typowner) AS \"%s\",\n",
+                                                 gettext_noop("Owner"));
+       }
        if (verbose && pset.sversion >= 90200)
        {
                printACLColumn(&buf, "t.typacl");
@@ -541,8 +655,9 @@ describeTypes(const char *pattern, bool verbose, bool showSystem)
         * composite types
         */
        appendPQExpBufferStr(&buf, "WHERE (t.typrelid = 0 ");
-       appendPQExpBufferStr(&buf, "OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c "
-                                         "WHERE c.oid = t.typrelid))\n");
+       appendPQExpBufferStr(&buf, "OR (SELECT c.relkind = " CppAsString2(RELKIND_COMPOSITE_TYPE)
+                                                " FROM pg_catalog.pg_class c "
+                                                "WHERE c.oid = t.typrelid))\n");
 
        /*
         * do not include array types (before 8.3 we have to use the assumption
@@ -555,7 +670,7 @@ describeTypes(const char *pattern, bool verbose, bool showSystem)
 
        if (!showSystem && !pattern)
                appendPQExpBufferStr(&buf, "      AND n.nspname <> 'pg_catalog'\n"
-                                                                  "      AND n.nspname <> 'information_schema'\n");
+                                                        "      AND n.nspname <> 'information_schema'\n");
 
        /* Match name pattern against either internal or external name */
        processSQLNamePattern(pset.db, &buf, pattern, true, false,
@@ -565,7 +680,7 @@ describeTypes(const char *pattern, bool verbose, bool showSystem)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -574,7 +689,7 @@ describeTypes(const char *pattern, bool verbose, bool showSystem)
        myopt.title = _("List of data types");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -640,7 +755,7 @@ describeOperators(const char *pattern, bool verbose, bool showSystem)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3, 4;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -649,7 +764,7 @@ describeOperators(const char *pattern, bool verbose, bool showSystem)
        myopt.title = _("List of operators");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -711,7 +826,7 @@ listAllDbs(const char *pattern, bool verbose)
                                                          NULL, "d.datname", NULL, NULL);
 
        appendPQExpBufferStr(&buf, "ORDER BY 1;");
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -720,7 +835,7 @@ listAllDbs(const char *pattern, bool verbose)
        myopt.title = _("List of databases");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -737,7 +852,7 @@ permissionsList(const char *pattern)
        PQExpBufferData buf;
        PGresult   *res;
        printQueryOpt myopt = pset.popt;
-       static const bool translate_columns[] = {false, false, true, false, false};
+       static const bool translate_columns[] = {false, false, true, false, false, false};
 
        initPQExpBuffer(&buf);
 
@@ -748,11 +863,12 @@ permissionsList(const char *pattern)
                                          "SELECT n.nspname as \"%s\",\n"
                                          "  c.relname as \"%s\",\n"
                                          "  CASE c.relkind"
-                                         " WHEN 'r' THEN '%s'"
-                                         " WHEN 'v' THEN '%s'"
-                                         " WHEN 'm' THEN '%s'"
-                                         " WHEN 'S' THEN '%s'"
-                                         " WHEN 'f' THEN '%s'"
+                                         " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
+                                         " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
+                                         " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
+                                         " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
+                                       " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
+                               " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
                                          " END as \"%s\",\n"
                                          "  ",
                                          gettext_noop("Schema"),
@@ -762,6 +878,7 @@ permissionsList(const char *pattern)
                                          gettext_noop("materialized view"),
                                          gettext_noop("sequence"),
                                          gettext_noop("foreign table"),
+                                         gettext_noop("table"),        /* partitioned table */
                                          gettext_noop("Type"));
 
        printACLColumn(&buf, "c.relacl");
@@ -773,11 +890,82 @@ permissionsList(const char *pattern)
                                                  "    FROM pg_catalog.pg_attribute a\n"
                                                  "    WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
                                                  "  ), E'\\n') AS \"%s\"",
-                                                 gettext_noop("Column access privileges"));
+                                                 gettext_noop("Column privileges"));
+
+       if (pset.sversion >= 90500 && pset.sversion < 100000)
+               appendPQExpBuffer(&buf,
+                                                 ",\n  pg_catalog.array_to_string(ARRAY(\n"
+                                                 "    SELECT polname\n"
+                                                 "    || CASE WHEN polcmd != '*' THEN\n"
+                                                 "           E' (' || polcmd || E'):'\n"
+                                                 "       ELSE E':'\n"
+                                                 "       END\n"
+                                                 "    || CASE WHEN polqual IS NOT NULL THEN\n"
+                                                 "           E'\\n  (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
+                                                 "       ELSE E''\n"
+                                                 "       END\n"
+                                                 "    || CASE WHEN polwithcheck IS NOT NULL THEN\n"
+                                                 "           E'\\n  (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
+                                                 "       ELSE E''\n"
+                                                 "       END"
+                                                 "    || CASE WHEN polroles <> '{0}' THEN\n"
+                                  "           E'\\n  to: ' || pg_catalog.array_to_string(\n"
+                                                 "               ARRAY(\n"
+                                                 "                   SELECT rolname\n"
+                                                 "                   FROM pg_catalog.pg_roles\n"
+                                                 "                   WHERE oid = ANY (polroles)\n"
+                                                 "                   ORDER BY 1\n"
+                                                 "               ), E', ')\n"
+                                                 "       ELSE E''\n"
+                                                 "       END\n"
+                                                 "    FROM pg_catalog.pg_policy pol\n"
+                                                 "    WHERE polrelid = c.oid), E'\\n')\n"
+                                                 "    AS \"%s\"",
+                                                 gettext_noop("Policies"));
+
+       if (pset.sversion >= 100000)
+               appendPQExpBuffer(&buf,
+                                                 ",\n  pg_catalog.array_to_string(ARRAY(\n"
+                                                 "    SELECT polname\n"
+                                                 "    || CASE WHEN NOT polpermissive THEN\n"
+                                                 "       E' (RESTRICTIVE)'\n"
+                                                 "       ELSE '' END\n"
+                                                 "    || CASE WHEN polcmd != '*' THEN\n"
+                                                 "           E' (' || polcmd || E'):'\n"
+                                                 "       ELSE E':'\n"
+                                                 "       END\n"
+                                                 "    || CASE WHEN polqual IS NOT NULL THEN\n"
+                                                 "           E'\\n  (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
+                                                 "       ELSE E''\n"
+                                                 "       END\n"
+                                                 "    || CASE WHEN polwithcheck IS NOT NULL THEN\n"
+                                                 "           E'\\n  (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
+                                                 "       ELSE E''\n"
+                                                 "       END"
+                                                 "    || CASE WHEN polroles <> '{0}' THEN\n"
+                                  "           E'\\n  to: ' || pg_catalog.array_to_string(\n"
+                                                 "               ARRAY(\n"
+                                                 "                   SELECT rolname\n"
+                                                 "                   FROM pg_catalog.pg_roles\n"
+                                                 "                   WHERE oid = ANY (polroles)\n"
+                                                 "                   ORDER BY 1\n"
+                                                 "               ), E', ')\n"
+                                                 "       ELSE E''\n"
+                                                 "       END\n"
+                                                 "    FROM pg_catalog.pg_policy pol\n"
+                                                 "    WHERE polrelid = c.oid), E'\\n')\n"
+                                                 "    AS \"%s\"",
+                                                 gettext_noop("Policies"));
 
        appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n"
           "     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
-                                         "WHERE c.relkind IN ('r', 'v', 'm', 'S', 'f')\n");
+                                                "WHERE c.relkind IN ("
+                                                CppAsString2(RELKIND_RELATION) ","
+                                                CppAsString2(RELKIND_VIEW) ","
+                                                CppAsString2(RELKIND_MATVIEW) ","
+                                                CppAsString2(RELKIND_SEQUENCE) ","
+                                                CppAsString2(RELKIND_FOREIGN_TABLE) ","
+                                                CppAsString2(RELKIND_PARTITIONED_TABLE) ")\n");
 
        /*
         * Unless a schema pattern is specified, we suppress system and temp
@@ -791,7 +979,7 @@ permissionsList(const char *pattern)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        if (!res)
        {
                termPQExpBuffer(&buf);
@@ -805,7 +993,7 @@ permissionsList(const char *pattern)
        myopt.translate_columns = translate_columns;
        myopt.n_translate_columns = lengthof(translate_columns);
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        termPQExpBuffer(&buf);
        PQclear(res);
@@ -828,8 +1016,11 @@ listDefaultACLs(const char *pattern)
 
        if (pset.sversion < 90000)
        {
-               psql_error("The server (version %d.%d) does not support altering default privileges.\n",
-                                  pset.sversion / 10000, (pset.sversion / 100) % 100);
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support altering default privileges.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
                return true;
        }
 
@@ -838,7 +1029,7 @@ listDefaultACLs(const char *pattern)
        printfPQExpBuffer(&buf,
                           "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
                                          "  n.nspname AS \"%s\",\n"
-                                         "  CASE d.defaclobjtype WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' END AS \"%s\",\n"
+                                         "  CASE d.defaclobjtype WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' END AS \"%s\",\n"
                                          "  ",
                                          gettext_noop("Owner"),
                                          gettext_noop("Schema"),
@@ -850,6 +1041,8 @@ listDefaultACLs(const char *pattern)
                                          gettext_noop("function"),
                                          DEFACLOBJ_TYPE,
                                          gettext_noop("type"),
+                                         DEFACLOBJ_NAMESPACE,
+                                         gettext_noop("schema"),
                                          gettext_noop("Type"));
 
        printACLColumn(&buf, "d.defaclacl");
@@ -865,7 +1058,7 @@ listDefaultACLs(const char *pattern)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        if (!res)
        {
                termPQExpBuffer(&buf);
@@ -879,7 +1072,7 @@ listDefaultACLs(const char *pattern)
        myopt.translate_columns = translate_columns;
        myopt.n_translate_columns = lengthof(translate_columns);
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        termPQExpBuffer(&buf);
        PQclear(res);
@@ -916,7 +1109,7 @@ objectDescription(const char *pattern, bool showSystem)
                                          gettext_noop("Object"),
                                          gettext_noop("Description"));
 
-       /* Constraint descriptions */
+       /* Table constraint descriptions */
        appendPQExpBuffer(&buf,
                                          "  SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
                                          "  n.nspname as nspname,\n"
@@ -927,7 +1120,7 @@ objectDescription(const char *pattern, bool showSystem)
                                          "ON c.oid = pgc.conrelid\n"
                                          "    LEFT JOIN pg_catalog.pg_namespace n "
                                          "    ON n.oid = c.relnamespace\n",
-                                         gettext_noop("constraint"));
+                                         gettext_noop("table constraint"));
 
        if (!showSystem && !pattern)
                appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
@@ -937,6 +1130,29 @@ objectDescription(const char *pattern, bool showSystem)
                                                  false, "n.nspname", "pgc.conname", NULL,
                                                  "pg_catalog.pg_table_is_visible(c.oid)");
 
+       /* Domain constraint descriptions */
+       appendPQExpBuffer(&buf,
+                                         "UNION ALL\n"
+                                         "  SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
+                                         "  n.nspname as nspname,\n"
+                                         "  CAST(pgc.conname AS pg_catalog.text) as name,"
+                                         "  CAST('%s' AS pg_catalog.text) as object\n"
+                                         "  FROM pg_catalog.pg_constraint pgc\n"
+                                         "    JOIN pg_catalog.pg_type t "
+                                         "ON t.oid = pgc.contypid\n"
+                                         "    LEFT JOIN pg_catalog.pg_namespace n "
+                                         "    ON n.oid = t.typnamespace\n",
+                                         gettext_noop("domain constraint"));
+
+       if (!showSystem && !pattern)
+               appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
+                                                        "      AND n.nspname <> 'information_schema'\n");
+
+       processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern,
+                                                 false, "n.nspname", "pgc.conname", NULL,
+                                                 "pg_catalog.pg_type_is_visible(t.oid)");
+
+
        /*
         * pg_opclass.opcmethod only available in 8.3+
         */
@@ -958,7 +1174,7 @@ objectDescription(const char *pattern, bool showSystem)
 
                if (!showSystem && !pattern)
                        appendPQExpBufferStr(&buf, "      AND n.nspname <> 'pg_catalog'\n"
-                                                                "      AND n.nspname <> 'information_schema'\n");
+                                                       "      AND n.nspname <> 'information_schema'\n");
 
                processSQLNamePattern(pset.db, &buf, pattern, true, false,
                                                          "n.nspname", "o.opcname", NULL,
@@ -987,7 +1203,7 @@ objectDescription(const char *pattern, bool showSystem)
 
                if (!showSystem && !pattern)
                        appendPQExpBufferStr(&buf, "      AND n.nspname <> 'pg_catalog'\n"
-                                                                "      AND n.nspname <> 'information_schema'\n");
+                                                       "      AND n.nspname <> 'information_schema'\n");
 
                processSQLNamePattern(pset.db, &buf, pattern, true, false,
                                                          "n.nspname", "opf.opfname", NULL,
@@ -1041,7 +1257,7 @@ objectDescription(const char *pattern, bool showSystem)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -1052,7 +1268,7 @@ objectDescription(const char *pattern, bool showSystem)
        myopt.translate_columns = translate_columns;
        myopt.n_translate_columns = lengthof(translate_columns);
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -1093,7 +1309,7 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem)
 
        appendPQExpBufferStr(&buf, "ORDER BY 2, 3;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -1153,9 +1369,8 @@ describeOneTableDetails(const char *schemaname,
        bool            printTableInitialized = false;
        int                     i;
        char       *view_def = NULL;
-       char       *headers[9];
+       char       *headers[11];
        char      **seq_values = NULL;
-       char      **modifiers = NULL;
        char      **ptr;
        PQExpBufferData title;
        PQExpBufferData tmpbuf;
@@ -1168,6 +1383,8 @@ describeOneTableDetails(const char *schemaname,
                bool            hasindex;
                bool            hasrules;
                bool            hastriggers;
+               bool            rowsecurity;
+               bool            forcerowsecurity;
                bool            hasoids;
                Oid                     tablespace;
                char       *reloptions;
@@ -1175,7 +1392,7 @@ describeOneTableDetails(const char *schemaname,
                char            relpersistence;
                char            relreplident;
        }                       tableinfo;
-       bool            show_modifiers = false;
+       bool            show_column_details = false;
        bool            retval;
 
        retval = false;
@@ -1189,11 +1406,28 @@ describeOneTableDetails(const char *schemaname,
        initPQExpBuffer(&tmpbuf);
 
        /* Get general table info */
-       if (pset.sversion >= 90400)
+       if (pset.sversion >= 90500)
+       {
+               printfPQExpBuffer(&buf,
+                         "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
+                               "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
+                                                 "c.relhasoids, %s, c.reltablespace, "
+                                                 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
+                                                 "c.relpersistence, c.relreplident\n"
+                                                 "FROM pg_catalog.pg_class c\n "
+                  "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
+                                                 "WHERE c.oid = '%s';",
+                                                 (verbose ?
+                                                  "pg_catalog.array_to_string(c.reloptions || "
+                                                  "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
+                                                  : "''"),
+                                                 oid);
+       }
+       else if (pset.sversion >= 90400)
        {
                printfPQExpBuffer(&buf,
                          "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
-                                                 "c.relhastriggers, c.relhasoids, "
+                                                 "c.relhastriggers, false, false, c.relhasoids, "
                                                  "%s, c.reltablespace, "
                                                  "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
                                                  "c.relpersistence, c.relreplident\n"
@@ -1210,7 +1444,7 @@ describeOneTableDetails(const char *schemaname,
        {
                printfPQExpBuffer(&buf,
                          "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
-                                                 "c.relhastriggers, c.relhasoids, "
+                                                 "c.relhastriggers, false, false, c.relhasoids, "
                                                  "%s, c.reltablespace, "
                                                  "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
                                                  "c.relpersistence\n"
@@ -1227,7 +1461,7 @@ describeOneTableDetails(const char *schemaname,
        {
                printfPQExpBuffer(&buf,
                          "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
-                                                 "c.relhastriggers, c.relhasoids, "
+                                                 "c.relhastriggers, false, false, c.relhasoids, "
                                                  "%s, c.reltablespace, "
                                                  "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END\n"
                                                  "FROM pg_catalog.pg_class c\n "
@@ -1243,7 +1477,7 @@ describeOneTableDetails(const char *schemaname,
        {
                printfPQExpBuffer(&buf,
                          "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
-                                                 "c.relhastriggers, c.relhasoids, "
+                                                 "c.relhastriggers, false, false, c.relhasoids, "
                                                  "%s, c.reltablespace\n"
                                                  "FROM pg_catalog.pg_class c\n "
                   "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
@@ -1258,7 +1492,7 @@ describeOneTableDetails(const char *schemaname,
        {
                printfPQExpBuffer(&buf,
                                          "SELECT relchecks, relkind, relhasindex, relhasrules, "
-                                                 "reltriggers <> 0, relhasoids, "
+                                                 "reltriggers <> 0, false, false, relhasoids, "
                                                  "%s, reltablespace\n"
                                                  "FROM pg_catalog.pg_class WHERE oid = '%s';",
                                                  (verbose ?
@@ -1269,7 +1503,7 @@ describeOneTableDetails(const char *schemaname,
        {
                printfPQExpBuffer(&buf,
                                          "SELECT relchecks, relkind, relhasindex, relhasrules, "
-                                                 "reltriggers <> 0, relhasoids, "
+                                                 "reltriggers <> 0, false, false, relhasoids, "
                                                  "'', reltablespace\n"
                                                  "FROM pg_catalog.pg_class WHERE oid = '%s';",
                                                  oid);
@@ -1278,13 +1512,13 @@ describeOneTableDetails(const char *schemaname,
        {
                printfPQExpBuffer(&buf,
                                          "SELECT relchecks, relkind, relhasindex, relhasrules, "
-                                                 "reltriggers <> 0, relhasoids, "
+                                                 "reltriggers <> 0, false, false, relhasoids, "
                                                  "'', ''\n"
                                                  "FROM pg_catalog.pg_class WHERE oid = '%s';",
                                                  oid);
        }
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        if (!res)
                goto error_return;
 
@@ -1301,18 +1535,20 @@ describeOneTableDetails(const char *schemaname,
        tableinfo.hasindex = strcmp(PQgetvalue(res, 0, 2), "t") == 0;
        tableinfo.hasrules = strcmp(PQgetvalue(res, 0, 3), "t") == 0;
        tableinfo.hastriggers = strcmp(PQgetvalue(res, 0, 4), "t") == 0;
-       tableinfo.hasoids = strcmp(PQgetvalue(res, 0, 5), "t") == 0;
+       tableinfo.rowsecurity = strcmp(PQgetvalue(res, 0, 5), "t") == 0;
+       tableinfo.forcerowsecurity = strcmp(PQgetvalue(res, 0, 6), "t") == 0;
+       tableinfo.hasoids = strcmp(PQgetvalue(res, 0, 7), "t") == 0;
        tableinfo.reloptions = (pset.sversion >= 80200) ?
-               pg_strdup(PQgetvalue(res, 0, 6)) : NULL;
+               pg_strdup(PQgetvalue(res, 0, 8)) : NULL;
        tableinfo.tablespace = (pset.sversion >= 80000) ?
-               atooid(PQgetvalue(res, 0, 7)) : 0;
+               atooid(PQgetvalue(res, 0, 9)) : 0;
        tableinfo.reloftype = (pset.sversion >= 90000 &&
-                                                  strcmp(PQgetvalue(res, 0, 8), "") != 0) ?
-               pg_strdup(PQgetvalue(res, 0, 8)) : NULL;
+                                                  strcmp(PQgetvalue(res, 0, 10), "") != 0) ?
+               pg_strdup(PQgetvalue(res, 0, 10)) : NULL;
        tableinfo.relpersistence = (pset.sversion >= 90100) ?
-               *(PQgetvalue(res, 0, 9)) : 0;
+               *(PQgetvalue(res, 0, 11)) : 0;
        tableinfo.relreplident = (pset.sversion >= 90400) ?
-               *(PQgetvalue(res, 0, 10)) : 'd';
+               *(PQgetvalue(res, 0, 12)) : 'd';
        PQclear(res);
        res = NULL;
 
@@ -1320,13 +1556,13 @@ describeOneTableDetails(const char *schemaname,
         * If it's a sequence, fetch its values and store into an array that will
         * be used later.
         */
-       if (tableinfo.relkind == 'S')
+       if (tableinfo.relkind == RELKIND_SEQUENCE)
        {
                printfPQExpBuffer(&buf, "SELECT * FROM %s", fmtId(schemaname));
                /* must be separate because fmtId isn't reentrant */
                appendPQExpBuffer(&buf, ".%s;", fmtId(relationname));
 
-               res = PSQLexec(buf.data, false);
+               res = PSQLexec(buf.data);
                if (!res)
                        goto error_return;
 
@@ -1357,14 +1593,18 @@ describeOneTableDetails(const char *schemaname,
                                                         "   WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation");
        else
                appendPQExpBufferStr(&buf, "\n  NULL AS attcollation");
-       if (tableinfo.relkind == 'i')
+       if (pset.sversion >= 100000)
+               appendPQExpBufferStr(&buf, ", a.attidentity");
+       else
+               appendPQExpBufferStr(&buf, ", ''::\"char\" AS attidentity");
+       if (tableinfo.relkind == RELKIND_INDEX)
                appendPQExpBufferStr(&buf, ",\n  pg_catalog.pg_get_indexdef(a.attrelid, a.attnum, TRUE) AS indexdef");
        else
                appendPQExpBufferStr(&buf, ",\n  NULL AS indexdef");
-       if (tableinfo.relkind == 'f' && pset.sversion >= 90200)
+       if (tableinfo.relkind == RELKIND_FOREIGN_TABLE && pset.sversion >= 90200)
                appendPQExpBufferStr(&buf, ",\n  CASE WHEN attfdwoptions IS NULL THEN '' ELSE "
-                                                 "  '(' || array_to_string(ARRAY(SELECT quote_ident(option_name) ||  ' ' || quote_literal(option_value)  FROM "
-                                                 "  pg_options_to_table(attfdwoptions)), ', ') || ')' END AS attfdwoptions");
+                                                        "  '(' || array_to_string(ARRAY(SELECT quote_ident(option_name) ||  ' ' || quote_literal(option_value)  FROM "
+                                                        "  pg_options_to_table(attfdwoptions)), ', ') || ')' END AS attfdwoptions");
        else
                appendPQExpBufferStr(&buf, ",\n  NULL AS attfdwoptions");
        if (verbose)
@@ -1376,9 +1616,12 @@ describeOneTableDetails(const char *schemaname,
                 * In 9.0+, we have column comments for: relations, views, composite
                 * types, and foreign tables (c.f. CommentObject() in comment.c).
                 */
-               if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
-                       tableinfo.relkind == 'm' ||
-                       tableinfo.relkind == 'f' || tableinfo.relkind == 'c')
+               if (tableinfo.relkind == RELKIND_RELATION ||
+                       tableinfo.relkind == RELKIND_VIEW ||
+                       tableinfo.relkind == RELKIND_MATVIEW ||
+                       tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
+                       tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
+                       tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
                        appendPQExpBufferStr(&buf, ", pg_catalog.col_description(a.attrelid, a.attnum)");
        }
 
@@ -1386,7 +1629,7 @@ describeOneTableDetails(const char *schemaname,
        appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
        appendPQExpBufferStr(&buf, "\nORDER BY a.attnum;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        if (!res)
                goto error_return;
        numrows = PQntuples(res);
@@ -1394,7 +1637,7 @@ describeOneTableDetails(const char *schemaname,
        /* Make title */
        switch (tableinfo.relkind)
        {
-               case 'r':
+               case RELKIND_RELATION:
                        if (tableinfo.relpersistence == 'u')
                                printfPQExpBuffer(&title, _("Unlogged table \"%s.%s\""),
                                                                  schemaname, relationname);
@@ -1402,11 +1645,11 @@ describeOneTableDetails(const char *schemaname,
                                printfPQExpBuffer(&title, _("Table \"%s.%s\""),
                                                                  schemaname, relationname);
                        break;
-               case 'v':
+               case RELKIND_VIEW:
                        printfPQExpBuffer(&title, _("View \"%s.%s\""),
                                                          schemaname, relationname);
                        break;
-               case 'm':
+               case RELKIND_MATVIEW:
                        if (tableinfo.relpersistence == 'u')
                                printfPQExpBuffer(&title, _("Unlogged materialized view \"%s.%s\""),
                                                                  schemaname, relationname);
@@ -1414,11 +1657,11 @@ describeOneTableDetails(const char *schemaname,
                                printfPQExpBuffer(&title, _("Materialized view \"%s.%s\""),
                                                                  schemaname, relationname);
                        break;
-               case 'S':
+               case RELKIND_SEQUENCE:
                        printfPQExpBuffer(&title, _("Sequence \"%s.%s\""),
                                                          schemaname, relationname);
                        break;
-               case 'i':
+               case RELKIND_INDEX:
                        if (tableinfo.relpersistence == 'u')
                                printfPQExpBuffer(&title, _("Unlogged index \"%s.%s\""),
                                                                  schemaname, relationname);
@@ -1431,18 +1674,26 @@ describeOneTableDetails(const char *schemaname,
                        printfPQExpBuffer(&title, _("Special relation \"%s.%s\""),
                                                          schemaname, relationname);
                        break;
-               case 't':
+               case RELKIND_TOASTVALUE:
                        printfPQExpBuffer(&title, _("TOAST table \"%s.%s\""),
                                                          schemaname, relationname);
                        break;
-               case 'c':
+               case RELKIND_COMPOSITE_TYPE:
                        printfPQExpBuffer(&title, _("Composite type \"%s.%s\""),
                                                          schemaname, relationname);
                        break;
-               case 'f':
+               case RELKIND_FOREIGN_TABLE:
                        printfPQExpBuffer(&title, _("Foreign table \"%s.%s\""),
                                                          schemaname, relationname);
                        break;
+               case RELKIND_PARTITIONED_TABLE:
+                       if (tableinfo.relpersistence == 'u')
+                               printfPQExpBuffer(&title, _("Unlogged table \"%s.%s\""),
+                                                                 schemaname, relationname);
+                       else
+                               printfPQExpBuffer(&title, _("Table \"%s.%s\""),
+                                                                 schemaname, relationname);
+                       break;
                default:
                        /* untranslated unknown relkind */
                        printfPQExpBuffer(&title, "?%c? \"%s.%s\"",
@@ -1455,34 +1706,43 @@ describeOneTableDetails(const char *schemaname,
        headers[1] = gettext_noop("Type");
        cols = 2;
 
-       if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
-               tableinfo.relkind == 'm' ||
-               tableinfo.relkind == 'f' || tableinfo.relkind == 'c')
+       if (tableinfo.relkind == RELKIND_RELATION ||
+               tableinfo.relkind == RELKIND_VIEW ||
+               tableinfo.relkind == RELKIND_MATVIEW ||
+               tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
+               tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
+               tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
        {
-               show_modifiers = true;
-               headers[cols++] = gettext_noop("Modifiers");
-               modifiers = pg_malloc0((numrows + 1) * sizeof(*modifiers));
+               headers[cols++] = gettext_noop("Collation");
+               headers[cols++] = gettext_noop("Nullable");
+               headers[cols++] = gettext_noop("Default");
+               show_column_details = true;
        }
 
-       if (tableinfo.relkind == 'S')
+       if (tableinfo.relkind == RELKIND_SEQUENCE)
                headers[cols++] = gettext_noop("Value");
 
-       if (tableinfo.relkind == 'i')
+       if (tableinfo.relkind == RELKIND_INDEX)
                headers[cols++] = gettext_noop("Definition");
 
-       if (tableinfo.relkind == 'f' && pset.sversion >= 90200)
-               headers[cols++] = gettext_noop("FDW Options");
+       if (tableinfo.relkind == RELKIND_FOREIGN_TABLE && pset.sversion >= 90200)
+               headers[cols++] = gettext_noop("FDW options");
 
        if (verbose)
        {
                headers[cols++] = gettext_noop("Storage");
-               if (tableinfo.relkind == 'r' || tableinfo.relkind == 'm' ||
-                       tableinfo.relkind == 'f')
+               if (tableinfo.relkind == RELKIND_RELATION ||
+                       tableinfo.relkind == RELKIND_MATVIEW ||
+                       tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
+                       tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
                        headers[cols++] = gettext_noop("Stats target");
                /* Column comments, if the relkind supports this feature. */
-               if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
-                       tableinfo.relkind == 'm' ||
-                       tableinfo.relkind == 'c' || tableinfo.relkind == 'f')
+               if (tableinfo.relkind == RELKIND_RELATION ||
+                       tableinfo.relkind == RELKIND_VIEW ||
+                       tableinfo.relkind == RELKIND_MATVIEW ||
+                       tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
+                       tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
+                       tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
                        headers[cols++] = gettext_noop("Description");
        }
 
@@ -1492,15 +1752,16 @@ describeOneTableDetails(const char *schemaname,
        for (i = 0; i < cols; i++)
                printTableAddHeader(&cont, headers[i], true, 'l');
 
-       /* Check if table is a view or materialized view */
-       if ((tableinfo.relkind == 'v' || tableinfo.relkind == 'm') && verbose)
+       /* Get view_def if table is a view or materialized view */
+       if ((tableinfo.relkind == RELKIND_VIEW ||
+                tableinfo.relkind == RELKIND_MATVIEW) && verbose)
        {
                PGresult   *result;
 
                printfPQExpBuffer(&buf,
                         "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);",
                                                  oid);
-               result = PSQLexec(buf.data, false);
+               result = PSQLexec(buf.data);
                if (!result)
                        goto error_return;
 
@@ -1519,57 +1780,45 @@ describeOneTableDetails(const char *schemaname,
                /* Type */
                printTableAddCell(&cont, PQgetvalue(res, i, 1), false, false);
 
-               /* Modifiers: collate, not null, default */
-               if (show_modifiers)
+               /* Collation, Nullable, Default */
+               if (show_column_details)
                {
-                       resetPQExpBuffer(&tmpbuf);
+                       char       *identity;
+                       char       *default_str = "";
 
-                       if (!PQgetisnull(res, i, 5))
-                       {
-                               if (tmpbuf.len > 0)
-                                       appendPQExpBufferStr(&tmpbuf, " ");
-                               appendPQExpBuffer(&tmpbuf, _("collate %s"),
-                                                                 PQgetvalue(res, i, 5));
-                       }
+                       printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
 
-                       if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
-                       {
-                               if (tmpbuf.len > 0)
-                                       appendPQExpBufferStr(&tmpbuf, " ");
-                               appendPQExpBufferStr(&tmpbuf, _("not null"));
-                       }
+                       printTableAddCell(&cont, strcmp(PQgetvalue(res, i, 3), "t") == 0 ? "not null" : "", false, false);
 
-                       /* handle "default" here */
-                       /* (note: above we cut off the 'default' string at 128) */
-                       if (strlen(PQgetvalue(res, i, 2)) != 0)
-                       {
-                               if (tmpbuf.len > 0)
-                                       appendPQExpBufferStr(&tmpbuf, " ");
-                               /* translator: default values of column definitions */
-                               appendPQExpBuffer(&tmpbuf, _("default %s"),
-                                                                 PQgetvalue(res, i, 2));
-                       }
+                       identity = PQgetvalue(res, i, 6);
 
-                       modifiers[i] = pg_strdup(tmpbuf.data);
-                       printTableAddCell(&cont, modifiers[i], false, false);
+                       if (!identity[0])
+                               /* (note: above we cut off the 'default' string at 128) */
+                               default_str = PQgetvalue(res, i, 2);
+                       else if (identity[0] == ATTRIBUTE_IDENTITY_ALWAYS)
+                               default_str = "generated always as identity";
+                       else if (identity[0] == ATTRIBUTE_IDENTITY_BY_DEFAULT)
+                               default_str = "generated by default as identity";
+
+                       printTableAddCell(&cont, default_str, false, false);
                }
 
                /* Value: for sequences only */
-               if (tableinfo.relkind == 'S')
+               if (tableinfo.relkind == RELKIND_SEQUENCE)
                        printTableAddCell(&cont, seq_values[i], false, false);
 
                /* Expression for index column */
-               if (tableinfo.relkind == 'i')
-                       printTableAddCell(&cont, PQgetvalue(res, i, 6), false, false);
+               if (tableinfo.relkind == RELKIND_INDEX)
+                       printTableAddCell(&cont, PQgetvalue(res, i, 7), false, false);
 
                /* FDW options for foreign table column, only for 9.2 or later */
-               if (tableinfo.relkind == 'f' && pset.sversion >= 90200)
-                       printTableAddCell(&cont, PQgetvalue(res, i, 7), false, false);
+               if (tableinfo.relkind == RELKIND_FOREIGN_TABLE && pset.sversion >= 90200)
+                       printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
 
                /* Storage and Description */
                if (verbose)
                {
-                       int                     firstvcol = 8;
+                       int                     firstvcol = 9;
                        char       *storage = PQgetvalue(res, i, firstvcol);
 
                        /* these strings are literal in our syntax, so not translated. */
@@ -1581,24 +1830,101 @@ describeOneTableDetails(const char *schemaname,
                                                          false, false);
 
                        /* Statistics target, if the relkind supports this feature */
-                       if (tableinfo.relkind == 'r' || tableinfo.relkind == 'm' ||
-                               tableinfo.relkind == 'f')
+                       if (tableinfo.relkind == RELKIND_RELATION ||
+                               tableinfo.relkind == RELKIND_MATVIEW ||
+                               tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
+                               tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
                        {
                                printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 1),
                                                                  false, false);
                        }
 
                        /* Column comments, if the relkind supports this feature. */
-                       if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
-                               tableinfo.relkind == 'm' ||
-                               tableinfo.relkind == 'c' || tableinfo.relkind == 'f')
+                       if (tableinfo.relkind == RELKIND_RELATION ||
+                               tableinfo.relkind == RELKIND_VIEW ||
+                               tableinfo.relkind == RELKIND_MATVIEW ||
+                               tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
+                               tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
+                               tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
                                printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 2),
                                                                  false, false);
                }
        }
 
        /* Make footers */
-       if (tableinfo.relkind == 'i')
+       if (pset.sversion >= 100000)
+       {
+               /* Get the partition information  */
+               PGresult   *result;
+               char       *parent_name;
+               char       *partdef;
+               char       *partconstraintdef = NULL;
+
+               /* If verbose, also request the partition constraint definition */
+               if (verbose)
+                       printfPQExpBuffer(&buf,
+                                                         "SELECT inhparent::pg_catalog.regclass,"
+                                                       "               pg_get_expr(c.relpartbound, inhrelid),"
+                                                 "             pg_get_partition_constraintdef(inhrelid)"
+                                                         " FROM pg_catalog.pg_class c"
+                                                         " JOIN pg_catalog.pg_inherits"
+                                                         " ON c.oid = inhrelid"
+                                                  " WHERE c.oid = '%s' AND c.relispartition;", oid);
+               else
+                       printfPQExpBuffer(&buf,
+                                                         "SELECT inhparent::pg_catalog.regclass,"
+                                                         "             pg_get_expr(c.relpartbound, inhrelid)"
+                                                         " FROM pg_catalog.pg_class c"
+                                                         " JOIN pg_catalog.pg_inherits"
+                                                         " ON c.oid = inhrelid"
+                                                  " WHERE c.oid = '%s' AND c.relispartition;", oid);
+               result = PSQLexec(buf.data);
+               if (!result)
+                       goto error_return;
+
+               if (PQntuples(result) > 0)
+               {
+                       parent_name = PQgetvalue(result, 0, 0);
+                       partdef = PQgetvalue(result, 0, 1);
+
+                       if (PQnfields(result) == 3)
+                               partconstraintdef = PQgetvalue(result, 0, 2);
+
+                       printfPQExpBuffer(&tmpbuf, _("Partition of: %s %s"), parent_name,
+                                                         partdef);
+                       printTableAddFooter(&cont, tmpbuf.data);
+
+                       if (partconstraintdef)
+                       {
+                               printfPQExpBuffer(&tmpbuf, _("Partition constraint: %s"),
+                                                                 partconstraintdef);
+                               printTableAddFooter(&cont, tmpbuf.data);
+                       }
+
+                       PQclear(result);
+               }
+       }
+
+       if (tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
+       {
+               /* Get the partition key information  */
+               PGresult   *result;
+               char       *partkeydef;
+
+               printfPQExpBuffer(&buf,
+                               "SELECT pg_catalog.pg_get_partkeydef('%s'::pg_catalog.oid);",
+                                                 oid);
+               result = PSQLexec(buf.data);
+               if (!result || PQntuples(result) != 1)
+                       goto error_return;
+
+               partkeydef = PQgetvalue(result, 0, 0);
+               printfPQExpBuffer(&tmpbuf, _("Partition key: %s"), partkeydef);
+               printTableAddFooter(&cont, tmpbuf.data);
+               PQclear(result);
+       }
+
+       if (tableinfo.relkind == RELKIND_INDEX)
        {
                /* Footer information about an index */
                PGresult   *result;
@@ -1612,13 +1938,13 @@ describeOneTableDetails(const char *schemaname,
                if (pset.sversion >= 90000)
                        appendPQExpBufferStr(&buf,
                                                                 "  (NOT i.indimmediate) AND "
-                                                               "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
+                                                       "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
                                                                 "WHERE conrelid = i.indrelid AND "
                                                                 "conindid = i.indexrelid AND "
                                                                 "contype IN ('p','u','x') AND "
                                                                 "condeferrable) AS condeferrable,\n"
                                                                 "  (NOT i.indimmediate) AND "
-                                                               "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
+                                                       "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
                                                                 "WHERE conrelid = i.indrelid AND "
                                                                 "conindid = i.indexrelid AND "
                                                                 "contype IN ('p','u','x') AND "
@@ -1639,7 +1965,7 @@ describeOneTableDetails(const char *schemaname,
                                                  "AND i.indrelid = c2.oid;",
                                                  oid);
 
-               result = PSQLexec(buf.data, false);
+               result = PSQLexec(buf.data);
                if (!result)
                        goto error_return;
                else if (PQntuples(result) != 1)
@@ -1697,7 +2023,7 @@ describeOneTableDetails(const char *schemaname,
 
                PQclear(result);
        }
-       else if (tableinfo.relkind == 'S')
+       else if (tableinfo.relkind == RELKIND_SEQUENCE)
        {
                /* Footer information about a sequence */
                PGresult   *result = NULL;
@@ -1705,7 +2031,8 @@ describeOneTableDetails(const char *schemaname,
                /* Get the column that owns this sequence */
                printfPQExpBuffer(&buf, "SELECT pg_catalog.quote_ident(nspname) || '.' ||"
                                                  "\n   pg_catalog.quote_ident(relname) || '.' ||"
-                                                 "\n   pg_catalog.quote_ident(attname)"
+                                                 "\n   pg_catalog.quote_ident(attname),"
+                                                 "\n   d.deptype"
                                                  "\nFROM pg_catalog.pg_class c"
                                        "\nINNER JOIN pg_catalog.pg_depend d ON c.oid=d.refobjid"
                         "\nINNER JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace"
@@ -1715,17 +2042,27 @@ describeOneTableDetails(const char *schemaname,
                           "\nWHERE d.classid='pg_catalog.pg_class'::pg_catalog.regclass"
                         "\n AND d.refclassid='pg_catalog.pg_class'::pg_catalog.regclass"
                                                  "\n AND d.objid=%s"
-                                                 "\n AND d.deptype='a'",
+                                                 "\n AND d.deptype IN ('a', 'i')",
                                                  oid);
 
-               result = PSQLexec(buf.data, false);
+               result = PSQLexec(buf.data);
                if (!result)
                        goto error_return;
                else if (PQntuples(result) == 1)
                {
-                       printfPQExpBuffer(&buf, _("Owned by: %s"),
-                                                         PQgetvalue(result, 0, 0));
-                       printTableAddFooter(&cont, buf.data);
+                       switch (PQgetvalue(result, 0, 1)[0])
+                       {
+                               case 'a':
+                                       printfPQExpBuffer(&buf, _("Owned by: %s"),
+                                                                         PQgetvalue(result, 0, 0));
+                                       printTableAddFooter(&cont, buf.data);
+                                       break;
+                               case 'i':
+                                       printfPQExpBuffer(&buf, _("Sequence for identity column: %s"),
+                                                                         PQgetvalue(result, 0, 0));
+                                       printTableAddFooter(&cont, buf.data);
+                                       break;
+                       }
                }
 
                /*
@@ -1735,8 +2072,10 @@ describeOneTableDetails(const char *schemaname,
                 */
                PQclear(result);
        }
-       else if (tableinfo.relkind == 'r' || tableinfo.relkind == 'm' ||
-                        tableinfo.relkind == 'f')
+       else if (tableinfo.relkind == RELKIND_RELATION ||
+                        tableinfo.relkind == RELKIND_MATVIEW ||
+                        tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
+                        tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
        {
                /* Footer information about a table */
                PGresult   *result = NULL;
@@ -1755,11 +2094,11 @@ describeOneTableDetails(const char *schemaname,
                        if (pset.sversion >= 90000)
                                appendPQExpBufferStr(&buf,
                                                   "pg_catalog.pg_get_constraintdef(con.oid, true), "
-                                                                 "contype, condeferrable, condeferred");
+                                                                        "contype, condeferrable, condeferred");
                        else
                                appendPQExpBufferStr(&buf,
-                                                                        "null AS constraintdef, null AS contype, "
-                                                                        "false AS condeferrable, false AS condeferred");
+                                                                  "null AS constraintdef, null AS contype, "
+                                                        "false AS condeferrable, false AS condeferred");
                        if (pset.sversion >= 90400)
                                appendPQExpBufferStr(&buf, ", i.indisreplident");
                        else
@@ -1775,7 +2114,7 @@ describeOneTableDetails(const char *schemaname,
                                                          "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
                         "ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname;",
                                                          oid);
-                       result = PSQLexec(buf.data, false);
+                       result = PSQLexec(buf.data);
                        if (!result)
                                goto error_return;
                        else
@@ -1841,7 +2180,7 @@ describeOneTableDetails(const char *schemaname,
 
                                        /* Print tablespace of the index on the same line */
                                        if (pset.sversion >= 80000)
-                                               add_tablespace_footer(&cont, 'i',
+                                               add_tablespace_footer(&cont, RELKIND_INDEX,
                                                                                   atooid(PQgetvalue(result, i, 11)),
                                                                                          false);
                                }
@@ -1859,7 +2198,7 @@ describeOneTableDetails(const char *schemaname,
                                                          "WHERE r.conrelid = '%s' AND r.contype = 'c'\n"
                                                          "ORDER BY 1;",
                                                          oid);
-                       result = PSQLexec(buf.data, false);
+                       result = PSQLexec(buf.data);
                        if (!result)
                                goto error_return;
                        else
@@ -1870,7 +2209,7 @@ describeOneTableDetails(const char *schemaname,
                                printTableAddFooter(&cont, _("Check constraints:"));
                                for (i = 0; i < tuples; i++)
                                {
-                                       /* untranslated contraint name and def */
+                                       /* untranslated constraint name and def */
                                        printfPQExpBuffer(&buf, "    \"%s\" %s",
                                                                          PQgetvalue(result, i, 0),
                                                                          PQgetvalue(result, i, 1));
@@ -1890,7 +2229,7 @@ describeOneTableDetails(const char *schemaname,
                                                          "FROM pg_catalog.pg_constraint r\n"
                                   "WHERE r.conrelid = '%s' AND r.contype = 'f' ORDER BY 1;",
                                                          oid);
-                       result = PSQLexec(buf.data, false);
+                       result = PSQLexec(buf.data);
                        if (!result)
                                goto error_return;
                        else
@@ -1921,7 +2260,7 @@ describeOneTableDetails(const char *schemaname,
                                                          "FROM pg_catalog.pg_constraint c\n"
                                  "WHERE c.confrelid = '%s' AND c.contype = 'f' ORDER BY 1;",
                                                          oid);
-                       result = PSQLexec(buf.data, false);
+                       result = PSQLexec(buf.data);
                        if (!result)
                                goto error_return;
                        else
@@ -1943,8 +2282,163 @@ describeOneTableDetails(const char *schemaname,
                        PQclear(result);
                }
 
+               /* print any row-level policies */
+               if (pset.sversion >= 90500)
+               {
+                       if (pset.sversion >= 100000)
+                               printfPQExpBuffer(&buf,
+                                                                 "SELECT pol.polname, pol.polpermissive,\n"
+                                                                 "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE array_to_string(array(select rolname from pg_roles where oid = any (pol.polroles) order by 1),',') END,\n"
+                                          "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n"
+                                 "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n"
+                                                                 "CASE pol.polcmd\n"
+                                                                 "WHEN 'r' THEN 'SELECT'\n"
+                                                                 "WHEN 'a' THEN 'INSERT'\n"
+                                                                 "WHEN 'w' THEN 'UPDATE'\n"
+                                                                 "WHEN 'd' THEN 'DELETE'\n"
+                                                                 "END AS cmd\n"
+                                                                 "FROM pg_catalog.pg_policy pol\n"
+                                                                 "WHERE pol.polrelid = '%s' ORDER BY 1;",
+                                                                 oid);
+                       else
+                               printfPQExpBuffer(&buf,
+                                                               "SELECT pol.polname, 't' as polpermissive,\n"
+                                                                 "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE array_to_string(array(select rolname from pg_roles where oid = any (pol.polroles) order by 1),',') END,\n"
+                                          "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n"
+                                 "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n"
+                                                                 "CASE pol.polcmd\n"
+                                                                 "WHEN 'r' THEN 'SELECT'\n"
+                                                                 "WHEN 'a' THEN 'INSERT'\n"
+                                                                 "WHEN 'w' THEN 'UPDATE'\n"
+                                                                 "WHEN 'd' THEN 'DELETE'\n"
+                                                                 "END AS cmd\n"
+                                                                 "FROM pg_catalog.pg_policy pol\n"
+                                                                 "WHERE pol.polrelid = '%s' ORDER BY 1;",
+                                                                 oid);
+
+                       result = PSQLexec(buf.data);
+                       if (!result)
+                               goto error_return;
+                       else
+                               tuples = PQntuples(result);
+
+                       /*
+                        * Handle cases where RLS is enabled and there are policies, or
+                        * there aren't policies, or RLS isn't enabled but there are
+                        * policies
+                        */
+                       if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0)
+                               printTableAddFooter(&cont, _("Policies:"));
+
+                       if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0)
+                               printTableAddFooter(&cont, _("Policies (forced row security enabled):"));
+
+                       if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0)
+                               printTableAddFooter(&cont, _("Policies (row security enabled): (none)"));
+
+                       if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0)
+                               printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)"));
+
+                       if (!tableinfo.rowsecurity && tuples > 0)
+                               printTableAddFooter(&cont, _("Policies (row security disabled):"));
+
+                       /* Might be an empty set - that's ok */
+                       for (i = 0; i < tuples; i++)
+                       {
+                               printfPQExpBuffer(&buf, "    POLICY \"%s\"",
+                                                                 PQgetvalue(result, i, 0));
+
+                               if (*(PQgetvalue(result, i, 1)) == 'f')
+                                       appendPQExpBuffer(&buf, " AS RESTRICTIVE");
+
+                               if (!PQgetisnull(result, i, 5))
+                                       appendPQExpBuffer(&buf, " FOR %s",
+                                                                         PQgetvalue(result, i, 5));
+
+                               if (!PQgetisnull(result, i, 2))
+                               {
+                                       appendPQExpBuffer(&buf, "\n      TO %s",
+                                                                         PQgetvalue(result, i, 2));
+                               }
+
+                               if (!PQgetisnull(result, i, 3))
+                                       appendPQExpBuffer(&buf, "\n      USING (%s)",
+                                                                         PQgetvalue(result, i, 3));
+
+                               if (!PQgetisnull(result, i, 4))
+                                       appendPQExpBuffer(&buf, "\n      WITH CHECK (%s)",
+                                                                         PQgetvalue(result, i, 4));
+
+                               printTableAddFooter(&cont, buf.data);
+
+                       }
+                       PQclear(result);
+               }
+
+               /* print any extended statistics */
+               if (pset.sversion >= 100000)
+               {
+                       printfPQExpBuffer(&buf,
+                                                         "SELECT oid, "
+                                                         "stxrelid::pg_catalog.regclass, "
+                                                         "stxnamespace::pg_catalog.regnamespace AS nsp, "
+                                                         "stxname,\n"
+                                                         "  (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
+                                                         "   FROM pg_catalog.unnest(stxkeys) s(attnum)\n"
+                                                         "   JOIN pg_catalog.pg_attribute a ON (stxrelid = a.attrelid AND\n"
+                       "        a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
+                                                         "  (stxkind @> '{d}') AS ndist_enabled,\n"
+                                                         "  (stxkind @> '{f}') AS deps_enabled\n"
+                                                         "FROM pg_catalog.pg_statistic_ext stat "
+                                                         "WHERE stxrelid = '%s'\n"
+                                                         "ORDER BY 1;",
+                                                         oid);
+
+                       result = PSQLexec(buf.data);
+                       if (!result)
+                               goto error_return;
+                       else
+                               tuples = PQntuples(result);
+
+                       if (tuples > 0)
+                       {
+                               printTableAddFooter(&cont, _("Statistics objects:"));
+
+                               for (i = 0; i < tuples; i++)
+                               {
+                                       bool            gotone = false;
+
+                                       printfPQExpBuffer(&buf, "    ");
+
+                                       /* statistics object name (qualified with namespace) */
+                                       appendPQExpBuffer(&buf, "\"%s\".\"%s\" (",
+                                                                         PQgetvalue(result, i, 2),
+                                                                         PQgetvalue(result, i, 3));
+
+                                       /* options */
+                                       if (strcmp(PQgetvalue(result, i, 5), "t") == 0)
+                                       {
+                                               appendPQExpBufferStr(&buf, "ndistinct");
+                                               gotone = true;
+                                       }
+
+                                       if (strcmp(PQgetvalue(result, i, 6), "t") == 0)
+                                       {
+                                               appendPQExpBuffer(&buf, "%sdependencies", gotone ? ", " : "");
+                                       }
+
+                                       appendPQExpBuffer(&buf, ") ON %s FROM %s",
+                                                                         PQgetvalue(result, i, 4),
+                                                                         PQgetvalue(result, i, 1));
+
+                                       printTableAddFooter(&cont, buf.data);
+                               }
+                       }
+                       PQclear(result);
+               }
+
                /* print rules */
-               if (tableinfo.hasrules && tableinfo.relkind != 'm')
+               if (tableinfo.hasrules && tableinfo.relkind != RELKIND_MATVIEW)
                {
                        if (pset.sversion >= 80300)
                        {
@@ -1964,7 +2458,7 @@ describeOneTableDetails(const char *schemaname,
                                                                  "WHERE r.ev_class = '%s' ORDER BY 1;",
                                                                  oid);
                        }
-                       result = PSQLexec(buf.data, false);
+                       result = PSQLexec(buf.data);
                        if (!result)
                                goto error_return;
                        else
@@ -2037,6 +2531,37 @@ describeOneTableDetails(const char *schemaname,
                        }
                        PQclear(result);
                }
+
+               /* print any publications */
+               if (pset.sversion >= 100000)
+               {
+                       printfPQExpBuffer(&buf,
+                                                         "SELECT pub.pubname\n"
+                                                         " FROM pg_catalog.pg_publication pub,\n"
+                                 "      pg_catalog.pg_get_publication_tables(pub.pubname)\n"
+                                                         "WHERE relid = '%s'\n"
+                                                         "ORDER BY 1;",
+                                                         oid);
+
+                       result = PSQLexec(buf.data);
+                       if (!result)
+                               goto error_return;
+                       else
+                               tuples = PQntuples(result);
+
+                       if (tuples > 0)
+                               printTableAddFooter(&cont, _("Publications:"));
+
+                       /* Might be an empty set - that's ok */
+                       for (i = 0; i < tuples; i++)
+                       {
+                               printfPQExpBuffer(&buf, "    \"%s\"",
+                                                                 PQgetvalue(result, i, 0));
+
+                               printTableAddFooter(&cont, buf.data);
+                       }
+                       PQclear(result);
+               }
        }
 
        if (view_def)
@@ -2055,7 +2580,7 @@ describeOneTableDetails(const char *schemaname,
                                                          "FROM pg_catalog.pg_rewrite r\n"
                        "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;",
                                                          oid);
-                       result = PSQLexec(buf.data, false);
+                       result = PSQLexec(buf.data);
                        if (!result)
                                goto error_return;
 
@@ -2112,7 +2637,7 @@ describeOneTableDetails(const char *schemaname,
                                                                 "   WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))");
                appendPQExpBufferStr(&buf, "\nORDER BY 1;");
 
-               result = PSQLexec(buf.data, false);
+               result = PSQLexec(buf.data);
                if (!result)
                        goto error_return;
                else
@@ -2188,7 +2713,7 @@ describeOneTableDetails(const char *schemaname,
                                                                        printfPQExpBuffer(&buf, _("Disabled triggers:"));
                                                                break;
                                                        case 2:
-                                                                       printfPQExpBuffer(&buf, _("Disabled internal triggers:"));
+                                                               printfPQExpBuffer(&buf, _("Disabled internal triggers:"));
                                                                break;
                                                        case 3:
                                                                printfPQExpBuffer(&buf, _("Triggers firing always:"));
@@ -2219,14 +2744,16 @@ describeOneTableDetails(const char *schemaname,
        /*
         * Finish printing the footer information about a table.
         */
-       if (tableinfo.relkind == 'r' || tableinfo.relkind == 'm' ||
-               tableinfo.relkind == 'f')
+       if (tableinfo.relkind == RELKIND_RELATION ||
+               tableinfo.relkind == RELKIND_MATVIEW ||
+               tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
+               tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
        {
                PGresult   *result;
                int                     tuples;
 
                /* print foreign server name */
-               if (tableinfo.relkind == 'f')
+               if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
                {
                        char       *ftoptions;
 
@@ -2241,7 +2768,7 @@ describeOneTableDetails(const char *schemaname,
                                                          "     pg_catalog.pg_foreign_server s\n"
                                                          "WHERE f.ftrelid = %s AND s.oid = f.ftserver;",
                                                          oid);
-                       result = PSQLexec(buf.data, false);
+                       result = PSQLexec(buf.data);
                        if (!result)
                                goto error_return;
                        else if (PQntuples(result) != 1)
@@ -2251,7 +2778,7 @@ describeOneTableDetails(const char *schemaname,
                        }
 
                        /* Print server name */
-                       printfPQExpBuffer(&buf, "Server: %s",
+                       printfPQExpBuffer(&buf, _("Server: %s"),
                                                          PQgetvalue(result, 0, 0));
                        printTableAddFooter(&cont, buf.data);
 
@@ -2259,16 +2786,21 @@ describeOneTableDetails(const char *schemaname,
                        ftoptions = PQgetvalue(result, 0, 1);
                        if (ftoptions && ftoptions[0] != '\0')
                        {
-                               printfPQExpBuffer(&buf, "FDW Options: (%s)", ftoptions);
+                               printfPQExpBuffer(&buf, _("FDW options: (%s)"), ftoptions);
                                printTableAddFooter(&cont, buf.data);
                        }
                        PQclear(result);
                }
 
-               /* print inherited tables */
-               printfPQExpBuffer(&buf, "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhparent AND i.inhrelid = '%s' ORDER BY inhseqno;", oid);
+               /* print inherited tables (exclude, if parent is a partitioned table) */
+               printfPQExpBuffer(&buf,
+                                                 "SELECT c.oid::pg_catalog.regclass"
+                                         " FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i"
+                                                 " WHERE c.oid=i.inhparent AND i.inhrelid = '%s'"
+                                " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_TABLE)
+                                                 " ORDER BY inhseqno;", oid);
 
-               result = PSQLexec(buf.data, false);
+               result = PSQLexec(buf.data);
                if (!result)
                        goto error_return;
                else
@@ -2287,7 +2819,7 @@ describeOneTableDetails(const char *schemaname,
                                        printfPQExpBuffer(&buf, "%*s  %s",
                                                                          sw, "", PQgetvalue(result, i, 0));
                                if (i < tuples - 1)
-                                       appendPQExpBufferStr(&buf, ",");
+                                       appendPQExpBufferChar(&buf, ',');
 
                                printTableAddFooter(&cont, buf.data);
                        }
@@ -2295,13 +2827,27 @@ describeOneTableDetails(const char *schemaname,
                        PQclear(result);
                }
 
-               /* print child tables */
-               if (pset.sversion >= 80300)
-                       printfPQExpBuffer(&buf, "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhrelid AND i.inhparent = '%s' ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;", oid);
+               /* print child tables (with additional info if partitions) */
+               if (pset.sversion >= 100000)
+                       printfPQExpBuffer(&buf,
+                                                         "SELECT c.oid::pg_catalog.regclass, pg_get_expr(c.relpartbound, c.oid)"
+                                         " FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i"
+                                                         " WHERE c.oid=i.inhrelid AND"
+                                                         " i.inhparent = '%s' AND"
+                                         " EXISTS (SELECT 1 FROM pg_class c WHERE c.oid = '%s')"
+                                                         " ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;", oid, oid);
+               else if (pset.sversion >= 80300)
+                       printfPQExpBuffer(&buf,
+                                                         "SELECT c.oid::pg_catalog.regclass"
+                                         " FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i"
+                                                         " WHERE c.oid=i.inhrelid AND"
+                                                         " i.inhparent = '%s' AND"
+                                         " EXISTS (SELECT 1 FROM pg_class c WHERE c.oid = '%s')"
+                                                         " ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;", oid, oid);
                else
                        printfPQExpBuffer(&buf, "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhrelid AND i.inhparent = '%s' ORDER BY c.relname;", oid);
 
-               result = PSQLexec(buf.data, false);
+               result = PSQLexec(buf.data);
                if (!result)
                        goto error_return;
                else
@@ -2312,24 +2858,40 @@ describeOneTableDetails(const char *schemaname,
                        /* print the number of child tables, if any */
                        if (tuples > 0)
                        {
-                               printfPQExpBuffer(&buf, _("Number of child tables: %d (Use \\d+ to list them.)"), tuples);
+                               if (tableinfo.relkind != RELKIND_PARTITIONED_TABLE)
+                                       printfPQExpBuffer(&buf, _("Number of child tables: %d (Use \\d+ to list them.)"), tuples);
+                               else
+                                       printfPQExpBuffer(&buf, _("Number of partitions: %d (Use \\d+ to list them.)"), tuples);
                                printTableAddFooter(&cont, buf.data);
                        }
                }
                else
                {
                        /* display the list of child tables */
-                       const char *ct = _("Child tables");
+                       const char *ct = (tableinfo.relkind != RELKIND_PARTITIONED_TABLE) ?
+                       _("Child tables") : _("Partitions");
                        int                     ctw = pg_wcswidth(ct, strlen(ct), pset.encoding);
 
                        for (i = 0; i < tuples; i++)
                        {
-                               if (i == 0)
-                                       printfPQExpBuffer(&buf, "%s: %s",
-                                                                         ct, PQgetvalue(result, i, 0));
+                               if (tableinfo.relkind != RELKIND_PARTITIONED_TABLE)
+                               {
+                                       if (i == 0)
+                                               printfPQExpBuffer(&buf, "%s: %s",
+                                                                                 ct, PQgetvalue(result, i, 0));
+                                       else
+                                               printfPQExpBuffer(&buf, "%*s  %s",
+                                                                                 ctw, "", PQgetvalue(result, i, 0));
+                               }
                                else
-                                       printfPQExpBuffer(&buf, "%*s  %s",
-                                                                         ctw, "", PQgetvalue(result, i, 0));
+                               {
+                                       if (i == 0)
+                                               printfPQExpBuffer(&buf, "%s: %s %s",
+                                                                                 ct, PQgetvalue(result, i, 0), PQgetvalue(result, i, 1));
+                                       else
+                                               printfPQExpBuffer(&buf, "%*s  %s %s",
+                                                                                 ctw, "", PQgetvalue(result, i, 0), PQgetvalue(result, i, 1));
+                               }
                                if (i < tuples - 1)
                                        appendPQExpBufferChar(&buf, ',');
 
@@ -2345,13 +2907,17 @@ describeOneTableDetails(const char *schemaname,
                        printTableAddFooter(&cont, buf.data);
                }
 
-               if ((tableinfo.relkind == 'r' || tableinfo.relkind == 'm') &&
-                       /*
-                        * No need to display default values;  we already display a
-                        * REPLICA IDENTITY marker on indexes.
-                        */
-                       tableinfo.relreplident != 'd' && tableinfo.relreplident != 'i' &&
-                       strcmp(schemaname, "pg_catalog") != 0)
+               if (verbose &&
+                       (tableinfo.relkind == RELKIND_RELATION ||
+                        tableinfo.relkind == RELKIND_MATVIEW) &&
+
+               /*
+                * No need to display default values; we already display a REPLICA
+                * IDENTITY marker on indexes.
+                */
+                       tableinfo.relreplident != 'i' &&
+                       ((strcmp(schemaname, "pg_catalog") != 0 && tableinfo.relreplident != 'd') ||
+                        (strcmp(schemaname, "pg_catalog") == 0 && tableinfo.relreplident != 'n')))
                {
                        const char *s = _("Replica Identity");
 
@@ -2365,14 +2931,8 @@ describeOneTableDetails(const char *schemaname,
                }
 
                /* OIDs, if verbose and not a materialized view */
-               if (verbose && tableinfo.relkind != 'm')
-               {
-                       const char *s = _("Has OIDs");
-
-                       printfPQExpBuffer(&buf, "%s: %s", s,
-                                                         (tableinfo.hasoids ? _("yes") : _("no")));
-                       printTableAddFooter(&cont, buf.data);
-               }
+               if (verbose && tableinfo.relkind != RELKIND_MATVIEW && tableinfo.hasoids)
+                       printTableAddFooter(&cont, _("Has OIDs: yes"));
 
                /* Tablespace info */
                add_tablespace_footer(&cont, tableinfo.relkind, tableinfo.tablespace,
@@ -2389,8 +2949,7 @@ describeOneTableDetails(const char *schemaname,
                printTableAddFooter(&cont, buf.data);
        }
 
-       printTable(&cont, pset.queryFout, pset.logfile);
-       printTableCleanup(&cont);
+       printTable(&cont, pset.queryFout, false, pset.logfile);
 
        retval = true;
 
@@ -2410,13 +2969,6 @@ error_return:
                free(seq_values);
        }
 
-       if (modifiers)
-       {
-               for (ptr = modifiers; *ptr; ptr++)
-                       free(*ptr);
-               free(modifiers);
-       }
-
        if (view_def)
                free(view_def);
 
@@ -2436,7 +2988,10 @@ add_tablespace_footer(printTableContent *const cont, char relkind,
                                          Oid tablespace, const bool newline)
 {
        /* relkinds for which we support tablespaces */
-       if (relkind == 'r' || relkind == 'm' || relkind == 'i')
+       if (relkind == RELKIND_RELATION ||
+               relkind == RELKIND_MATVIEW ||
+               relkind == RELKIND_INDEX ||
+               relkind == RELKIND_PARTITIONED_TABLE)
        {
                /*
                 * We ignore the database default tablespace so that users not using
@@ -2452,7 +3007,7 @@ add_tablespace_footer(printTableContent *const cont, char relkind,
                        printfPQExpBuffer(&buf,
                                                          "SELECT spcname FROM pg_catalog.pg_tablespace\n"
                                                          "WHERE oid = '%u';", tablespace);
-                       result = PSQLexec(buf.data, false);
+                       result = PSQLexec(buf.data);
                        if (!result)
                                return;
                        /* Should always be the case, but.... */
@@ -2490,7 +3045,7 @@ add_tablespace_footer(printTableContent *const cont, char relkind,
  * Describes roles.  Any schema portion of the pattern is ignored.
  */
 bool
-describeRoles(const char *pattern, bool verbose)
+describeRoles(const char *pattern, bool verbose, bool showSystem)
 {
        PQExpBufferData buf;
        PGresult   *res;
@@ -2528,8 +3083,16 @@ describeRoles(const char *pattern, bool verbose)
                        appendPQExpBufferStr(&buf, "\n, r.rolreplication");
                }
 
+               if (pset.sversion >= 90500)
+               {
+                       appendPQExpBufferStr(&buf, "\n, r.rolbypassrls");
+               }
+
                appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
 
+               if (!showSystem && !pattern)
+                       appendPQExpBufferStr(&buf, "WHERE r.rolname !~ '^pg_'\n");
+
                processSQLNamePattern(pset.db, &buf, pattern, false, false,
                                                          NULL, "r.rolname", NULL, NULL);
        }
@@ -2551,7 +3114,7 @@ describeRoles(const char *pattern, bool verbose)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        if (!res)
                return false;
 
@@ -2591,6 +3154,10 @@ describeRoles(const char *pattern, bool verbose)
                        if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0)
                                add_role_attribute(&buf, _("Replication"));
 
+               if (pset.sversion >= 90500)
+                       if (strcmp(PQgetvalue(res, i, (verbose ? 11 : 10)), "t") == 0)
+                               add_role_attribute(&buf, _("Bypass RLS"));
+
                conns = atoi(PQgetvalue(res, i, 6));
                if (conns >= 0)
                {
@@ -2625,7 +3192,7 @@ describeRoles(const char *pattern, bool verbose)
        }
        termPQExpBuffer(&buf);
 
-       printTable(&cont, pset.queryFout, pset.logfile);
+       printTable(&cont, pset.queryFout, false, pset.logfile);
        printTableCleanup(&cont);
 
        for (i = 0; i < nrows; i++)
@@ -2682,7 +3249,7 @@ listDbRoleSettings(const char *pattern, const char *pattern2)
                return false;
        }
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        if (!res)
                return false;
 
@@ -2699,7 +3266,7 @@ listDbRoleSettings(const char *pattern, const char *pattern2)
                myopt.title = _("List of settings");
                myopt.translate_header = true;
 
-               printQuery(res, &myopt, pset.queryFout, pset.logfile);
+               printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
        }
 
        PQclear(res);
@@ -2744,20 +3311,21 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
        initPQExpBuffer(&buf);
 
        /*
-        * Note: as of Pg 8.2, we no longer use relkind 's', but we keep it here
-        * for backwards compatibility.
+        * Note: as of Pg 8.2, we no longer use relkind 's' (special), but we keep
+        * it here for backwards compatibility.
         */
        printfPQExpBuffer(&buf,
                                          "SELECT n.nspname as \"%s\",\n"
                                          "  c.relname as \"%s\",\n"
                                          "  CASE c.relkind"
-                                         " WHEN 'r' THEN '%s'"
-                                         " WHEN 'v' THEN '%s'"
-                                         " WHEN 'm' THEN '%s'"
-                                         " WHEN 'i' THEN '%s'"
-                                         " WHEN 'S' THEN '%s'"
+                                         " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
+                                         " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
+                                         " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
+                                         " WHEN " CppAsString2(RELKIND_INDEX) " THEN '%s'"
+                                         " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
                                          " WHEN 's' THEN '%s'"
-                                         " WHEN 'f' THEN '%s'"
+                                       " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
+                               " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
                                          " END as \"%s\",\n"
                                          "  pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
                                          gettext_noop("Schema"),
@@ -2769,6 +3337,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
                                          gettext_noop("sequence"),
                                          gettext_noop("special"),
                                          gettext_noop("foreign table"),
+                                         gettext_noop("table"),        /* partitioned table */
                                          gettext_noop("Type"),
                                          gettext_noop("Owner"));
 
@@ -2780,7 +3349,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
        if (verbose)
        {
                /*
-                * As of PostgreSQL 9.0, use pg_table_size() to show a more acurate
+                * As of PostgreSQL 9.0, use pg_table_size() to show a more accurate
                 * size of a table, including FSM, VM and TOAST tables.
                 */
                if (pset.sversion >= 90000)
@@ -2807,22 +3376,22 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
 
        appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
        if (showTables)
-               appendPQExpBufferStr(&buf, "'r',");
+               appendPQExpBufferStr(&buf, CppAsString2(RELKIND_RELATION) ","
+                                                        CppAsString2(RELKIND_PARTITIONED_TABLE) ",");
        if (showViews)
-               appendPQExpBufferStr(&buf, "'v',");
+               appendPQExpBufferStr(&buf, CppAsString2(RELKIND_VIEW) ",");
        if (showMatViews)
-               appendPQExpBufferStr(&buf, "'m',");
+               appendPQExpBufferStr(&buf, CppAsString2(RELKIND_MATVIEW) ",");
        if (showIndexes)
-               appendPQExpBufferStr(&buf, "'i',");
+               appendPQExpBufferStr(&buf, CppAsString2(RELKIND_INDEX) ",");
        if (showSeq)
-               appendPQExpBufferStr(&buf, "'S',");
+               appendPQExpBufferStr(&buf, CppAsString2(RELKIND_SEQUENCE) ",");
        if (showSystem || pattern)
-               appendPQExpBufferStr(&buf, "'s',");             /* was RELKIND_SPECIAL in <=
-                                                                                                * 8.1 */
+               appendPQExpBufferStr(&buf, "'s',");             /* was RELKIND_SPECIAL */
        if (showForeign)
-               appendPQExpBufferStr(&buf, "'f',");
+               appendPQExpBufferStr(&buf, CppAsString2(RELKIND_FOREIGN_TABLE) ",");
 
-       appendPQExpBufferStr(&buf, "''");               /* dummy */
+       appendPQExpBufferStr(&buf, "''");       /* dummy */
        appendPQExpBufferStr(&buf, ")\n");
 
        if (!showSystem && !pattern)
@@ -2831,9 +3400,10 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
 
        /*
         * TOAST objects are suppressed unconditionally.  Since we don't provide
-        * any way to select relkind 't' above, we would never show toast tables
-        * in any case; it seems a bit confusing to allow their indexes to be
-        * shown. Use plain \d if you really need to look at a TOAST table/index.
+        * any way to select RELKIND_TOASTVALUE above, we would never show toast
+        * tables in any case; it seems a bit confusing to allow their indexes to
+        * be shown.  Use plain \d if you really need to look at a TOAST
+        * table/index.
         */
        appendPQExpBufferStr(&buf, "      AND n.nspname !~ '^pg_toast'\n");
 
@@ -2843,7 +3413,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
 
        appendPQExpBufferStr(&buf, "ORDER BY 1,2;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -2863,7 +3433,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
                myopt.translate_columns = translate_columns;
                myopt.n_translate_columns = lengthof(translate_columns);
 
-               printQuery(res, &myopt, pset.queryFout, pset.logfile);
+               printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
        }
 
        PQclear(res);
@@ -2903,12 +3473,12 @@ listLanguages(const char *pattern, bool verbose, bool showSystem)
                                                  ",\n       NOT l.lanispl AS \"%s\",\n"
                                                  "       l.lanplcallfoid::regprocedure AS \"%s\",\n"
                                   "       l.lanvalidator::regprocedure AS \"%s\",\n       ",
-                                                 gettext_noop("Internal Language"),
-                                                 gettext_noop("Call Handler"),
+                                                 gettext_noop("Internal language"),
+                                                 gettext_noop("Call handler"),
                                                  gettext_noop("Validator"));
                if (pset.sversion >= 90000)
                        appendPQExpBuffer(&buf, "l.laninline::regprocedure AS \"%s\",\n       ",
-                                                         gettext_noop("Inline Handler"));
+                                                         gettext_noop("Inline handler"));
                printACLColumn(&buf, "l.lanacl");
        }
 
@@ -2930,7 +3500,7 @@ listLanguages(const char *pattern, bool verbose, bool showSystem)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -2939,7 +3509,7 @@ listLanguages(const char *pattern, bool verbose, bool showSystem)
        myopt.title = _("List of languages");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -2963,24 +3533,24 @@ listDomains(const char *pattern, bool verbose, bool showSystem)
        printfPQExpBuffer(&buf,
                                          "SELECT n.nspname as \"%s\",\n"
                                          "       t.typname as \"%s\",\n"
-        "       pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
-                                         "       TRIM(LEADING\n",
+       "       pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n",
                                          gettext_noop("Schema"),
                                          gettext_noop("Name"),
                                          gettext_noop("Type"));
 
        if (pset.sversion >= 90100)
-               appendPQExpBufferStr(&buf,
-                                                        "            COALESCE((SELECT ' collate ' || c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
-                                                        "                      WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation), '') ||\n");
+               appendPQExpBuffer(&buf,
+                                                 "       (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
+                                                 "        WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n",
+                                                 gettext_noop("Collation"));
        appendPQExpBuffer(&buf,
-          "            CASE WHEN t.typnotnull THEN ' not null' ELSE '' END ||\n"
-                                         "            CASE WHEN t.typdefault IS NOT NULL THEN ' default ' || t.typdefault ELSE '' END\n"
-                                         "       ) as \"%s\",\n"
+                        "       CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
+                                         "       t.typdefault as \"%s\",\n"
                                          "       pg_catalog.array_to_string(ARRAY(\n"
                                          "         SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
                                          "       ), ' ') as \"%s\"",
-                                         gettext_noop("Modifier"),
+                                         gettext_noop("Nullable"),
+                                         gettext_noop("Default"),
                                          gettext_noop("Check"));
 
        if (verbose)
@@ -3002,7 +3572,7 @@ listDomains(const char *pattern, bool verbose, bool showSystem)
        if (verbose)
                appendPQExpBufferStr(&buf,
                                                         "     LEFT JOIN pg_catalog.pg_description d "
-                                                        "ON d.classoid = t.tableoid AND d.objoid = t.oid "
+                                                  "ON d.classoid = t.tableoid AND d.objoid = t.oid "
                                                         "AND d.objsubid = 0\n");
 
        appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
@@ -3017,7 +3587,7 @@ listDomains(const char *pattern, bool verbose, bool showSystem)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -3026,7 +3596,7 @@ listDomains(const char *pattern, bool verbose, bool showSystem)
        myopt.title = _("List of domains");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -3044,7 +3614,7 @@ listConversions(const char *pattern, bool verbose, bool showSystem)
        PGresult   *res;
        printQueryOpt myopt = pset.popt;
        static const bool translate_columns[] =
-               {false, false, false, false, true, false};
+       {false, false, false, false, true, false};
 
        initPQExpBuffer(&buf);
 
@@ -3083,7 +3653,7 @@ listConversions(const char *pattern, bool verbose, bool showSystem)
 
        if (!showSystem && !pattern)
                appendPQExpBufferStr(&buf, "  AND n.nspname <> 'pg_catalog'\n"
-                                                 "  AND n.nspname <> 'information_schema'\n");
+                                                        "  AND n.nspname <> 'information_schema'\n");
 
        processSQLNamePattern(pset.db, &buf, pattern, true, false,
                                                  "n.nspname", "c.conname", NULL,
@@ -3091,7 +3661,7 @@ listConversions(const char *pattern, bool verbose, bool showSystem)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -3102,7 +3672,7 @@ listConversions(const char *pattern, bool verbose, bool showSystem)
        myopt.translate_columns = translate_columns;
        myopt.n_translate_columns = lengthof(translate_columns);
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -3134,7 +3704,7 @@ listEventTriggers(const char *pattern, bool verbose)
                                          "  when 'D' then '%s' end as \"%s\",\n"
                                          " e.evtfoid::pg_catalog.regproc as \"%s\", "
                                          "pg_catalog.array_to_string(array(select x"
-                                         " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
+                               " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
                                          gettext_noop("Name"),
                                          gettext_noop("Event"),
                                          gettext_noop("Owner"),
@@ -3157,7 +3727,7 @@ listEventTriggers(const char *pattern, bool verbose)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -3168,7 +3738,7 @@ listEventTriggers(const char *pattern, bool verbose)
        myopt.translate_columns = translate_columns;
        myopt.n_translate_columns = lengthof(translate_columns);
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -3256,7 +3826,7 @@ listCasts(const char *pattern, bool verbose)
 
        appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -3267,7 +3837,7 @@ listCasts(const char *pattern, bool verbose)
        myopt.translate_columns = translate_columns;
        myopt.n_translate_columns = lengthof(translate_columns);
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -3284,12 +3854,15 @@ listCollations(const char *pattern, bool verbose, bool showSystem)
        PQExpBufferData buf;
        PGresult   *res;
        printQueryOpt myopt = pset.popt;
-       static const bool translate_columns[] = {false, false, false, false, false};
+       static const bool translate_columns[] = {false, false, false, false, false, false};
 
        if (pset.sversion < 90100)
        {
-               psql_error("The server (version %d.%d) does not support collations.\n",
-                                  pset.sversion / 10000, (pset.sversion / 100) % 100);
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support collations.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
                return true;
        }
 
@@ -3305,6 +3878,11 @@ listCollations(const char *pattern, bool verbose, bool showSystem)
                                          gettext_noop("Collate"),
                                          gettext_noop("Ctype"));
 
+       if (pset.sversion >= 100000)
+               appendPQExpBuffer(&buf,
+                                                 ",\n       CASE c.collprovider WHEN 'd' THEN 'default' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\"",
+                                                 gettext_noop("Provider"));
+
        if (verbose)
                appendPQExpBuffer(&buf,
                                                  ",\n       pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
@@ -3312,11 +3890,11 @@ listCollations(const char *pattern, bool verbose, bool showSystem)
 
        appendPQExpBufferStr(&buf,
                          "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
-                                         "WHERE n.oid = c.collnamespace\n");
+                                                "WHERE n.oid = c.collnamespace\n");
 
        if (!showSystem && !pattern)
                appendPQExpBufferStr(&buf, "      AND n.nspname <> 'pg_catalog'\n"
-                                                 "      AND n.nspname <> 'information_schema'\n");
+                                                        "      AND n.nspname <> 'information_schema'\n");
 
        /*
         * Hide collations that aren't usable in the current database's encoding.
@@ -3332,7 +3910,7 @@ listCollations(const char *pattern, bool verbose, bool showSystem)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -3343,7 +3921,7 @@ listCollations(const char *pattern, bool verbose, bool showSystem)
        myopt.translate_columns = translate_columns;
        myopt.n_translate_columns = lengthof(translate_columns);
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -3391,7 +3969,7 @@ listSchemas(const char *pattern, bool verbose, bool showSystem)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -3400,7 +3978,7 @@ listSchemas(const char *pattern, bool verbose, bool showSystem)
        myopt.title = _("List of schemas");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -3420,8 +3998,11 @@ listTSParsers(const char *pattern, bool verbose)
 
        if (pset.sversion < 80300)
        {
-               psql_error("The server (version %d.%d) does not support full text search.\n",
-                                  pset.sversion / 10000, (pset.sversion / 100) % 100);
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support full text search.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
                return true;
        }
 
@@ -3431,11 +4012,11 @@ listTSParsers(const char *pattern, bool verbose)
        initPQExpBuffer(&buf);
 
        printfPQExpBuffer(&buf,
-                                         "SELECT \n"
+                                         "SELECT\n"
                                          "  n.nspname as \"%s\",\n"
                                          "  p.prsname as \"%s\",\n"
                        "  pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
-                                         "FROM pg_catalog.pg_ts_parser p \n"
+                                         "FROM pg_catalog.pg_ts_parser p\n"
                   "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
                                          gettext_noop("Schema"),
                                          gettext_noop("Name"),
@@ -3448,7 +4029,7 @@ listTSParsers(const char *pattern, bool verbose)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -3457,7 +4038,7 @@ listTSParsers(const char *pattern, bool verbose)
        myopt.title = _("List of text search parsers");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -3476,9 +4057,9 @@ listTSParsersVerbose(const char *pattern)
        initPQExpBuffer(&buf);
 
        printfPQExpBuffer(&buf,
-                                         "SELECT p.oid, \n"
-                                         "  n.nspname, \n"
-                                         "  p.prsname \n"
+                                         "SELECT p.oid,\n"
+                                         "  n.nspname,\n"
+                                         "  p.prsname\n"
                                          "FROM pg_catalog.pg_ts_parser p\n"
                        "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n"
                );
@@ -3489,7 +4070,7 @@ listTSParsersVerbose(const char *pattern)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -3543,34 +4124,34 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
        initPQExpBuffer(&buf);
 
        printfPQExpBuffer(&buf,
-                                         "SELECT '%s' AS \"%s\", \n"
-                                         "   p.prsstart::pg_catalog.regproc AS \"%s\", \n"
-                 "   pg_catalog.obj_description(p.prsstart, 'pg_proc') as \"%s\" \n"
-                                         " FROM pg_catalog.pg_ts_parser p \n"
-                                         " WHERE p.oid = '%s' \n"
-                                         "UNION ALL \n"
-                                         "SELECT '%s', \n"
-                                         "   p.prstoken::pg_catalog.regproc, \n"
-                                       "   pg_catalog.obj_description(p.prstoken, 'pg_proc') \n"
-                                         " FROM pg_catalog.pg_ts_parser p \n"
-                                         " WHERE p.oid = '%s' \n"
-                                         "UNION ALL \n"
-                                         "SELECT '%s', \n"
-                                         "   p.prsend::pg_catalog.regproc, \n"
-                                         "   pg_catalog.obj_description(p.prsend, 'pg_proc') \n"
-                                         " FROM pg_catalog.pg_ts_parser p \n"
-                                         " WHERE p.oid = '%s' \n"
-                                         "UNION ALL \n"
-                                         "SELECT '%s', \n"
-                                         "   p.prsheadline::pg_catalog.regproc, \n"
-                                "   pg_catalog.obj_description(p.prsheadline, 'pg_proc') \n"
-                                         " FROM pg_catalog.pg_ts_parser p \n"
-                                         " WHERE p.oid = '%s' \n"
-                                         "UNION ALL \n"
-                                         "SELECT '%s', \n"
-                                         "   p.prslextype::pg_catalog.regproc, \n"
-                                 "   pg_catalog.obj_description(p.prslextype, 'pg_proc') \n"
-                                         " FROM pg_catalog.pg_ts_parser p \n"
+                                         "SELECT '%s' AS \"%s\",\n"
+                                         "   p.prsstart::pg_catalog.regproc AS \"%s\",\n"
+                  "   pg_catalog.obj_description(p.prsstart, 'pg_proc') as \"%s\"\n"
+                                         " FROM pg_catalog.pg_ts_parser p\n"
+                                         " WHERE p.oid = '%s'\n"
+                                         "UNION ALL\n"
+                                         "SELECT '%s',\n"
+                                         "   p.prstoken::pg_catalog.regproc,\n"
+                                         "   pg_catalog.obj_description(p.prstoken, 'pg_proc')\n"
+                                         " FROM pg_catalog.pg_ts_parser p\n"
+                                         " WHERE p.oid = '%s'\n"
+                                         "UNION ALL\n"
+                                         "SELECT '%s',\n"
+                                         "   p.prsend::pg_catalog.regproc,\n"
+                                         "   pg_catalog.obj_description(p.prsend, 'pg_proc')\n"
+                                         " FROM pg_catalog.pg_ts_parser p\n"
+                                         " WHERE p.oid = '%s'\n"
+                                         "UNION ALL\n"
+                                         "SELECT '%s',\n"
+                                         "   p.prsheadline::pg_catalog.regproc,\n"
+                                 "   pg_catalog.obj_description(p.prsheadline, 'pg_proc')\n"
+                                         " FROM pg_catalog.pg_ts_parser p\n"
+                                         " WHERE p.oid = '%s'\n"
+                                         "UNION ALL\n"
+                                         "SELECT '%s',\n"
+                                         "   p.prslextype::pg_catalog.regproc,\n"
+                                  "   pg_catalog.obj_description(p.prslextype, 'pg_proc')\n"
+                                         " FROM pg_catalog.pg_ts_parser p\n"
                                          " WHERE p.oid = '%s';",
                                          gettext_noop("Start parse"),
                                          gettext_noop("Method"),
@@ -3586,7 +4167,7 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
                                          gettext_noop("Get token types"),
                                          oid);
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -3603,22 +4184,22 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
        myopt.translate_columns = translate_columns;
        myopt.n_translate_columns = lengthof(translate_columns);
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
 
        initPQExpBuffer(&buf);
 
        printfPQExpBuffer(&buf,
-                                         "SELECT t.alias as \"%s\", \n"
-                                         "  t.description as \"%s\" \n"
-                         "FROM pg_catalog.ts_token_type( '%s'::pg_catalog.oid ) as t \n"
+                                         "SELECT t.alias as \"%s\",\n"
+                                         "  t.description as \"%s\"\n"
+                          "FROM pg_catalog.ts_token_type( '%s'::pg_catalog.oid ) as t\n"
                                          "ORDER BY 1;",
                                          gettext_noop("Token name"),
                                          gettext_noop("Description"),
                                          oid);
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -3635,7 +4216,7 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
        myopt.translate_columns = NULL;
        myopt.n_translate_columns = 0;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -3655,15 +4236,18 @@ listTSDictionaries(const char *pattern, bool verbose)
 
        if (pset.sversion < 80300)
        {
-               psql_error("The server (version %d.%d) does not support full text search.\n",
-                                  pset.sversion / 10000, (pset.sversion / 100) % 100);
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support full text search.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
                return true;
        }
 
        initPQExpBuffer(&buf);
 
        printfPQExpBuffer(&buf,
-                                         "SELECT \n"
+                                         "SELECT\n"
                                          "  n.nspname as \"%s\",\n"
                                          "  d.dictname as \"%s\",\n",
                                          gettext_noop("Schema"),
@@ -3672,11 +4256,11 @@ listTSDictionaries(const char *pattern, bool verbose)
        if (verbose)
        {
                appendPQExpBuffer(&buf,
-                                                 "  ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM \n"
-                                                 "    pg_catalog.pg_ts_template t \n"
-                                                 "                      LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace \n"
-                                                 "                      WHERE d.dicttemplate = t.oid ) AS  \"%s\", \n"
-                                                 "  d.dictinitoption as \"%s\", \n",
+                                                 "  ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM\n"
+                                                 "    pg_catalog.pg_ts_template t\n"
+                                                 "    LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace\n"
+                                                 "    WHERE d.dicttemplate = t.oid ) AS  \"%s\",\n"
+                                                 "  d.dictinitoption as \"%s\",\n",
                                                  gettext_noop("Template"),
                                                  gettext_noop("Init options"));
        }
@@ -3694,7 +4278,7 @@ listTSDictionaries(const char *pattern, bool verbose)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -3703,7 +4287,7 @@ listTSDictionaries(const char *pattern, bool verbose)
        myopt.title = _("List of text search dictionaries");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -3723,8 +4307,11 @@ listTSTemplates(const char *pattern, bool verbose)
 
        if (pset.sversion < 80300)
        {
-               psql_error("The server (version %d.%d) does not support full text search.\n",
-                                  pset.sversion / 10000, (pset.sversion / 100) % 100);
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support full text search.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
                return true;
        }
 
@@ -3732,7 +4319,7 @@ listTSTemplates(const char *pattern, bool verbose)
 
        if (verbose)
                printfPQExpBuffer(&buf,
-                                                 "SELECT \n"
+                                                 "SELECT\n"
                                                  "  n.nspname AS \"%s\",\n"
                                                  "  t.tmplname AS \"%s\",\n"
                                                  "  t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
@@ -3745,7 +4332,7 @@ listTSTemplates(const char *pattern, bool verbose)
                                                  gettext_noop("Description"));
        else
                printfPQExpBuffer(&buf,
-                                                 "SELECT \n"
+                                                 "SELECT\n"
                                                  "  n.nspname AS \"%s\",\n"
                                                  "  t.tmplname AS \"%s\",\n"
                 "  pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
@@ -3762,7 +4349,7 @@ listTSTemplates(const char *pattern, bool verbose)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -3771,7 +4358,7 @@ listTSTemplates(const char *pattern, bool verbose)
        myopt.title = _("List of text search templates");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -3791,8 +4378,11 @@ listTSConfigs(const char *pattern, bool verbose)
 
        if (pset.sversion < 80300)
        {
-               psql_error("The server (version %d.%d) does not support full text search.\n",
-                                  pset.sversion / 10000, (pset.sversion / 100) % 100);
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support full text search.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
                return true;
        }
 
@@ -3802,12 +4392,12 @@ listTSConfigs(const char *pattern, bool verbose)
        initPQExpBuffer(&buf);
 
        printfPQExpBuffer(&buf,
-                                         "SELECT \n"
+                                         "SELECT\n"
                                          "   n.nspname as \"%s\",\n"
                                          "   c.cfgname as \"%s\",\n"
                   "   pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
                                          "FROM pg_catalog.pg_ts_config c\n"
-                 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace \n",
+                  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
                                          gettext_noop("Schema"),
                                          gettext_noop("Name"),
                                          gettext_noop("Description")
@@ -3819,7 +4409,7 @@ listTSConfigs(const char *pattern, bool verbose)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -3828,7 +4418,7 @@ listTSConfigs(const char *pattern, bool verbose)
        myopt.title = _("List of text search configurations");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -3845,13 +4435,13 @@ listTSConfigsVerbose(const char *pattern)
 
        printfPQExpBuffer(&buf,
                                          "SELECT c.oid, c.cfgname,\n"
-                                         "   n.nspname, \n"
-                                         "   p.prsname, \n"
-                                         "   np.nspname as pnspname \n"
-                                         "FROM pg_catalog.pg_ts_config c \n"
-          "   LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace, \n"
-                                         " pg_catalog.pg_ts_parser p \n"
-         "   LEFT JOIN pg_catalog.pg_namespace np ON np.oid = p.prsnamespace \n"
+                                         "   n.nspname,\n"
+                                         "   p.prsname,\n"
+                                         "   np.nspname as pnspname\n"
+                                         "FROM pg_catalog.pg_ts_config c\n"
+               "   LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace,\n"
+                                         " pg_catalog.pg_ts_parser p\n"
+          "   LEFT JOIN pg_catalog.pg_namespace np ON np.oid = p.prsnamespace\n"
                                          "WHERE  p.oid = c.cfgparser\n"
                );
 
@@ -3861,7 +4451,7 @@ listTSConfigsVerbose(const char *pattern)
 
        appendPQExpBufferStr(&buf, "ORDER BY 3, 2;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -3920,26 +4510,26 @@ describeOneTSConfig(const char *oid, const char *nspname, const char *cfgname,
        initPQExpBuffer(&buf);
 
        printfPQExpBuffer(&buf,
-                                         "SELECT \n"
-                                         "  ( SELECT t.alias FROM \n"
-                                         "    pg_catalog.ts_token_type(c.cfgparser) AS t \n"
-                                         "    WHERE t.tokid = m.maptokentype ) AS \"%s\", \n"
-                                         "  pg_catalog.btrim( \n"
-                                 "    ARRAY( SELECT mm.mapdict::pg_catalog.regdictionary \n"
-                                         "           FROM pg_catalog.pg_ts_config_map AS mm \n"
-                                         "           WHERE mm.mapcfg = m.mapcfg AND mm.maptokentype = m.maptokentype \n"
-                                         "           ORDER BY mapcfg, maptokentype, mapseqno \n"
-                                         "    ) :: pg_catalog.text , \n"
-                                         "  '{}') AS \"%s\" \n"
-        "FROM pg_catalog.pg_ts_config AS c, pg_catalog.pg_ts_config_map AS m \n"
-                                         "WHERE c.oid = '%s' AND m.mapcfg = c.oid \n"
-                                         "GROUP BY m.mapcfg, m.maptokentype, c.cfgparser \n"
+                                         "SELECT\n"
+                                         "  ( SELECT t.alias FROM\n"
+                                         "    pg_catalog.ts_token_type(c.cfgparser) AS t\n"
+                                         "    WHERE t.tokid = m.maptokentype ) AS \"%s\",\n"
+                                         "  pg_catalog.btrim(\n"
+                                  "    ARRAY( SELECT mm.mapdict::pg_catalog.regdictionary\n"
+                                         "           FROM pg_catalog.pg_ts_config_map AS mm\n"
+                                         "           WHERE mm.mapcfg = m.mapcfg AND mm.maptokentype = m.maptokentype\n"
+                                         "           ORDER BY mapcfg, maptokentype, mapseqno\n"
+                                         "    ) :: pg_catalog.text,\n"
+                                         "  '{}') AS \"%s\"\n"
+         "FROM pg_catalog.pg_ts_config AS c, pg_catalog.pg_ts_config_map AS m\n"
+                                         "WHERE c.oid = '%s' AND m.mapcfg = c.oid\n"
+                                         "GROUP BY m.mapcfg, m.maptokentype, c.cfgparser\n"
                                          "ORDER BY 1;",
                                          gettext_noop("Token"),
                                          gettext_noop("Dictionaries"),
                                          oid);
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -3966,7 +4556,7 @@ describeOneTSConfig(const char *oid, const char *nspname, const char *cfgname,
        myopt.topt.default_footer = false;
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        termPQExpBuffer(&title);
 
@@ -3989,8 +4579,11 @@ listForeignDataWrappers(const char *pattern, bool verbose)
 
        if (pset.sversion < 80400)
        {
-               psql_error("The server (version %d.%d) does not support foreign-data wrappers.\n",
-                                  pset.sversion / 10000, (pset.sversion / 100) % 100);
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support foreign-data wrappers.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
                return true;
        }
 
@@ -4019,7 +4612,7 @@ listForeignDataWrappers(const char *pattern, bool verbose)
                                                  "  quote_literal(option_value)  FROM "
                                                  "  pg_options_to_table(fdwoptions)),  ', ') || ')' "
                                                  "  END AS \"%s\"",
-                                                 gettext_noop("FDW Options"));
+                                                 gettext_noop("FDW options"));
 
                if (pset.sversion >= 90100)
                        appendPQExpBuffer(&buf,
@@ -4040,7 +4633,7 @@ listForeignDataWrappers(const char *pattern, bool verbose)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -4049,7 +4642,7 @@ listForeignDataWrappers(const char *pattern, bool verbose)
        myopt.title = _("List of foreign-data wrappers");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -4069,8 +4662,11 @@ listForeignServers(const char *pattern, bool verbose)
 
        if (pset.sversion < 80400)
        {
-               psql_error("The server (version %d.%d) does not support foreign servers.\n",
-                                  pset.sversion / 10000, (pset.sversion / 100) % 100);
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support foreign servers.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
                return true;
        }
 
@@ -4100,7 +4696,7 @@ listForeignServers(const char *pattern, bool verbose)
                                                  "  d.description AS \"%s\"",
                                                  gettext_noop("Type"),
                                                  gettext_noop("Version"),
-                                                 gettext_noop("FDW Options"),
+                                                 gettext_noop("FDW options"),
                                                  gettext_noop("Description"));
        }
 
@@ -4111,7 +4707,7 @@ listForeignServers(const char *pattern, bool verbose)
        if (verbose)
                appendPQExpBufferStr(&buf,
                                                         "LEFT JOIN pg_description d\n       "
-                                                        "ON d.classoid = s.tableoid AND d.objoid = s.oid "
+                                                  "ON d.classoid = s.tableoid AND d.objoid = s.oid "
                                                         "AND d.objsubid = 0\n");
 
        processSQLNamePattern(pset.db, &buf, pattern, false, false,
@@ -4119,7 +4715,7 @@ listForeignServers(const char *pattern, bool verbose)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -4128,7 +4724,7 @@ listForeignServers(const char *pattern, bool verbose)
        myopt.title = _("List of foreign servers");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -4148,8 +4744,11 @@ listUserMappings(const char *pattern, bool verbose)
 
        if (pset.sversion < 80400)
        {
-               psql_error("The server (version %d.%d) does not support user mappings.\n",
-                                  pset.sversion / 10000, (pset.sversion / 100) % 100);
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support user mappings.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
                return true;
        }
 
@@ -4168,7 +4767,7 @@ listUserMappings(const char *pattern, bool verbose)
                                                  "  quote_literal(option_value)  FROM "
                                                  "  pg_options_to_table(umoptions)),  ', ') || ')' "
                                                  "  END AS \"%s\"",
-                                                 gettext_noop("FDW Options"));
+                                                 gettext_noop("FDW options"));
 
        appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
 
@@ -4177,7 +4776,7 @@ listUserMappings(const char *pattern, bool verbose)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -4186,7 +4785,7 @@ listUserMappings(const char *pattern, bool verbose)
        myopt.title = _("List of user mappings");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -4206,8 +4805,11 @@ listForeignTables(const char *pattern, bool verbose)
 
        if (pset.sversion < 90100)
        {
-               psql_error("The server (version %d.%d) does not support foreign tables.\n",
-                                  pset.sversion / 10000, (pset.sversion / 100) % 100);
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support foreign tables.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
                return true;
        }
 
@@ -4229,7 +4831,7 @@ listForeignTables(const char *pattern, bool verbose)
                                                  "  pg_options_to_table(ftoptions)),  ', ') || ')' "
                                                  "  END AS \"%s\",\n"
                                                  "  d.description AS \"%s\"",
-                                                 gettext_noop("FDW Options"),
+                                                 gettext_noop("FDW options"),
                                                  gettext_noop("Description"));
 
        appendPQExpBufferStr(&buf,
@@ -4247,11 +4849,12 @@ listForeignTables(const char *pattern, bool verbose)
                                                         "d.objoid = c.oid AND d.objsubid = 0\n");
 
        processSQLNamePattern(pset.db, &buf, pattern, false, false,
-                                                 NULL, "n.nspname", "c.relname", NULL);
+                                                 "n.nspname", "c.relname", NULL,
+                                                 "pg_catalog.pg_table_is_visible(c.oid)");
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -4260,7 +4863,7 @@ listForeignTables(const char *pattern, bool verbose)
        myopt.title = _("List of foreign tables");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -4280,8 +4883,11 @@ listExtensions(const char *pattern)
 
        if (pset.sversion < 90100)
        {
-               psql_error("The server (version %d.%d) does not support extensions.\n",
-                                  pset.sversion / 10000, (pset.sversion / 100) % 100);
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support extensions.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
                return true;
        }
 
@@ -4305,7 +4911,7 @@ listExtensions(const char *pattern)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -4314,7 +4920,7 @@ listExtensions(const char *pattern)
        myopt.title = _("List of installed extensions");
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -4334,8 +4940,11 @@ listExtensionContents(const char *pattern)
 
        if (pset.sversion < 90100)
        {
-               psql_error("The server (version %d.%d) does not support extensions.\n",
-                                  pset.sversion / 10000, (pset.sversion / 100) % 100);
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support extensions.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
                return true;
        }
 
@@ -4351,7 +4960,7 @@ listExtensionContents(const char *pattern)
 
        appendPQExpBufferStr(&buf, "ORDER BY 1;");
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -4408,10 +5017,10 @@ listOneExtensionContents(const char *extname, const char *oid)
                                          "FROM pg_catalog.pg_depend\n"
                                          "WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND refobjid = '%s' AND deptype = 'e'\n"
                                          "ORDER BY 1;",
-                                         gettext_noop("Object Description"),
+                                         gettext_noop("Object description"),
                                          oid);
 
-       res = PSQLexec(buf.data, false);
+       res = PSQLexec(buf.data);
        termPQExpBuffer(&buf);
        if (!res)
                return false;
@@ -4421,7 +5030,269 @@ listOneExtensionContents(const char *extname, const char *oid)
        myopt.title = title;
        myopt.translate_header = true;
 
-       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
+
+       PQclear(res);
+       return true;
+}
+
+/* \dRp
+ * Lists publications.
+ *
+ * Takes an optional regexp to select particular publications
+ */
+bool
+listPublications(const char *pattern)
+{
+       PQExpBufferData buf;
+       PGresult   *res;
+       printQueryOpt myopt = pset.popt;
+       static const bool translate_columns[] = {false, false, false, false, false, false};
+
+       if (pset.sversion < 100000)
+       {
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support publications.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
+               return true;
+       }
+
+       initPQExpBuffer(&buf);
+
+       printfPQExpBuffer(&buf,
+                                         "SELECT pubname AS \"%s\",\n"
+                                         "  pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
+                                         "  puballtables AS \"%s\",\n"
+                                         "  pubinsert AS \"%s\",\n"
+                                         "  pubupdate AS \"%s\",\n"
+                                         "  pubdelete AS \"%s\"\n",
+                                         gettext_noop("Name"),
+                                         gettext_noop("Owner"),
+                                         gettext_noop("All tables"),
+                                         gettext_noop("Inserts"),
+                                         gettext_noop("Updates"),
+                                         gettext_noop("Deletes"));
+
+       appendPQExpBufferStr(&buf,
+                                                "\nFROM pg_catalog.pg_publication\n");
+
+       processSQLNamePattern(pset.db, &buf, pattern, false, false,
+                                                 NULL, "pubname", NULL,
+                                                 NULL);
+
+       appendPQExpBufferStr(&buf, "ORDER BY 1;");
+
+       res = PSQLexec(buf.data);
+       termPQExpBuffer(&buf);
+       if (!res)
+               return false;
+
+       myopt.nullPrint = NULL;
+       myopt.title = _("List of publications");
+       myopt.translate_header = true;
+       myopt.translate_columns = translate_columns;
+       myopt.n_translate_columns = lengthof(translate_columns);
+
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
+
+       PQclear(res);
+
+       return true;
+}
+
+/* \dRp+
+ * Describes publications including the contents.
+ *
+ * Takes an optional regexp to select particular publications
+ */
+bool
+describePublications(const char *pattern)
+{
+       PQExpBufferData buf;
+       int                     i;
+       PGresult   *res;
+
+       if (pset.sversion < 100000)
+       {
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support publications.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
+               return true;
+       }
+
+       initPQExpBuffer(&buf);
+
+       printfPQExpBuffer(&buf,
+                                         "SELECT oid, pubname, puballtables, pubinsert,\n"
+                                         "  pubupdate, pubdelete\n"
+                                         "FROM pg_catalog.pg_publication\n");
+
+       processSQLNamePattern(pset.db, &buf, pattern, false, false,
+                                                 NULL, "pubname", NULL,
+                                                 NULL);
+
+       appendPQExpBufferStr(&buf, "ORDER BY 2;");
+
+       res = PSQLexec(buf.data);
+       if (!res)
+       {
+               termPQExpBuffer(&buf);
+               return false;
+       }
+
+       for (i = 0; i < PQntuples(res); i++)
+       {
+               const char      align = 'l';
+               int                     ncols = 4;
+               int                     nrows = 1;
+               int                     tables = 0;
+               PGresult   *tabres;
+               char       *pubid = PQgetvalue(res, i, 0);
+               char       *pubname = PQgetvalue(res, i, 1);
+               bool            puballtables = strcmp(PQgetvalue(res, i, 2), "t") == 0;
+               int                     j;
+               PQExpBufferData title;
+               printTableOpt myopt = pset.popt.topt;
+               printTableContent cont;
+
+               initPQExpBuffer(&title);
+               printfPQExpBuffer(&title, _("Publication %s"), pubname);
+               printTableInit(&cont, &myopt, title.data, ncols, nrows);
+
+               printTableAddHeader(&cont, gettext_noop("All tables"), true, align);
+               printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
+               printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
+               printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
+
+               printTableAddCell(&cont, PQgetvalue(res, i, 2), false, false);
+               printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
+               printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
+               printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
+
+               if (!puballtables)
+               {
+                       printfPQExpBuffer(&buf,
+                                                         "SELECT n.nspname, c.relname\n"
+                                                         "FROM pg_catalog.pg_class c,\n"
+                                                         "     pg_catalog.pg_namespace n,\n"
+                                                         "     pg_catalog.pg_publication_rel pr\n"
+                                                         "WHERE c.relnamespace = n.oid\n"
+                                                         "  AND c.oid = pr.prrelid\n"
+                                                         "  AND pr.prpubid = '%s'\n"
+                                                         "ORDER BY 1,2", pubid);
+
+                       tabres = PSQLexec(buf.data);
+                       if (!tabres)
+                       {
+                               printTableCleanup(&cont);
+                               PQclear(res);
+                               termPQExpBuffer(&buf);
+                               termPQExpBuffer(&title);
+                               return false;
+                       }
+                       else
+                               tables = PQntuples(tabres);
+
+                       if (tables > 0)
+                               printTableAddFooter(&cont, _("Tables:"));
+
+                       for (j = 0; j < tables; j++)
+                       {
+                               printfPQExpBuffer(&buf, "    \"%s.%s\"",
+                                                                 PQgetvalue(tabres, j, 0),
+                                                                 PQgetvalue(tabres, j, 1));
+
+                               printTableAddFooter(&cont, buf.data);
+                       }
+                       PQclear(tabres);
+               }
+
+               printTable(&cont, pset.queryFout, false, pset.logfile);
+               printTableCleanup(&cont);
+
+               termPQExpBuffer(&title);
+       }
+
+       termPQExpBuffer(&buf);
+       PQclear(res);
+
+       return true;
+}
+
+/* \dRs
+ * Describes subscriptions.
+ *
+ * Takes an optional regexp to select particular subscriptions
+ */
+bool
+describeSubscriptions(const char *pattern, bool verbose)
+{
+       PQExpBufferData buf;
+       PGresult   *res;
+       printQueryOpt myopt = pset.popt;
+       static const bool translate_columns[] = {false, false, false, false,
+       false, false};
+
+       if (pset.sversion < 100000)
+       {
+               char            sverbuf[32];
+
+               psql_error("The server (version %s) does not support subscriptions.\n",
+                                  formatPGVersionNumber(pset.sversion, false,
+                                                                                sverbuf, sizeof(sverbuf)));
+               return true;
+       }
+
+       initPQExpBuffer(&buf);
+
+       printfPQExpBuffer(&buf,
+                                         "SELECT subname AS \"%s\"\n"
+                                         ",  pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
+                                         ",  subenabled AS \"%s\"\n"
+                                         ",  subpublications AS \"%s\"\n",
+                                         gettext_noop("Name"),
+                                         gettext_noop("Owner"),
+                                         gettext_noop("Enabled"),
+                                         gettext_noop("Publication"));
+
+       if (verbose)
+       {
+               appendPQExpBuffer(&buf,
+                                                 ",  subsynccommit AS \"%s\"\n"
+                                                 ",  subconninfo AS \"%s\"\n",
+                                                 gettext_noop("Synchronous commit"),
+                                                 gettext_noop("Conninfo"));
+       }
+
+       /* Only display subscriptions in current database. */
+       appendPQExpBufferStr(&buf,
+                                                "FROM pg_catalog.pg_subscription\n"
+                                                "WHERE subdbid = (SELECT oid\n"
+                                                "                 FROM pg_catalog.pg_database\n"
+                                        "                 WHERE datname = current_database())");
+
+       processSQLNamePattern(pset.db, &buf, pattern, true, false,
+                                                 NULL, "subname", NULL,
+                                                 NULL);
+
+       appendPQExpBufferStr(&buf, "ORDER BY 1;");
+
+       res = PSQLexec(buf.data);
+       termPQExpBuffer(&buf);
+       if (!res)
+               return false;
+
+       myopt.nullPrint = NULL;
+       myopt.title = _("List of subscriptions");
+       myopt.translate_header = true;
+       myopt.translate_columns = translate_columns;
+       myopt.n_translate_columns = lengthof(translate_columns);
+
+       printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
 
        PQclear(res);
        return true;
@@ -4431,7 +5302,7 @@ listOneExtensionContents(const char *extname, const char *oid)
  * printACLColumn
  *
  * Helper function for consistently formatting ACL (privilege) columns.
- * The proper targetlist entry is appended to buf.     Note lack of any
+ * The proper targetlist entry is appended to buf.  Note lack of any
  * whitespace or comma decoration.
  */
 static void