Skip to content

Commit c49d926

Browse files
committed
Clean up some more freshly-dead code in pg_dump and pg_upgrade.
I missed a few things in 30e7c17 and e469f0a, as noted by Justin Pryzby. Discussion: https://postgr.es/m/2923349.1634942313@sss.pgh.pa.us
1 parent 58e2e6e commit c49d926

File tree

7 files changed

+62
-192
lines changed

7 files changed

+62
-192
lines changed

src/bin/pg_dump/dumputils.c

+8-12
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ static void AddAcl(PQExpBuffer aclbuf, const char *keyword,
3939
* TABLE, SEQUENCE, FUNCTION, PROCEDURE, LANGUAGE, SCHEMA, DATABASE, TABLESPACE,
4040
* FOREIGN DATA WRAPPER, SERVER, or LARGE OBJECT)
4141
* acls: the ACL string fetched from the database
42-
* baseacls: the initial ACL string for this object; can be
43-
* NULL or empty string to indicate "not available from server"
42+
* baseacls: the initial ACL string for this object
4443
* owner: username of object owner (will be passed through fmtId); can be
4544
* NULL or empty string to indicate "no owner known"
4645
* prefix: string to prefix to each generated command; typically empty
@@ -104,17 +103,14 @@ buildACLCommands(const char *name, const char *subname, const char *nspname,
104103
return false;
105104
}
106105

107-
/* Parse the baseacls, if provided */
108-
if (baseacls && *baseacls != '\0')
106+
/* Parse the baseacls too */
107+
if (!parsePGArray(baseacls, &baseitems, &nbaseitems))
109108
{
110-
if (!parsePGArray(baseacls, &baseitems, &nbaseitems))
111-
{
112-
if (aclitems)
113-
free(aclitems);
114-
if (baseitems)
115-
free(baseitems);
116-
return false;
117-
}
109+
if (aclitems)
110+
free(aclitems);
111+
if (baseitems)
112+
free(baseitems);
113+
return false;
118114
}
119115

120116
/*

src/bin/pg_dump/pg_backup_db.c

+6-11
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,13 @@ _check_database_version(ArchiveHandle *AH)
5656
}
5757

5858
/*
59-
* When running against 9.0 or later, check if we are in recovery mode,
60-
* which means we are on a hot standby.
59+
* Check if server is in recovery mode, which means we are on a hot
60+
* standby.
6161
*/
62-
if (remoteversion >= 90000)
63-
{
64-
res = ExecuteSqlQueryForSingleRow((Archive *) AH, "SELECT pg_catalog.pg_is_in_recovery()");
65-
66-
AH->public.isStandby = (strcmp(PQgetvalue(res, 0, 0), "t") == 0);
67-
PQclear(res);
68-
}
69-
else
70-
AH->public.isStandby = false;
62+
res = ExecuteSqlQueryForSingleRow((Archive *) AH,
63+
"SELECT pg_catalog.pg_is_in_recovery()");
64+
AH->public.isStandby = (strcmp(PQgetvalue(res, 0, 0), "t") == 0);
65+
PQclear(res);
7166
}
7267

