Clean up some more freshly-dead code in pg_dump and pg_upgrade.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 16 Dec 2021 17:01:59 +0000 (12:01 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 16 Dec 2021 17:01:59 +0000 (12:01 -0500)
I missed a few things in 30e7c175b and e469f0aaf,
as noted by Justin Pryzby.

Discussion: https://postgr.es/m/2923349.1634942313@sss.pgh.pa.us

src/bin/pg_dump/dumputils.c
src/bin/pg_dump/pg_backup_db.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dump.h
src/bin/pg_upgrade/TESTING
src/bin/pg_upgrade/function.c
src/bin/pg_upgrade/option.c

index dfc96bc98baecfc8302e32080957db114e0faa44..b5900e4ed846d88ac071d62ac2616c6a159961e9 100644 (file)
@@ -39,8 +39,7 @@ static void AddAcl(PQExpBuffer aclbuf, const char *keyword,
  *     TABLE, SEQUENCE, FUNCTION, PROCEDURE, LANGUAGE, SCHEMA, DATABASE, TABLESPACE,
  *     FOREIGN DATA WRAPPER, SERVER, or LARGE OBJECT)
  * acls: the ACL string fetched from the database
- * baseacls: the initial ACL string for this object; can be
- *     NULL or empty string to indicate "not available from server"
+ * baseacls: the initial ACL string for this object
  * owner: username of object owner (will be passed through fmtId); can be
  *     NULL or empty string to indicate "no owner known"
  * prefix: string to prefix to each generated command; typically empty
@@ -104,17 +103,14 @@ buildACLCommands(const char *name, const char *subname, const char *nspname,
        return false;
    }
 
-   /* Parse the baseacls, if provided */
-   if (baseacls && *baseacls != '\0')
+   /* Parse the baseacls too */
+   if (!parsePGArray(baseacls, &baseitems, &nbaseitems))
    {
-       if (!parsePGArray(baseacls, &baseitems, &nbaseitems))
-       {
-           if (aclitems)
-               free(aclitems);
-           if (baseitems)
-               free(baseitems);
-           return false;
-       }
+       if (aclitems)
+           free(aclitems);
+       if (baseitems)
+           free(baseitems);
+       return false;
    }
 
    /*
index 2856c16e853dba4087061137e33a31912355ddf8..3184eda3e75d2076b3dc12cc14295ec514a34897 100644 (file)
@@ -56,18 +56,13 @@ _check_database_version(ArchiveHandle *AH)
    }
 
    /*
-    * When running against 9.0 or later, check if we are in recovery mode,
-    * which means we are on a hot standby.
+    * Check if server is in recovery mode, which means we are on a hot
+    * standby.
     */
-   if (remoteversion >= 90000)
-   {
-       res = ExecuteSqlQueryForSingleRow((Archive *) AH, "SELECT pg_catalog.pg_is_in_recovery()");
-
-       AH->public.isStandby = (strcmp(PQgetvalue(res, 0, 0), "t") == 0);
-       PQclear(res);
-   }
-   else
-       AH->public.isStandby = false;
+   res = ExecuteSqlQueryForSingleRow((Archive *) AH,
+                                     "SELECT pg_catalog.pg_is_in_recovery()");
+   AH->public.isStandby = (strcmp(PQgetvalue(res, 0, 0), "t") == 0);
+   PQclear(res);
 }
 
 /*
index 15dae8bd88e5c60412f9abb113094b1035d75246..784771c2d7e3bccf79203be72d0273365e6eeeb3 100644 (file)
@@ -11444,19 +11444,17 @@ dumpFunc(Archive *fout, const FuncInfo *finfo)
 
    /*
     * See backend/commands/functioncmds.c for details of how the 'AS' clause
-    * is used.  In 8.4 and up, an unused probin is NULL (here ""); previous
-    * versions would set it to "-".  There are no known cases in which prosrc
-    * is unused, so the tests below for "-" are probably useless.
+    * is used.
     */
    if (prosqlbody)
    {
        appendPQExpBufferStr(asPart, prosqlbody);
    }
