]> granicus.if.org Git - postgresql/blobdiff - src/bin/pg_dump/pg_dump.c
Empty search_path in Autovacuum and non-psql/pgbench clients.
[postgresql] / src / bin / pg_dump / pg_dump.c
index 8b67ec1aa1d60c0b60808ce2a4d3da9e46b8f151..2c934e6365403f413ef71e5fbb33c6c8f3dcb388 100644 (file)
@@ -60,6 +60,7 @@
 #include "pg_backup_db.h"
 #include "pg_backup_utils.h"
 #include "pg_dump.h"
+#include "fe_utils/connect.h"
 #include "fe_utils/string_utils.h"
 
 
@@ -1021,6 +1022,8 @@ setup_connection(Archive *AH, const char *dumpencoding,
        PGconn     *conn = GetConnection(AH);
        const char *std_strings;
 
+       PQclear(ExecuteSqlQueryForSingleRow(AH, ALWAYS_SECURE_SEARCH_PATH_SQL));
+
        /*
         * Set the client encoding if requested.
         */
@@ -1311,11 +1314,18 @@ expand_table_name_patterns(Archive *fout,
 
        for (cell = patterns->head; cell; cell = cell->next)
        {
+               /*
+                * Query must remain ABSOLUTELY devoid of unqualified names.  This
+                * would be unnecessary given a pg_table_is_visible() variant taking a
+                * search_path argument.
+                */
                appendPQExpBuffer(query,
                                                  "SELECT c.oid"
                                                  "\nFROM pg_catalog.pg_class c"
-                                                 "\n     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace"
-                                                 "\nWHERE c.relkind in ('%c', '%c', '%c', '%c', '%c', '%c')\n",
+                                                 "\n     LEFT JOIN pg_catalog.pg_namespace n"
+                                                 "\n     ON n.oid OPERATOR(pg_catalog.=) c.relnamespace"
+                                                 "\nWHERE c.relkind OPERATOR(pg_catalog.=) ANY"
+                                                 "\n    (array['%c', '%c', '%c', '%c', '%c', '%c'])\n",
                                                  RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW,
                                                  RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE,
                                                  RELKIND_PARTITIONED_TABLE);
@@ -1323,7 +1333,10 @@ expand_table_name_patterns(Archive *fout,
                                                          false, "n.nspname", "c.relname", NULL,
                                                          "pg_catalog.pg_table_is_visible(c.oid)");
 
+               ExecuteSqlStatement(fout, "RESET search_path");
                res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
+               PQclear(ExecuteSqlQueryForSingleRow(fout,
+                                                                                       ALWAYS_SECURE_SEARCH_PATH_SQL));
                if (strict_names && PQntuples(res) == 0)
                        exit_horribly(NULL, "no matching tables were found for pattern \"%s\"\n", cell->val);