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

Commit3bdd7f9

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 parent8ea3e7a commit3bdd7f9

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
@@ -158,6 +158,7 @@ static void dumpType(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo);
158158
staticvoiddumpBaseType(Archive*fout,DumpOptions*dopt,TypeInfo*tyinfo);
159159
staticvoiddumpEnumType(Archive*fout,DumpOptions*dopt,TypeInfo*tyinfo);
160160
staticvoiddumpRangeType(Archive*fout,DumpOptions*dopt,TypeInfo*tyinfo);
161+
staticvoiddumpUndefinedType(Archive*fout,DumpOptions*dopt,TypeInfo*tyinfo);
161162
staticvoiddumpDomain(Archive*fout,DumpOptions*dopt,TypeInfo*tyinfo);
162163
staticvoiddumpCompositeType(Archive*fout,DumpOptions*dopt,TypeInfo*tyinfo);
163164
staticvoiddumpCompositeTypeColComments(Archive*fout,TypeInfo*tyinfo);
@@ -1329,11 +1330,6 @@ selectDumpableType(TypeInfo *tyinfo)
13291330
/* dump only types in dumpable namespaces */
13301331
if (!tyinfo->dobj.namespace->dobj.dump)
13311332
tyinfo->dobj.dump= false;
1332-
1333-
/* skip undefined placeholder types */
1334-
elseif (!tyinfo->isDefined)
1335-
tyinfo->dobj.dump= false;
1336-
13371333
else
13381334
tyinfo->dobj.dump= true;
13391335
}
@@ -3707,7 +3703,7 @@ getTypes(Archive *fout, int *numTypes)
37073703
}
37083704
}
37093705

3710-
if (strlen(tyinfo[i].rolname)==0&&tyinfo[i].isDefined)
3706+
if (strlen(tyinfo[i].rolname)==0)
37113707
write_msg(NULL,"WARNING: owner of data type \"%s\" appears to be invalid\n",
37123708
tyinfo[i].dobj.name);
37133709
}
@@ -8554,6 +8550,8 @@ dumpType(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo)
85548550
dumpEnumType(fout,dopt,tyinfo);
85558551
elseif (tyinfo->typtype==TYPTYPE_RANGE)
85568552
dumpRangeType(fout,dopt,tyinfo);
8553+
elseif (tyinfo->typtype==TYPTYPE_PSEUDO&& !tyinfo->isDefined)
8554+
dumpUndefinedType(fout,dopt,tyinfo);
85578555
else
85588556
write_msg(NULL,"WARNING: typtype of data type \"%s\" appears to be invalid\n",
85598557
tyinfo->dobj.name);
@@ -8820,6 +8818,73 @@ dumpRangeType(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo)
88208818
destroyPQExpBuffer(query);
88218819
}
88228820

8821+
/*
8822+
* dumpUndefinedType
8823+
* writes out to fout the queries to recreate a !typisdefined type
8824+
*
8825+
* This is a shell type, but we use different terminology to distinguish
8826+
* this case from where we have to emit a shell type definition to break
8827+
* circular dependencies. An undefined type shouldn't ever have anything
8828+
* depending on it.
8829+
*/
8830+
staticvoid
8831+
dumpUndefinedType(Archive*fout,DumpOptions*dopt,TypeInfo*tyinfo)
8832+
{
8833+
PQExpBufferq=createPQExpBuffer();
8834+
PQExpBufferdelq=createPQExpBuffer();
8835+
PQExpBufferlabelq=createPQExpBuffer();
8836+
char*qtypname;
8837+
8838+
qtypname=pg_strdup(fmtId(tyinfo->dobj.name));
8839+
8840+
/*
8841+
* DROP must be fully qualified in case same name appears in pg_catalog.
8842+
*/
8843+
appendPQExpBuffer(delq,"DROP TYPE %s.",
8844+
fmtId(tyinfo->dobj.namespace->dobj.name));
8845+
appendPQExpBuffer(delq,"%s;\n",
8846+
qtypname);
8847+
8848+
if (dopt->binary_upgrade)
8849+
binary_upgrade_set_type_oids_by_type_oid(fout,
8850+
q,tyinfo->dobj.catId.oid);
8851+
8852+
appendPQExpBuffer(q,"CREATE TYPE %s;\n",
8853+
qtypname);
8854+
8855+
appendPQExpBuffer(labelq,"TYPE %s",qtypname);
8856+
8857+
if (dopt->binary_upgrade)
8858+
binary_upgrade_extension_member(q,&tyinfo->dobj,labelq->data);
8859+
8860+
ArchiveEntry(fout,tyinfo->dobj.catId,tyinfo->dobj.dumpId,
8861+
tyinfo->dobj.name,
8862+
tyinfo->dobj.namespace->dobj.name,
8863+
NULL,
8864+
tyinfo->rolname, false,
8865+
"TYPE",SECTION_PRE_DATA,
8866+
q->data,delq->data,NULL,
8867+
NULL,0,
8868+
NULL,NULL);
8869+
8870+
/* Dump Type Comments and Security Labels */
8871+
dumpComment(fout,dopt,labelq->data,
8872+
tyinfo->dobj.namespace->dobj.name,tyinfo->rolname,
8873+
tyinfo->dobj.catId,0,tyinfo->dobj.dumpId);
8874+
dumpSecLabel(fout,dopt,labelq->data,
8875+
tyinfo->dobj.namespace->dobj.name,tyinfo->rolname,
8876+
tyinfo->dobj.catId,0,tyinfo->dobj.dumpId);
8877+
8878+
dumpACL(fout,dopt,tyinfo->dobj.catId,tyinfo->dobj.dumpId,"TYPE",
8879+
qtypname,NULL,tyinfo->dobj.name,
8880+
tyinfo->dobj.namespace->dobj.name,
8881+
tyinfo->rolname,tyinfo->typacl);
8882+
8883+
destroyPQExpBuffer(q);
8884+
destroyPQExpBuffer(delq);
8885+
destroyPQExpBuffer(labelq);
8886+
}
8887+
88238888
/*
88248889
* dumpBaseType
88258890
* 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
@@ -127,7 +127,7 @@ typedef struct _typeInfo
127127
chartyptype;/* 'b', 'c', etc */
128128
boolisArray;/* true if auto-generated array type */
129129
boolisDefined;/* true if typisdefined */
130-
/* Ifit's a dumpable base type, we create a "shell type" entry for it */
130+
/* Ifneeded, we'll create a "shell type" entry for it; link that here: */
131131
struct_shellTypeInfo*shellType;/* shell-type entry, or NULL */
132132
/* If it's a domain, we store links to its constraints here: */
133133
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