-   else if (probin[0] != '\0' && strcmp(probin, "-") != 0)
+   else if (probin[0] != '\0')
    {
        appendPQExpBufferStr(asPart, "AS ");
        appendStringLiteralAH(asPart, probin, fout);
-       if (strcmp(prosrc, "-") != 0)
+       if (prosrc[0] != '\0')
        {
            appendPQExpBufferStr(asPart, ", ");
 
@@ -11473,15 +11471,12 @@ dumpFunc(Archive *fout, const FuncInfo *finfo)
    }
    else
    {
-       if (strcmp(prosrc, "-") != 0)
-       {
-           appendPQExpBufferStr(asPart, "AS ");
-           /* with no bin, dollar quote src unconditionally if allowed */
-           if (dopt->disable_dollar_quoting)
-               appendStringLiteralAH(asPart, prosrc, fout);
-           else
-               appendStringLiteralDQ(asPart, prosrc, NULL);
-       }
+       appendPQExpBufferStr(asPart, "AS ");
+       /* with no bin, dollar quote src unconditionally if allowed */
+       if (dopt->disable_dollar_quoting)
+           appendStringLiteralAH(asPart, prosrc, fout);
+       else
+           appendStringLiteralDQ(asPart, prosrc, NULL);
    }
 
    nallargs = finfo->nargs;    /* unless we learn different from allargs */
index 6dccb4be4edb483b64fae8403482c47029ba117c..f011ace8a80f15ec3d95e705b89a1b6eb6f60f7e 100644 (file)
@@ -149,9 +149,6 @@ typedef struct _dumpableObject
 /*
  * Object types that have ACLs must store them in a DumpableAcl sub-struct,
  * which must immediately follow the DumpableObject base struct.
- *
- * Note: when dumping from a pre-9.2 server, which lacks the acldefault()
- * function, acldefault will be NULL or empty.
  */
 typedef struct _dumpableAcl
 {
index e69874b42d0b32a3a6a43e9750f8530a549de957..78b9747908c5230cbf5ffa3e8535ee67395fd326 100644 (file)
@@ -55,16 +55,6 @@ Here are the steps needed to create a regression database dump file:
         Commands like CREATE TRIGGER and ALTER TABLE sometimes have
         differences.
 
-    d)  For pre-9.0, change CREATE OR REPLACE LANGUAGE to CREATE LANGUAGE
-
-    e)  For pre-9.0, remove 'regex_flavor'
-
-    f)  For pre-9.0, adjust extra_float_digits
-        Postgres 9.0 pg_dump uses extra_float_digits=-2 for pre-9.0
-        databases, and extra_float_digits=-3 for >= 9.0 databases.
-        It is necessary to modify 9.0 pg_dump to always use -3, and
-        modify the pre-9.0 old server to accept extra_float_digits=-3.
-
 Once the dump is created, it can be repeatedly loaded into the old
 database, upgraded, and dumped out of the new database, and then
 compared to the original version. To test the dump file, perform these
index 4952de1de5a9d0cea4502d7962fb5b71a4c79f4a..627ec0ce28b9de5586ec6eb357e03e58adbc91d9 100644 (file)
@@ -55,7 +55,6 @@ get_loadable_libraries(void)
    PGresult  **ress;
    int         totaltups;
    int         dbnum;
-   bool        found_public_plpython_handler = false;
 
    ress = (PGresult **) pg_malloc(old_cluster.dbarr.ndbs * sizeof(PGresult *));
    totaltups = 0;
@@ -79,68 +78,9 @@ get_loadable_libraries(void)
                                        FirstNormalObjectId);
        totaltups += PQntuples(ress[dbnum]);
 
