Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfa6e785

Browse files
committed
Fix pg_dump to dump shell types.
Per discussion, it really ought to do this. The original choice toexclude shell types was probably made in the dark ages before we madeit harder to accidentally create shell types; but that was in 7.3.Also, cause the standard regression tests to leave a shell type behind,for convenience in testing the case in pg_dump and pg_upgrade.Back-patch to all supported branches.
1 parent118c9bb commitfa6e785

File tree

4 files changed

+77
-7
lines changed

4 files changed

+77
-7
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ static void dumpType(Archive *fout, TypeInfo *tyinfo);
172172
staticvoiddumpBaseType(Archive*fout,TypeInfo*tyinfo);
173173
staticvoiddumpEnumType(Archive*fout,TypeInfo*tyinfo);
174174
staticvoiddumpRangeType(Archive*fout,TypeInfo*tyinfo);
175+
staticvoiddumpUndefinedType(Archive*fout,TypeInfo*tyinfo);
175176
staticvoiddumpDomain(Archive*fout,TypeInfo*tyinfo);
176177
staticvoiddumpCompositeType(Archive*fout,TypeInfo*tyinfo);
177178
staticvoiddumpCompositeTypeColComments(Archive*fout,TypeInfo*tyinfo);
@@ -1321,11 +1322,6 @@ selectDumpableType(TypeInfo *tyinfo)
13211322
/* dump only types in dumpable namespaces */
13221323
if (!tyinfo->dobj.namespace->dobj.dump)
13231324
tyinfo->dobj.dump= false;
1324-
1325-
/* skip undefined placeholder types */
1326-
elseif (!tyinfo->isDefined)
1327-
tyinfo->dobj.dump= false;
1328-
13291325
else
13301326
tyinfo->dobj.dump= true;
13311327
}
@@ -3462,7 +3458,7 @@ getTypes(Archive *fout, int *numTypes)
34623458
}
34633459
}
34643460

3465-
if (strlen(tyinfo[i].rolname)==0&&tyinfo[i].isDefined)
3461+
if (strlen(tyinfo[i].rolname)==0)
34663462
write_msg(NULL,"WARNING: owner of data type \"%s\" appears to be invalid\n",
34673463
tyinfo[i].dobj.name);
34683464
}
@@ -8135,6 +8131,8 @@ dumpType(Archive *fout, TypeInfo *tyinfo)
81358131
dumpEnumType(fout,tyinfo);
81368132
elseif (tyinfo->typtype==TYPTYPE_RANGE)
81378133
dumpRangeType(fout,tyinfo);
8134+
elseif (tyinfo->typtype==TYPTYPE_PSEUDO&& !tyinfo->isDefined)
8135+
dumpUndefinedType(fout,tyinfo);
81388136
else
81398137
write_msg(NULL,"WARNING: typtype of data type \"%s\" appears to be invalid\n",
81408138
tyinfo->dobj.name);
@@ -8401,6 +8399,73 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
84018399
destroyPQExpBuffer(query);
84028400
}
84038401