7368
/*

src/bin/pg_dump/pg_dump.c

+9-14
Original file line numberDiff line numberDiff line change
@@ -11444,19 +11444,17 @@ dumpFunc(Archive *fout, const FuncInfo *finfo)
1144411444

1144511445
/*
1144611446
* See backend/commands/functioncmds.c for details of how the 'AS' clause
11447-
* is used. In 8.4 and up, an unused probin is NULL (here ""); previous
11448-
* versions would set it to "-". There are no known cases in which prosrc
11449-
* is unused, so the tests below for "-" are probably useless.
11447+
* is used.
1145011448
*/
1145111449
if (prosqlbody)
1145211450
{
1145311451
appendPQExpBufferStr(asPart, prosqlbody);
1145411452
}
11455-
else if (probin[0] != '\0' && strcmp(probin, "-") != 0)
11453+
else if (probin[0] != '\0')
1145611454
{
1145711455
appendPQExpBufferStr(asPart, "AS ");
1145811456
appendStringLiteralAH(asPart, probin, fout);
11459-
if (strcmp(prosrc, "-") != 0)
11457+
if (prosrc[0] != '\0')
1146011458
{
1146111459
appendPQExpBufferStr(asPart, ", ");
1146211460

@@ -11473,15 +11471,12 @@ dumpFunc(Archive *fout, const FuncInfo *finfo)
1147311471
}
1147411472
else
1147511473
{
11476-
if (strcmp(prosrc, "-") != 0)
11477-
{
11478-
appendPQExpBufferStr(asPart, "AS ");
11479-
/* with no bin, dollar quote src unconditionally if allowed */
11480-
if (dopt->disable_dollar_quoting)
11481-
appendStringLiteralAH(asPart, prosrc, fout);
11482-
else
11483-
appendStringLiteralDQ(asPart, prosrc, NULL);
11484-
}
11474+
appendPQExpBufferStr(asPart, "AS ");
11475+
/* with no bin, dollar quote src unconditionally if allowed */
11476+
if (dopt->disable_dollar_quoting)
11477+
appendStringLiteralAH(asPart, prosrc, fout);
11478+
else
11479+
appendStringLiteralDQ(asPart, prosrc, NULL);
1148511480
}
1148611481

1148711482
nallargs = finfo->nargs; /* unless we learn different from allargs */

src/bin/pg_dump/pg_dump.h

-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ typedef struct _dumpableObject
149149
/*
150150
* Object types that have ACLs must store them in a DumpableAcl sub-struct,
151151
* which must immediately follow the DumpableObject base struct.
152-
*
153-
* Note: when dumping from a pre-9.2 server, which lacks the acldefault()
154-
* function, acldefault will be NULL or empty.
155152
*/
156153
typedef struct _dumpableAcl
157154
{

src/bin/pg_upgrade/TESTING

-10
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,6 @@ Here are the steps needed to create a regression database dump file:
5555
Commands like CREATE TRIGGER and ALTER TABLE sometimes have
5656
differences.
5757

58-
d) For pre-9.0, change CREATE OR REPLACE LANGUAGE to CREATE LANGUAGE
59-
60-
e) For pre-9.0, remove 'regex_flavor'
61-
62-
f) For pre-9.0, adjust extra_float_digits
63-
Postgres 9.0 pg_dump uses extra_float_digits=-2 for pre-9.0
64-
databases, and extra_float_digits=-3 for >= 9.0 databases.
65-
It is necessary to modify 9.0 pg_dump to always use -3, and
66-
modify the pre-9.0 old server to accept extra_float_digits=-3.
67-
6858
Once the dump is created, it can be repeatedly loaded into the old
6959
database, upgraded, and dumped out of the new database, and then
7060
compared to the original version. To test the dump file, perform these

src/bin/pg_upgrade/function.c

-76
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ get_loadable_libraries(void)
5555
PGresult **ress;
5656
int totaltups;
5757
int dbnum;
58-
bool found_public_plpython_handler = false;
5958

6059
ress = (PGresult **) pg_malloc(old_cluster.dbarr.ndbs * sizeof(PGresult *));
6160
totaltups = 0;
@@ -79,68 +78,9 @@ get_loadable_libraries(void)
7978
FirstNormalObjectId);
8079
totaltups += PQntuples(ress[dbnum]);
8180