-       /*
-        * Systems that install plpython before 8.1 have
-        * plpython_call_handler() defined in the "public" schema, causing
-        * pg_dump to dump it.  However that function still references
-        * "plpython" (no "2"), so it throws an error on restore.  This code
-        * checks for the problem function, reports affected databases to the
-        * user and explains how to remove them. 8.1 git commit:
-        * e0dedd0559f005d60c69c9772163e69c204bac69
-        * http://archives.postgresql.org/pgsql-hackers/2012-03/msg01101.php
-        * http://archives.postgresql.org/pgsql-bugs/2012-05/msg00206.php
-        */
-       if (GET_MAJOR_VERSION(old_cluster.major_version) <= 900)
-       {
-           PGresult   *res;
-
-           res = executeQueryOrDie(conn,
-                                   "SELECT 1 "
-                                   "FROM pg_catalog.pg_proc p "
-                                   "    JOIN pg_catalog.pg_namespace n "
-                                   "    ON pronamespace = n.oid "
-                                   "WHERE proname = 'plpython_call_handler' AND "
-                                   "nspname = 'public' AND "
-                                   "prolang = %u AND "
-                                   "probin = '$libdir/plpython' AND "
-                                   "p.oid >= %u;",
-                                   ClanguageId,
-                                   FirstNormalObjectId);
-           if (PQntuples(res) > 0)
-           {
-               if (!found_public_plpython_handler)
-               {
-                   pg_log(PG_WARNING,
-                          "\nThe old cluster has a \"plpython_call_handler\" function defined\n"
-                          "in the \"public\" schema which is a duplicate of the one defined\n"
-                          "in the \"pg_catalog\" schema.  You can confirm this by executing\n"
-                          "in psql:\n"
-                          "\n"
-                          "    \\df *.plpython_call_handler\n"
-                          "\n"
-                          "The \"public\" schema version of this function was created by a\n"
-                          "pre-8.1 install of plpython, and must be removed for pg_upgrade\n"
-                          "to complete because it references a now-obsolete \"plpython\"\n"
-                          "shared object file.  You can remove the \"public\" schema version\n"
-                          "of this function by running the following command:\n"
-                          "\n"
-                          "    DROP FUNCTION public.plpython_call_handler()\n"
-                          "\n"
-                          "in each affected database:\n"
-                          "\n");
-               }
-               pg_log(PG_WARNING, "    %s\n", active_db->db_name);
-               found_public_plpython_handler = true;
-           }
-           PQclear(res);
-       }
-
        PQfinish(conn);
    }
 
-   if (found_public_plpython_handler)
-       pg_fatal("Remove the problem functions from the old cluster to continue.\n");
-
    os_info.libraries = (LibraryInfo *) pg_malloc(totaltups * sizeof(LibraryInfo));
    totaltups = 0;
 
@@ -209,22 +149,6 @@ check_loadable_libraries(void)
        /* Did the library name change?  Probe it. */
        if (libnum == 0 || strcmp(lib, os_info.libraries[libnum - 1].name) != 0)
        {
-           /*
-            * In Postgres 9.0, Python 3 support was added, and to do that, a
-            * plpython2u language was created with library name plpython2.so
-            * as a symbolic link to plpython.so.  In Postgres 9.1, only the
-            * plpython2.so library was created, and both plpythonu and
-            * plpython2u point to it.  For this reason, any reference to
-            * library name "plpython" in an old PG <= 9.1 cluster must look
-            * for "plpython2" in the new cluster.
-            */
-           if (GET_MAJOR_VERSION(old_cluster.major_version) <= 900 &&
-               strcmp(lib, "$libdir/plpython") == 0)
-           {
-               lib = "$libdir/plpython2";
-               llen = strlen(lib);
-           }
-
            strcpy(cmd, "LOAD '");
            PQescapeStringConn(conn, cmd + strlen(cmd), lib, llen, NULL);
            strcat(cmd, "'");
index 64bbda565084e0f2c25b002cd052fd78841e893e..2d92294d9d35e70f803e9f59dc702eaf7601422e 100644 (file)
@@ -160,11 +160,6 @@ parseCommandLine(int argc, char *argv[])
                }
                break;
 
-               /*
-                * Someday, the port number option could be removed and passed
-                * using -o/-O, but that requires postmaster -C to be
-                * supported on all old/new versions (added in PG 9.2).
-                */
            case 'p':
                if ((old_cluster.port = atoi(optarg)) <= 0)
                    pg_fatal("invalid old port number\n");
@@ -187,12 +182,6 @@ parseCommandLine(int argc, char *argv[])
                pg_free(os_info.user);
                os_info.user = pg_strdup(optarg);
                os_info.user_specified = true;
-
-               /*
-                * Push the user name into the environment so pre-9.1
-                * pg_ctl/libpq uses it.
-                */
-               setenv("PGUSER", os_info.user, 1);
                break;
 
            case 'v':
