1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-23 14:01:44 +03:00

Remove pg_dump/pg_dumpall support for dumping from pre-8.0 servers.

The need for dumping from such ancient servers has decreased to about nil
in the field, so let's remove all the code that catered to it.  Aside
from removing a lot of boilerplate variant queries, this allows us to not
have to cope with servers that don't have (a) schemas or (b) pg_depend.
That means we can get rid of assorted squishy code around that.  There
may be some nonobvious additional simplifications possible, but this patch
already removes about 1500 lines of code.

I did not remove the ability for pg_restore to read custom-format archives
generated by these old versions (and light testing says that that does
still work).  If you have an old server, you probably also have a pg_dump
that will work with it; but you have an old custom-format backup file,
that might be all you have.

It'd be possible at this point to remove fmtQualifiedId()'s version
argument, but I refrained since that would affect code outside pg_dump.

Discussion: <2661.1475849167@sss.pgh.pa.us>
This commit is contained in:
Tom Lane
2016-10-12 12:19:56 -04:00
parent bb55dd6059
commit 64f3524e2c
7 changed files with 232 additions and 1759 deletions

View File

@ -18,8 +18,6 @@
#include "fe_utils/string_utils.h"
#define supports_grant_options(version) ((version) >= 70400)
static bool parseAclItem(const char *item, const char *type,
const char *name, const char *subname, int remoteVersion,
PQExpBuffer grantee, PQExpBuffer grantor,
@ -246,11 +244,9 @@ buildACLCommands(const char *name, const char *subname,
/*
* For the owner, the default privilege level is ALL WITH
* GRANT OPTION (only ALL prior to 7.4).
* GRANT OPTION.
*/
if (supports_grant_options(remoteVersion)
? strcmp(privswgo->data, "ALL") != 0
: strcmp(privs->data, "ALL") != 0)
if (strcmp(privswgo->data, "ALL") != 0)
{
appendPQExpBuffer(firstsql, "%sREVOKE ALL", prefix);
if (subname)
@ -403,16 +399,19 @@ buildDefaultACLCommands(const char *type, const char *nspname,
* username=privilegecodes/grantor
* or
* group groupname=privilegecodes/grantor
* (the /grantor part will not be present if pre-7.4 database).
* (the "group" case occurs only with servers before 8.1).
*
* Returns true on success, false on parse error. On success, the components
* of the string are returned in the PQExpBuffer parameters.
*
* The returned grantee string will be the dequoted username or groupname
* (preceded with "group " in the latter case). The returned grantor is
* the dequoted grantor name or empty. Privilege characters are decoded
* and split between privileges with grant option (privswgo) and without
* (privs).
* (preceded with "group " in the latter case). Note that a grant to PUBLIC
* is represented by an empty grantee string. The returned grantor is the
* dequoted grantor name. Privilege characters are decoded and split between
* privileges with grant option (privswgo) and without (privs).
*
* Note: for cross-version compatibility, it's important to use ALL when
* appropriate.
* Note: for cross-version compatibility, it's important to use ALL to
* represent the privilege sets whenever appropriate.
*/
static bool
parseAclItem(const char *item, const char *type,
@ -439,7 +438,7 @@ parseAclItem(const char *item, const char *type,
return false;
}
/* grantor may be listed after / */
/* grantor should appear after / */
slpos = strchr(eqpos + 1, '/');
if (slpos)
{
@ -452,7 +451,10 @@ parseAclItem(const char *item, const char *type,
}
}
else
resetPQExpBuffer(grantor);
{
free(buf);
return false;
}
/* privilege codes */
#define CONVERT_PRIV(code, keywd) \
@ -490,29 +492,19 @@ do { \
{
/* table only */
CONVERT_PRIV('a', "INSERT");
if (remoteVersion >= 70200)
CONVERT_PRIV('x', "REFERENCES");
CONVERT_PRIV('x', "REFERENCES");
/* rest are not applicable to columns */
if (subname == NULL)
{
if (remoteVersion >= 70200)
{
CONVERT_PRIV('d', "DELETE");
CONVERT_PRIV('t', "TRIGGER");
}
CONVERT_PRIV('d', "DELETE");
CONVERT_PRIV('t', "TRIGGER");
if (remoteVersion >= 80400)
CONVERT_PRIV('D', "TRUNCATE");
}
}
/* UPDATE */
if (remoteVersion >= 70200 ||
strcmp(type, "SEQUENCE") == 0 ||
strcmp(type, "SEQUENCES") == 0)
CONVERT_PRIV('w', "UPDATE");
else
/* 7.0 and 7.1 have a simpler worldview */
CONVERT_PRIV('w', "UPDATE,DELETE");
CONVERT_PRIV('w', "UPDATE");
}
else if (strcmp(type, "FUNCTION") == 0 ||
strcmp(type, "FUNCTIONS") == 0)

View File

@ -388,7 +388,7 @@ RestoreArchive(Archive *AHX)
* target.
*/
AHX->minRemoteVersion = 0;
AHX->maxRemoteVersion = 999999;
AHX->maxRemoteVersion = 9999999;
ConnectDatabase(AHX, ropt->dbname,
ropt->pghost, ropt->pgport, ropt->username,

File diff suppressed because it is too large Load Diff

View File

@ -605,7 +605,6 @@ extern void parseOidArray(const char *str, Oid *array, int arraysize);
extern void sortDumpableObjects(DumpableObject **objs, int numObjs,
DumpId preBoundaryId, DumpId postBoundaryId);
extern void sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs);
extern void sortDumpableObjectsByTypeOid(DumpableObject **objs, int numObjs);
extern void sortDataAndIndexObjectsBySize(DumpableObject **objs, int numObjs);
/*

View File

@ -23,63 +23,7 @@
static const char *modulename = gettext_noop("sorter");
/*
* Sort priority for object types when dumping a pre-7.3 database.
* Objects are sorted by priority levels, and within an equal priority level
* by OID. (This is a relatively crude hack to provide semi-reasonable
* behavior for old databases without full dependency info.) Note: collations,
* extensions, text search, foreign-data, materialized view, event trigger,
* policies, transforms, access methods and default ACL objects can't really
* happen here, so the rather bogus priorities for them don't matter.
*
* NOTE: object-type priorities must match the section assignments made in
* pg_dump.c; that is, PRE_DATA objects must sort before DO_PRE_DATA_BOUNDARY,
* POST_DATA objects must sort after DO_POST_DATA_BOUNDARY, and DATA objects
* must sort between them.
*/
static const int oldObjectTypePriority[] =
{
1, /* DO_NAMESPACE */
1, /* DO_EXTENSION */
2, /* DO_TYPE */
2, /* DO_SHELL_TYPE */
2, /* DO_FUNC */
3, /* DO_AGG */
3, /* DO_OPERATOR */
3, /* DO_ACCESS_METHOD */
4, /* DO_OPCLASS */
4, /* DO_OPFAMILY */
4, /* DO_COLLATION */
5, /* DO_CONVERSION */
6, /* DO_TABLE */
8, /* DO_ATTRDEF */
15, /* DO_INDEX */
16, /* DO_RULE */
17, /* DO_TRIGGER */
14, /* DO_CONSTRAINT */
18, /* DO_FK_CONSTRAINT */
2, /* DO_PROCLANG */
2, /* DO_CAST */
11, /* DO_TABLE_DATA */
7, /* DO_DUMMY_TYPE */
4, /* DO_TSPARSER */
4, /* DO_TSDICT */
4, /* DO_TSTEMPLATE */
4, /* DO_TSCONFIG */
4, /* DO_FDW */
4, /* DO_FOREIGN_SERVER */
19, /* DO_DEFAULT_ACL */
4, /* DO_TRANSFORM */
9, /* DO_BLOB */
12, /* DO_BLOB_DATA */
10, /* DO_PRE_DATA_BOUNDARY */
13, /* DO_POST_DATA_BOUNDARY */
20, /* DO_EVENT_TRIGGER */
15, /* DO_REFRESH_MATVIEW */
21 /* DO_POLICY */
};
/*
* Sort priority for object types when dumping newer databases.
* Sort priority for database object types.
* Objects are sorted by type, and within a type by name.
*
* NOTE: object-type priorities must match the section assignments made in
@ -87,7 +31,7 @@ static const int oldObjectTypePriority[] =
* POST_DATA objects must sort after DO_POST_DATA_BOUNDARY, and DATA objects
* must sort between them.
*/
static const int newObjectTypePriority[] =
static const int dbObjectTypePriority[] =
{
1, /* DO_NAMESPACE */
4, /* DO_EXTENSION */
@ -134,7 +78,6 @@ static DumpId postDataBoundId;
static int DOTypeNameCompare(const void *p1, const void *p2);
static int DOTypeOidCompare(const void *p1, const void *p2);
static bool TopoSort(DumpableObject **objs,
int numObjs,
DumpableObject **ordering,
@ -266,8 +209,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
int cmpval;
/* Sort by type */
cmpval = newObjectTypePriority[obj1->objType] -
newObjectTypePriority[obj2->objType];
cmpval = dbObjectTypePriority[obj1->objType] -
dbObjectTypePriority[obj2->objType];
if (cmpval != 0)
return cmpval;
@ -345,37 +288,6 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
/*
* Sort the given objects into a type/OID-based ordering
*
* This is used with pre-7.3 source databases as a crude substitute for the
* lack of dependency information.
*/
void
sortDumpableObjectsByTypeOid(DumpableObject **objs, int numObjs)
{
if (numObjs > 1)
qsort((void *) objs, numObjs, sizeof(DumpableObject *),
DOTypeOidCompare);
}
static int
DOTypeOidCompare(const void *p1, const void *p2)
{
DumpableObject *obj1 = *(DumpableObject *const *) p1;
DumpableObject *obj2 = *(DumpableObject *const *) p2;
int cmpval;
cmpval = oldObjectTypePriority[obj1->objType] -
oldObjectTypePriority[obj2->objType];
if (cmpval != 0)
return cmpval;
return oidcmp(obj1->catId.oid, obj2->catId.oid);
}
/*
* Sort the given objects into a safe dump order using dependency
* information (to the extent we have it available).

View File

@ -480,10 +480,7 @@ main(int argc, char *argv[])
dropDBs(conn);
if (!roles_only && !no_tablespaces)
{
if (server_version >= 80000)
dropTablespaces(conn);
}
dropTablespaces(conn);
if (!tablespaces_only)
dropRoles(conn);
@ -505,12 +502,9 @@ main(int argc, char *argv[])
dumpGroups(conn);
}
/* Dump tablespaces */
if (!roles_only && !no_tablespaces)
{
/* Dump tablespaces */
if (server_version >= 80000)
dumpTablespaces(conn);
}
dumpTablespaces(conn);
/* Dump CREATE DATABASE commands */
if (binary_upgrade || (!globals_only && !roles_only && !tablespaces_only))
@ -886,9 +880,8 @@ dumpRoles(PGconn *conn)
* We do it this way because config settings for roles could mention the
* names of other roles.
*/
if (server_version >= 70300)
for (i = 0; i < PQntuples(res); i++)
dumpUserConfig(conn, PQgetvalue(res, i, i_rolname));
for (i = 0; i < PQntuples(res); i++)
dumpUserConfig(conn, PQgetvalue(res, i, i_rolname));
PQclear(res);
@ -1204,16 +1197,10 @@ dropDBs(PGconn *conn)
PGresult *res;
int i;
if (server_version >= 70100)
res = executeQuery(conn,
"SELECT datname "
"FROM pg_database d "
"WHERE datallowconn ORDER BY 1");
else
res = executeQuery(conn,
"SELECT datname "
"FROM pg_database d "
"ORDER BY 1");
res = executeQuery(conn,
"SELECT datname "
"FROM pg_database d "
"WHERE datallowconn ORDER BY 1");
if (PQntuples(res) > 0)
fprintf(OPF, "--\n-- Drop databases\n--\n\n");
@ -1269,12 +1256,10 @@ dumpCreateDB(PGconn *conn)
* We will dump encoding and locale specifications in the CREATE DATABASE
* commands for just those databases with values different from defaults.
*
* We consider template0's encoding and locale (or, pre-7.1, template1's)
* to define the installation default. Pre-8.4 installations do not have
* per-database locale settings; for them, every database must necessarily
* be using the installation default, so there's no need to do anything
* (which is good, since in very old versions there is no good way to find
* out what the installation locale is anyway...)
* We consider template0's encoding and locale to define the installation
* default. Pre-8.4 installations do not have per-database locale
* settings; for them, every database must necessarily be using the
* installation default, so there's no need to do anything.
*/
if (server_version >= 80400)
res = executeQuery(conn,
@ -1282,18 +1267,12 @@ dumpCreateDB(PGconn *conn)
"datcollate, datctype "
"FROM pg_database "
"WHERE datname = 'template0'");
else if (server_version >= 70100)
res = executeQuery(conn,
"SELECT pg_encoding_to_char(encoding), "
"null::text AS datcollate, null::text AS datctype "
"FROM pg_database "
"WHERE datname = 'template0'");
else
res = executeQuery(conn,
"SELECT pg_encoding_to_char(encoding), "
"null::text AS datcollate, null::text AS datctype "
"FROM pg_database "
"WHERE datname = 'template1'");
"WHERE datname = 'template0'");
/* If for some reason the template DB isn't there, treat as unknown */
if (PQntuples(res) > 0)
@ -1371,7 +1350,7 @@ dumpCreateDB(PGconn *conn)
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace "
"FROM pg_database d LEFT JOIN pg_authid u ON (datdba = u.oid) "
"WHERE datallowconn ORDER BY 1");
else if (server_version >= 80000)
else
res = executeQuery(conn,
"SELECT datname, "
"coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), "
@ -1382,47 +1361,6 @@ dumpCreateDB(PGconn *conn)
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace "
"FROM pg_database d LEFT JOIN pg_shadow u ON (datdba = usesysid) "
"WHERE datallowconn ORDER BY 1");
else if (server_version >= 70300)
res = executeQuery(conn,
"SELECT datname, "
"coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), "
"pg_encoding_to_char(d.encoding), "
"null::text AS datcollate, null::text AS datctype, datfrozenxid, 0 AS datminmxid, "
"datistemplate, datacl, '' as rdatacl, "
"-1 as datconnlimit, "
"'pg_default' AS dattablespace "
"FROM pg_database d LEFT JOIN pg_shadow u ON (datdba = usesysid) "
"WHERE datallowconn ORDER BY 1");
else if (server_version >= 70100)
res = executeQuery(conn,
"SELECT datname, "
"coalesce("
"(select usename from pg_shadow where usesysid=datdba), "
"(select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), "
"pg_encoding_to_char(d.encoding), "
"null::text AS datcollate, null::text AS datctype, 0 AS datfrozenxid, 0 AS datminmxid, "
"datistemplate, '' as datacl, '' as rdatacl, "
"-1 as datconnlimit, "
"'pg_default' AS dattablespace "
"FROM pg_database d "
"WHERE datallowconn ORDER BY 1");
else
{
/*
* Note: 7.0 fails to cope with sub-select in COALESCE, so just deal
* with getting a NULL by not printing any OWNER clause.
*/
res = executeQuery(conn,
"SELECT datname, "
"(select usename from pg_shadow where usesysid=datdba), "
"pg_encoding_to_char(d.encoding), "
"null::text AS datcollate, null::text AS datctype, 0 AS datfrozenxid, 0 AS datminmxid, "
"'f' as datistemplate, "
"'' as datacl, '' as rdatacl, -1 as datconnlimit, "
"'pg_default' AS dattablespace "
"FROM pg_database d "
"ORDER BY 1");
}
for (i = 0; i < PQntuples(res); i++)
{
@ -1541,8 +1479,7 @@ dumpCreateDB(PGconn *conn)
fprintf(OPF, "%s", buf->data);
if (server_version >= 70300)
dumpDatabaseConfig(conn, dbname);
dumpDatabaseConfig(conn, dbname);
free(fdbname);
}
@ -1738,10 +1675,7 @@ dumpDatabases(PGconn *conn)
PGresult *res;
int i;
if (server_version >= 70100)
res = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1");
else
res = executeQuery(conn, "SELECT datname FROM pg_database ORDER BY 1");
res = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1");
for (i = 0; i < PQntuples(res); i++)
{
@ -2062,11 +1996,11 @@ connectDatabase(const char *dbname, const char *connection_string,
my_version = PG_VERSION_NUM;
/*
* We allow the server to be back to 7.0, and up to any minor release of
* We allow the server to be back to 8.0, and up to any minor release of
* our own major version. (See also version check in pg_dump.c.)
*/
if (my_version != server_version
&& (server_version < 70000 ||
&& (server_version < 80000 ||
(server_version / 100) > (my_version / 100)))
{
fprintf(stderr, _("server version: %s; %s version: %s\n"),
@ -2076,11 +2010,9 @@ connectDatabase(const char *dbname, const char *connection_string,
}
/*
* On 7.3 and later, make sure we are not fooled by non-system schemas in
* the search path.
* Make sure we are not fooled by non-system schemas in the search path.
*/
if (server_version >= 70300)
executeCommand(conn, "SET search_path = pg_catalog");
executeCommand(conn, "SET search_path = pg_catalog");
return conn;
}