82-
/*
83-
* Systems that install plpython before 8.1 have
84-
* plpython_call_handler() defined in the "public" schema, causing
85-
* pg_dump to dump it. However that function still references
86-
* "plpython" (no "2"), so it throws an error on restore. This code
87-
* checks for the problem function, reports affected databases to the
88-
* user and explains how to remove them. 8.1 git commit:
89-
* e0dedd0559f005d60c69c9772163e69c204bac69
90-
* http://archives.postgresql.org/pgsql-hackers/2012-03/msg01101.php
91-
* http://archives.postgresql.org/pgsql-bugs/2012-05/msg00206.php
92-
*/
93-
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 900)
94-
{
95-
PGresult *res;
96-
97-
res = executeQueryOrDie(conn,
98-
"SELECT 1 "
99-
"FROM pg_catalog.pg_proc p "
100-
" JOIN pg_catalog.pg_namespace n "
101-
" ON pronamespace = n.oid "
102-
"WHERE proname = 'plpython_call_handler' AND "
103-
"nspname = 'public' AND "
104-
"prolang = %u AND "
105-
"probin = '$libdir/plpython' AND "
106-
"p.oid >= %u;",
107-
ClanguageId,
108-
FirstNormalObjectId);
109-
if (PQntuples(res) > 0)
110-
{
111-
if (!found_public_plpython_handler)
112-
{
113-
pg_log(PG_WARNING,
114-
"\nThe old cluster has a \"plpython_call_handler\" function defined\n"
115-
"in the \"public\" schema which is a duplicate of the one defined\n"
116-
"in the \"pg_catalog\" schema. You can confirm this by executing\n"
117-
"in psql:\n"
118-
"\n"
119-
" \\df *.plpython_call_handler\n"
120-
"\n"
121-
"The \"public\" schema version of this function was created by a\n"
122-
"pre-8.1 install of plpython, and must be removed for pg_upgrade\n"
123-
"to complete because it references a now-obsolete \"plpython\"\n"
124-
"shared object file. You can remove the \"public\" schema version\n"
125-
"of this function by running the following command:\n"
126-
"\n"
127-
" DROP FUNCTION public.plpython_call_handler()\n"
128-
"\n"
129-
"in each affected database:\n"
130-
"\n");
131-
}
132-
pg_log(PG_WARNING, " %s\n", active_db->db_name);
133-
found_public_plpython_handler = true;
134-
}
135-
PQclear(res);
136-
}
137-
13881
PQfinish(conn);
13982
}
14083

141-
if (found_public_plpython_handler)
142-
pg_fatal("Remove the problem functions from the old cluster to continue.\n");
143-
14484
os_info.libraries = (LibraryInfo *) pg_malloc(totaltups * sizeof(LibraryInfo));
14585
totaltups = 0;
14686

@@ -209,22 +149,6 @@ check_loadable_libraries(void)
209149
/* Did the library name change? Probe it. */
210150
if (libnum == 0 || strcmp(lib, os_info.libraries[libnum - 1].name) != 0)
211151
{
212-
/*
213-
* In Postgres 9.0, Python 3 support was added, and to do that, a
214-
* plpython2u language was created with library name plpython2.so
215-
* as a symbolic link to plpython.so. In Postgres 9.1, only the
216-
* plpython2.so library was created, and both plpythonu and
217-
* plpython2u point to it. For this reason, any reference to
218-
* library name "plpython" in an old PG <= 9.1 cluster must look
219-
* for "plpython2" in the new cluster.
220-
*/
221-
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 900 &&
222-
strcmp(lib, "$libdir/plpython") == 0)
223-
{
224-
lib = "$libdir/plpython2";
225-
llen = strlen(lib);
226-
}
227-
228152
strcpy(cmd, "LOAD '");
229153
PQescapeStringConn(conn, cmd + strlen(cmd), lib, llen, NULL);
230154
strcat(cmd, "'");

src/bin/pg_upgrade/option.c

+39-66
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ parseCommandLine(int argc, char *argv[])
160160
}
161161
break;
162162

163-
/*
164-
* Someday, the port number option could be removed and passed
165-
* using -o/-O, but that requires postmaster -C to be
166-
* supported on all old/new versions (added in PG 9.2).
167-
*/
168163
case 'p':
169164
if ((old_cluster.port = atoi(optarg)) <= 0)
170165
pg_fatal("invalid old port number\n");
@@ -187,12 +182,6 @@ parseCommandLine(int argc, char *argv[])
187182
pg_free(os_info.user);
188183
os_info.user = pg_strdup(optarg);
189184
os_info.user_specified = true;
190-
191-
/*
192-
* Push the user name into the environment so pre-9.1
193-
* pg_ctl/libpq uses it.
194-
*/
195-
setenv("PGUSER", os_info.user, 1);
196185
break;
197186