@@ -469,67 +458,51 @@ void
 get_sock_dir(ClusterInfo *cluster, bool live_check)
 {
 #if defined(HAVE_UNIX_SOCKETS) && !defined(WIN32)
-
-   /*
-    * sockdir and port were added to postmaster.pid in PG 9.1. Pre-9.1 cannot
-    * process pg_ctl -w for sockets in non-default locations.
-    */
-   if (GET_MAJOR_VERSION(cluster->major_version) >= 901)
+   if (!live_check)
+       cluster->sockdir = user_opts.socketdir;
+   else
    {
-       if (!live_check)
-           cluster->sockdir = user_opts.socketdir;
-       else
+       /*
+        * If we are doing a live check, we will use the old cluster's Unix
+        * domain socket directory so we can connect to the live server.
+        */
+       unsigned short orig_port = cluster->port;
+       char        filename[MAXPGPATH],
+                   line[MAXPGPATH];
+       FILE       *fp;
+       int         lineno;
+
+       snprintf(filename, sizeof(filename), "%s/postmaster.pid",
+                cluster->pgdata);
+       if ((fp = fopen(filename, "r")) == NULL)
+           pg_fatal("could not open file \"%s\": %s\n",
+                    filename, strerror(errno));
+
+       for (lineno = 1;
+            lineno <= Max(LOCK_FILE_LINE_PORT, LOCK_FILE_LINE_SOCKET_DIR);
+            lineno++)
        {
-           /*
-            * If we are doing a live check, we will use the old cluster's
-            * Unix domain socket directory so we can connect to the live
-            * server.
-            */
-           unsigned short orig_port = cluster->port;
-           char        filename[MAXPGPATH],
-                       line[MAXPGPATH];
-           FILE       *fp;
-           int         lineno;
-
-           snprintf(filename, sizeof(filename), "%s/postmaster.pid",
-                    cluster->pgdata);
-           if ((fp = fopen(filename, "r")) == NULL)
-               pg_fatal("could not open file \"%s\": %s\n",
-                        filename, strerror(errno));
-
-           for (lineno = 1;
-                lineno <= Max(LOCK_FILE_LINE_PORT, LOCK_FILE_LINE_SOCKET_DIR);
-                lineno++)
+           if (fgets(line, sizeof(line), fp) == NULL)
+               pg_fatal("could not read line %d from file \"%s\": %s\n",
+                        lineno, filename, strerror(errno));
+
+           /* potentially overwrite user-supplied value */
+           if (lineno == LOCK_FILE_LINE_PORT)
+               sscanf(line, "%hu", &old_cluster.port);
+           if (lineno == LOCK_FILE_LINE_SOCKET_DIR)
            {
-               if (fgets(line, sizeof(line), fp) == NULL)
-                   pg_fatal("could not read line %d from file \"%s\": %s\n",
-                            lineno, filename, strerror(errno));
-
-               /* potentially overwrite user-supplied value */
-               if (lineno == LOCK_FILE_LINE_PORT)
-                   sscanf(line, "%hu", &old_cluster.port);
-               if (lineno == LOCK_FILE_LINE_SOCKET_DIR)
-               {
-                   /* strip trailing newline and carriage return */
-                   cluster->sockdir = pg_strdup(line);
-                   (void) pg_strip_crlf(cluster->sockdir);
-               }
+               /* strip trailing newline and carriage return */
+               cluster->sockdir = pg_strdup(line);
+               (void) pg_strip_crlf(cluster->sockdir);
            }
-           fclose(fp);
-
-           /* warn of port number correction */
-           if (orig_port != DEF_PGUPORT && old_cluster.port != orig_port)
-               pg_log(PG_WARNING, "user-supplied old port number %hu corrected to %hu\n",
-                      orig_port, cluster->port);
        }
-   }
-   else
+       fclose(fp);
 
-       /*
-        * Can't get sockdir and pg_ctl -w can't use a non-default, use
-        * default
-        */
-       cluster->sockdir = NULL;
+       /* warn of port number correction */
+       if (orig_port != DEF_PGUPORT && old_cluster.port != orig_port)
+           pg_log(PG_WARNING, "user-supplied old port number %hu corrected to %hu\n",
+                  orig_port, cluster->port);
+   }
 #else                          /* !HAVE_UNIX_SOCKETS || WIN32 */
    cluster->sockdir = NULL;
 #endif