mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-28 11:55:03 +03:00 
			
		
		
		
	For 8.0 servers, get last built-in oid from pg_database
We didn't start ensuring that all built-in objects had OIDs less than 16384 until 8.1, so for 8.0 servers we still need to query the value out of pg_database. We need this, in particular, to distinguish which casts were built-in and which were user-defined. For HEAD, we only worry about going back to 8.0, for the back-branches, we also ensure that 7.0-7.4 work. Discussion: https://www.postgresql.org/message-id/flat/20160504183952.GE10850%40tamriel.snowman.net
This commit is contained in:
		| @@ -96,7 +96,10 @@ bool		g_verbose;			/* User wants verbose narration of our | |||||||
| /* subquery used to convert user ID (eg, datdba) to user name */ | /* subquery used to convert user ID (eg, datdba) to user name */ | ||||||
| static const char *username_subquery; | static const char *username_subquery; | ||||||
|  |  | ||||||
| /* obsolete as of 7.3: */ | /* | ||||||
|  |  * For 8.0 and earlier servers, pulled from pg_database, for 8.1+ we use | ||||||
|  |  * FirstNormalObjectId - 1. | ||||||
|  |  */ | ||||||
| static Oid	g_last_builtin_oid; /* value of the last builtin oid */ | static Oid	g_last_builtin_oid; /* value of the last builtin oid */ | ||||||
|  |  | ||||||
| /* The specified names/patterns should to match at least one entity */ | /* The specified names/patterns should to match at least one entity */ | ||||||
| @@ -683,17 +686,24 @@ main(int argc, char **argv) | |||||||
| 		exit_horribly(NULL, | 		exit_horribly(NULL, | ||||||
| 		   "Exported snapshots are not supported by this server version.\n"); | 		   "Exported snapshots are not supported by this server version.\n"); | ||||||
|  |  | ||||||
| 	/* Find the last built-in OID, if needed */ | 	/* | ||||||
| 	if (fout->remoteVersion < 70300) | 	 * Find the last built-in OID, if needed (prior to 8.1) | ||||||
|  | 	 * | ||||||
|  | 	 * With 8.1 and above, we can just use FirstNormalObjectId - 1. | ||||||
|  | 	 */ | ||||||
|  | 	if (fout->remoteVersion < 80100) | ||||||
| 	{ | 	{ | ||||||
| 		if (fout->remoteVersion >= 70100) | 		if (fout->remoteVersion >= 70100) | ||||||
| 			g_last_builtin_oid = findLastBuiltinOid_V71(fout, | 			g_last_builtin_oid = findLastBuiltinOid_V71(fout, | ||||||
| 												  PQdb(GetConnection(fout))); | 												  PQdb(GetConnection(fout))); | ||||||
| 		else | 		else | ||||||
| 			g_last_builtin_oid = findLastBuiltinOid_V70(fout); | 			g_last_builtin_oid = findLastBuiltinOid_V70(fout); | ||||||
| 		if (g_verbose) |  | ||||||
| 			write_msg(NULL, "last built-in OID is %u\n", g_last_builtin_oid); |  | ||||||
| 	} | 	} | ||||||
|  | 	else | ||||||
|  | 		g_last_builtin_oid = FirstNormalObjectId - 1; | ||||||
|  |  | ||||||
|  | 	if (g_verbose) | ||||||
|  | 		write_msg(NULL, "last built-in OID is %u\n", g_last_builtin_oid); | ||||||
|  |  | ||||||
| 	/* Expand schema selection patterns into OID lists */ | 	/* Expand schema selection patterns into OID lists */ | ||||||
| 	if (schema_include_patterns.head != NULL) | 	if (schema_include_patterns.head != NULL) | ||||||
| @@ -1507,7 +1517,7 @@ selectDumpableCast(CastInfo *cast, Archive *fout) | |||||||
| 	 * This would be DUMP_COMPONENT_ACL for from-initdb casts, but they do not | 	 * This would be DUMP_COMPONENT_ACL for from-initdb casts, but they do not | ||||||
| 	 * support ACLs currently. | 	 * support ACLs currently. | ||||||
| 	 */ | 	 */ | ||||||
| 	if (cast->dobj.catId.oid < (Oid) FirstNormalObjectId) | 	if (cast->dobj.catId.oid <= (Oid) g_last_builtin_oid) | ||||||
| 		cast->dobj.dump = DUMP_COMPONENT_NONE; | 		cast->dobj.dump = DUMP_COMPONENT_NONE; | ||||||
| 	else | 	else | ||||||
| 		cast->dobj.dump = fout->dopt->include_everything ? | 		cast->dobj.dump = fout->dopt->include_everything ? | ||||||
| @@ -1539,7 +1549,7 @@ selectDumpableProcLang(ProcLangInfo *plang, Archive *fout) | |||||||
| 		plang->dobj.dump = DUMP_COMPONENT_NONE; | 		plang->dobj.dump = DUMP_COMPONENT_NONE; | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		if (plang->dobj.catId.oid < (Oid) FirstNormalObjectId) | 		if (plang->dobj.catId.oid <= (Oid) g_last_builtin_oid) | ||||||
| 			plang->dobj.dump = fout->remoteVersion < 90600 ? | 			plang->dobj.dump = fout->remoteVersion < 90600 ? | ||||||
| 				DUMP_COMPONENT_NONE : DUMP_COMPONENT_ACL; | 				DUMP_COMPONENT_NONE : DUMP_COMPONENT_ACL; | ||||||
| 		else | 		else | ||||||
| @@ -1565,7 +1575,7 @@ selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout) | |||||||
| 	 * This would be DUMP_COMPONENT_ACL for from-initdb access methods, but | 	 * This would be DUMP_COMPONENT_ACL for from-initdb access methods, but | ||||||
| 	 * they do not support ACLs currently. | 	 * they do not support ACLs currently. | ||||||
| 	 */ | 	 */ | ||||||
| 	if (method->dobj.catId.oid < (Oid) FirstNormalObjectId) | 	if (method->dobj.catId.oid <= (Oid) g_last_builtin_oid) | ||||||
| 		method->dobj.dump = DUMP_COMPONENT_NONE; | 		method->dobj.dump = DUMP_COMPONENT_NONE; | ||||||
| 	else | 	else | ||||||
| 		method->dobj.dump = fout->dopt->include_everything ? | 		method->dobj.dump = fout->dopt->include_everything ? | ||||||
| @@ -1590,7 +1600,7 @@ selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt) | |||||||
| 	 * change permissions on those objects, if they wish to, and have those | 	 * change permissions on those objects, if they wish to, and have those | ||||||
| 	 * changes preserved. | 	 * changes preserved. | ||||||
| 	 */ | 	 */ | ||||||
| 	if (dopt->binary_upgrade && extinfo->dobj.catId.oid < (Oid) FirstNormalObjectId) | 	if (dopt->binary_upgrade && extinfo->dobj.catId.oid <= (Oid) g_last_builtin_oid) | ||||||
| 		extinfo->dobj.dump = extinfo->dobj.dump_contains = DUMP_COMPONENT_ACL; | 		extinfo->dobj.dump = extinfo->dobj.dump_contains = DUMP_COMPONENT_ACL; | ||||||
| 	else | 	else | ||||||
| 		extinfo->dobj.dump = extinfo->dobj.dump_contains = | 		extinfo->dobj.dump = extinfo->dobj.dump_contains = | ||||||
| @@ -9571,8 +9581,8 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo) | |||||||
| 		/* | 		/* | ||||||
| 		 * We unconditionally create the extension, so we must drop it if it | 		 * We unconditionally create the extension, so we must drop it if it | ||||||
| 		 * exists.  This could happen if the user deleted 'plpgsql' and then | 		 * exists.  This could happen if the user deleted 'plpgsql' and then | ||||||
| 		 * readded it, causing its oid to be greater than FirstNormalObjectId. | 		 * readded it, causing its oid to be greater than g_last_builtin_oid. | ||||||
| 		 * The FirstNormalObjectId test was kept to avoid repeatedly dropping | 		 * The g_last_builtin_oid test was kept to avoid repeatedly dropping | ||||||
| 		 * and recreating extensions like 'plpgsql'. | 		 * and recreating extensions like 'plpgsql'. | ||||||
| 		 */ | 		 */ | ||||||
| 		appendPQExpBuffer(q, "DROP EXTENSION IF EXISTS %s;\n", qextname); | 		appendPQExpBuffer(q, "DROP EXTENSION IF EXISTS %s;\n", qextname); | ||||||
| @@ -16284,10 +16294,10 @@ dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo) | |||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * findLastBuiltInOid - |  * findLastBuiltinOid - | ||||||
|  * find the last built in oid |  * find the last built in oid | ||||||
|  * |  * | ||||||
|  * For 7.1 and 7.2, we do this by retrieving datlastsysoid from the |  * For 7.1 through 8.0, we do this by retrieving datlastsysoid from the | ||||||
|  * pg_database entry for the current database |  * pg_database entry for the current database | ||||||
|  */ |  */ | ||||||
| static Oid | static Oid | ||||||
| @@ -16309,7 +16319,7 @@ findLastBuiltinOid_V71(Archive *fout, const char *dbname) | |||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * findLastBuiltInOid - |  * findLastBuiltinOid - | ||||||
|  * find the last built in oid |  * find the last built in oid | ||||||
|  * |  * | ||||||
|  * For 7.0, we do this by assuming that the last thing that initdb does is to |  * For 7.0, we do this by assuming that the last thing that initdb does is to | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user