198187
case 'v':
@@ -469,67 +458,51 @@ void
469458
get_sock_dir(ClusterInfo *cluster, bool live_check)
470459
{
471460
#if defined(HAVE_UNIX_SOCKETS) && !defined(WIN32)
472-
473-
/*
474-
* sockdir and port were added to postmaster.pid in PG 9.1. Pre-9.1 cannot
475-
* process pg_ctl -w for sockets in non-default locations.
476-
*/
477-
if (GET_MAJOR_VERSION(cluster->major_version) >= 901)
461+
if (!live_check)
462+
cluster->sockdir = user_opts.socketdir;
463+
else
478464
{
479-
if (!live_check)
480-
cluster->sockdir = user_opts.socketdir;
481-
else
465+
/*
466+
* If we are doing a live check, we will use the old cluster's Unix
467+
* domain socket directory so we can connect to the live server.
468+
*/
469+
unsigned short orig_port = cluster->port;
470+
char filename[MAXPGPATH],
471+
line[MAXPGPATH];
472+
FILE *fp;
473+
int lineno;
474+
475+
snprintf(filename, sizeof(filename), "%s/postmaster.pid",
476+
cluster->pgdata);
477+
if ((fp = fopen(filename, "r")) == NULL)
478+
pg_fatal("could not open file \"%s\": %s\n",
479+
filename, strerror(errno));
480+
481+
for (lineno = 1;
482+
lineno <= Max(LOCK_FILE_LINE_PORT, LOCK_FILE_LINE_SOCKET_DIR);
483+
lineno++)
482484
{
483-
/*
484-
* If we are doing a live check, we will use the old cluster's
485-
* Unix domain socket directory so we can connect to the live
486-
* server.
487-
*/
488-
unsigned short orig_port = cluster->port;
489-
char filename[MAXPGPATH],
490-
line[MAXPGPATH];
491-
FILE *fp;
492-
int lineno;
493-
494-
snprintf(filename, sizeof(filename), "%s/postmaster.pid",
495-
cluster->pgdata);
496-
if ((fp = fopen(filename, "r")) == NULL)
497-
pg_fatal("could not open file \"%s\": %s\n",
498-
filename, strerror(errno));
499-
500-
for (lineno = 1;
501-
lineno <= Max(LOCK_FILE_LINE_PORT, LOCK_FILE_LINE_SOCKET_DIR);
502-
lineno++)
485+
if (fgets(line, sizeof(line), fp) == NULL)
486+
pg_fatal("could not read line %d from file \"%s\": %s\n",
487+
lineno, filename, strerror(errno));
488+
489+
/* potentially overwrite user-supplied value */
490+
if (lineno == LOCK_FILE_LINE_PORT)
491+
sscanf(line, "%hu", &old_cluster.port);
492+
if (lineno == LOCK_FILE_LINE_SOCKET_DIR)
503493
{
504-
if (fgets(line, sizeof(line), fp) == NULL)
505-
pg_fatal("could not read line %d from file \"%s\": %s\n",
506-
lineno, filename, strerror(errno));
507-
508-
/* potentially overwrite user-supplied value */
509-
if (lineno == LOCK_FILE_LINE_PORT)
510-
sscanf(line, "%hu", &old_cluster.port);
511-
if (lineno == LOCK_FILE_LINE_SOCKET_DIR)
512-
{
513-
/* strip trailing newline and carriage return */
514-
cluster->sockdir = pg_strdup(line);
515-
(void) pg_strip_crlf(cluster->sockdir);
516-
}
494+
/* strip trailing newline and carriage return */
495+
cluster->sockdir = pg_strdup(line);
496+
(void) pg_strip_crlf(cluster->sockdir);
517497
}
518-
fclose(fp);
519-
520-
/* warn of port number correction */
521-
if (orig_port != DEF_PGUPORT && old_cluster.port != orig_port)
522-
pg_log(PG_WARNING, "user-supplied old port number %hu corrected to %hu\n",
523-
orig_port, cluster->port);
524498
}
525-
}
526-
else
499+
fclose(fp);
527500

528-
/*
529-
* Can't get sockdir and pg_ctl -w can't use a non-default, use
530-
* default
531-
*/
532-
cluster->sockdir = NULL;
501+
/* warn of port number correction */
502+
if (orig_port != DEF_PGUPORT && old_cluster.port != orig_port)
503+
pg_log(PG_WARNING, "user-supplied old port number %hu corrected to %hu\n",
504+
orig_port, cluster->port);
505+
}
533506
#else /* !HAVE_UNIX_SOCKETS || WIN32 */
534507
cluster->sockdir = NULL;
535508
#endif

0 commit comments

Comments
 (0)