8402+
/*
8403+
* dumpUndefinedType
8404+
* writes out to fout the queries to recreate a !typisdefined type
8405+
*
8406+
* This is a shell type, but we use different terminology to distinguish
8407+
* this case from where we have to emit a shell type definition to break
8408+
* circular dependencies. An undefined type shouldn't ever have anything
8409+
* depending on it.
8410+
*/
8411+
staticvoid
8412+
dumpUndefinedType(Archive*fout,TypeInfo*tyinfo)
8413+
{
8414+
PQExpBufferq=createPQExpBuffer();
8415+
PQExpBufferdelq=createPQExpBuffer();
8416+
PQExpBufferlabelq=createPQExpBuffer();
8417+
char*qtypname;
8418+
8419+
qtypname=pg_strdup(fmtId(tyinfo->dobj.name));
8420+
8421+
/*
8422+
* DROP must be fully qualified in case same name appears in pg_catalog.
8423+
*/
8424+
appendPQExpBuffer(delq,"DROP TYPE %s.",
8425+
fmtId(tyinfo->dobj.namespace->dobj.name));
8426+
appendPQExpBuffer(delq,"%s;\n",
8427+
qtypname);
8428+
8429+
if (binary_upgrade)
8430+
binary_upgrade_set_type_oids_by_type_oid(fout,
8431+
q,tyinfo->dobj.catId.oid);
8432+
8433+
appendPQExpBuffer(q,"CREATE TYPE %s;\n",
8434+
qtypname);
8435+
8436+
appendPQExpBuffer(labelq,"TYPE %s",qtypname);
8437+
8438+
if (binary_upgrade)
8439+
binary_upgrade_extension_member(q,&tyinfo->dobj,labelq->data);
8440+
8441+
ArchiveEntry(fout,tyinfo->dobj.catId,tyinfo->dobj.dumpId,
8442+
tyinfo->dobj.name,
8443+
tyinfo->dobj.namespace->dobj.name,
8444+
NULL,
8445+
tyinfo->rolname, false,
8446+
"TYPE",SECTION_PRE_DATA,
8447+
q->data,delq->data,NULL,
8448+
NULL,0,
8449+
NULL,NULL);
8450+
8451+
/* Dump Type Comments and Security Labels */
8452+
dumpComment(fout,labelq->data,
8453+
tyinfo->dobj.namespace->dobj.name,tyinfo->rolname,
8454+
tyinfo->dobj.catId,0,tyinfo->dobj.dumpId);
8455+
dumpSecLabel(fout,labelq->data,
8456+
tyinfo->dobj.namespace->dobj.name,tyinfo->rolname,
8457+
tyinfo->dobj.catId,0,tyinfo->dobj.dumpId);
8458+
8459+
dumpACL(fout,tyinfo->dobj.catId,tyinfo->dobj.dumpId,"TYPE",
8460+
qtypname,NULL,tyinfo->dobj.name,
8461+
tyinfo->dobj.namespace->dobj.name,
8462+
tyinfo->rolname,tyinfo->typacl);
8463+
8464+
destroyPQExpBuffer(q);
8465+
destroyPQExpBuffer(delq);
8466+
destroyPQExpBuffer(labelq);
8467+
}
8468+
84048469
/*
84058470
* dumpBaseType
84068471
* writes out to fout the queries to recreate a user-defined base type

‎src/bin/pg_dump/pg_dump.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ typedef struct _typeInfo
161161
chartyptype;/* 'b', 'c', etc */
162162
boolisArray;/* true if auto-generated array type */
163163
boolisDefined;/* true if typisdefined */
164-
/* Ifit's a dumpable base type, we create a "shell type" entry for it */
164+
/* Ifneeded, we'll create a "shell type" entry for it; link that here: */
165165
struct_shellTypeInfo*shellType;/* shell-type entry, or NULL */
166166
/* If it's a domain, we store links to its constraints here: */
167167
intnDomChecks;

‎src/test/regress/expected/create_type.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ ERROR: type "shell" already exists
2929
DROP TYPE shell;
3030
DROP TYPE shell; -- fail, type not exist
3131
ERROR: type "shell" does not exist
32+
-- also, let's leave one around for purposes of pg_dump testing
33+
CREATE TYPE myshell;
3234
--
3335
-- Test type-related default values (broken in releases before PG 7.2)
3436
--

‎src/test/regress/sql/create_type.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ CREATE TYPE shell; -- fail, type already present
3131
DROPTYPE shell;
3232
DROPTYPE shell;-- fail, type not exist
3333

34+
-- also, let's leave one around for purposes of pg_dump testing
35+
CREATETYPEmyshell;
36+
3437
--
3538
-- Test type-related default values (broken in releases before PG 7.2)
3639
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp