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

Commit92880ff

Browse files
committed
Revert "Make pg_dump emit ATTACH PARTITION instead of PARTITION OF"
... and fallout (from branches 10, 11 and master). The change wasill-considered, and it broke a few normal use cases; since we don't havetime to fix it, we'll try again after this week's minor releases.Reported-by: Rushabh LathiaDiscussion:https://postgr.es/m/CAGPqQf0iQV=PPOv2Btog9J9AwOQp6HmuVd6SbGTR_v3Zp2XT1w@mail.gmail.com
1 parentdcbdd1a commit92880ff

File tree

3 files changed

+75
-83
lines changed

3 files changed

+75
-83
lines changed

‎doc/src/sgml/release-11.sgml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,29 +1053,6 @@ Branch: REL9_4_STABLE [12c42a543] 2019-04-11 21:06:21 +0200
10531053

10541054
<listitem>
10551055
<!--
1056-
Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
1057-
Branch: master [3b23552ad] 2019-04-24 15:30:37 -0400
1058-
Branch: REL_11_STABLE [a98c48deb] 2019-04-24 15:30:37 -0400
1059-
Branch: REL_10_STABLE [5a191f697] 2019-04-24 15:30:37 -0400
1060-
-->
1061-
<para>
1062-
Make <application>pg_dump</application> recreate table partitions
1063-
using <command>ATTACH PARTITION</command> instead
1064-
of <command>CREATE TABLE ... PARTITION OF</command> (David Rowley)
1065-
</para>
1066-
1067-
<para>
1068-
This avoids various corner-case problems, notably that dump and
1069-
restore might unexpectedly alter a partition's column ordering.
1070-
It also means that a selective restore of the partition can succeed
1071-
even if its parent partitioned table isn't restored.
1072-
(The <command>ATTACH PARTITION</command> will fail of course, but
1073-
the partition table itself can be created and populated.)
1074-
</para>
1075-
</listitem>
1076-
1077-
<listitem>
1078-
<!--
10791056
Author: Michael Paquier <michael@paquier.xyz>
10801057
Branch: master [a7eadaaaa] 2019-03-18 10:34:45 +0900
10811058
Branch: REL_11_STABLE [dcf2a0db8] 2019-03-18 10:35:01 +0900

‎src/bin/pg_dump/pg_dump.c

Lines changed: 72 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8617,12 +8617,9 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
86178617
* Normally this is always true, but it's false for dropped columns, as well
86188618
* as those that were inherited without any local definition. (If we print
86198619
* such a column it will mistakenly get pg_attribute.attislocal set to true.)
8620-
* For partitions, it's always true, because we want the partitions to be
8621-
* created independently and ATTACH PARTITION used afterwards.
8622-
*
8623-
* In binary_upgrade mode, we must print all columns and fix the attislocal/
8624-
* attisdropped state later, so as to keep control of the physical column
8625-
* order.
8620+
* However, in binary_upgrade mode, we must print all such columns anyway and
8621+
* fix the attislocal/attisdropped state later, so as to keep control of the
8622+
* physical column order.
86268623
*
86278624
* This function exists because there are scattered nonobvious places that
86288625
* must be kept in sync with this decision.
@@ -8632,9 +8629,7 @@ shouldPrintColumn(DumpOptions *dopt, TableInfo *tbinfo, int colno)
86328629
{
86338630
if (dopt->binary_upgrade)
86348631
return true;
8635-
if (tbinfo->attisdropped[colno])
8636-
return false;
8637-
return (tbinfo->attislocal[colno] || tbinfo->ispartition);
8632+
return (tbinfo->attislocal[colno] && !tbinfo->attisdropped[colno]);
86388633
}
86398634

86408635

@@ -15543,6 +15538,27 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1554315538
if (tbinfo->reloftype && !dopt->binary_upgrade)
1554415539
appendPQExpBuffer(q, " OF %s", tbinfo->reloftype);
1554515540

15541+
/*
15542+
* If the table is a partition, dump it as such; except in the case of
15543+
* a binary upgrade, we dump the table normally and attach it to the
15544+
* parent afterward.
15545+
*/
15546+
if (tbinfo->ispartition && !dopt->binary_upgrade)
15547+
{
15548+
TableInfo *parentRel = tbinfo->parents[0];
15549+
15550+
/*
15551+
* With partitions, unlike inheritance, there can only be one
15552+
* parent.
15553+
*/
15554+
if (tbinfo->numParents != 1)
15555+
exit_horribly(NULL, "invalid number of parents %d for table \"%s\"\n",
15556+
tbinfo->numParents, tbinfo->dobj.name);
15557+
15558+
appendPQExpBuffer(q, " PARTITION OF %s",
15559+
fmtQualifiedDumpable(parentRel));
15560+
}
15561+
1554615562
if (tbinfo->relkind != RELKIND_MATVIEW)
1554715563
{
1554815564
/* Dump the attributes */
@@ -15571,9 +15587,12 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1557115587
(!tbinfo->inhNotNull[j] ||
1557215588
dopt->binary_upgrade));
1557315589

15574-
/* Skip column if fully defined by reloftype */
15575-
if (tbinfo->reloftype && !has_default && !has_notnull &&
15576-
!dopt->binary_upgrade)
15590+
/*
15591+
* Skip column if fully defined by reloftype or the
15592+
* partition parent.
15593+
*/
15594+
if ((tbinfo->reloftype || tbinfo->ispartition) &&
15595+
!has_default && !has_notnull && !dopt->binary_upgrade)
1557715596
continue;
1557815597

1557915598
/* Format properly if not first attr */
@@ -15596,16 +15615,20 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1559615615
* clean things up later.
1559715616
*/
1559815617
appendPQExpBufferStr(q, " INTEGER /* dummy */");
15599-
/*and skip tothenext column */
15618+
/*Skip alltherest, too */
1560015619
continue;
1560115620
}
1560215621

1560315622
/*
15604-
* Attribute type; print it except when creating a typed
15605-
* table ('OF type_name'), but in binary-upgrade mode,
15606-
* print it in that case too.
15623+
* Attribute type
15624+
*
15625+
* In binary-upgrade mode, we always include the type. If
15626+
* we aren't in binary-upgrade mode, then we skip the type
15627+
* when creating a typed table ('OF type_name') or a
15628+
* partition ('PARTITION OF'), since the type comes from
15629+
* the parent/partitioned table.
1560715630
*/
15608-
if (dopt->binary_upgrade || !tbinfo->reloftype)
15631+
if (dopt->binary_upgrade ||(!tbinfo->reloftype && !tbinfo->ispartition))
1560915632
{
1561015633
appendPQExpBuffer(q, " %s",
1561115634
tbinfo->atttypnames[j]);
@@ -15655,20 +15678,25 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1565515678

1565615679
if (actual_atts)
1565715680
appendPQExpBufferStr(q, "\n)");
15658-
else if (!(tbinfo->reloftype && !dopt->binary_upgrade))
15681+
else if (!((tbinfo->reloftype || tbinfo->ispartition) &&
15682+
!dopt->binary_upgrade))
1565915683
{
1566015684
/*
15661-
*No attributes? wemust have a parenthesized attribute list,
15662-
*even thoughempty, when not using the OF TYPE syntax.
15685+
*Wemust have a parenthesized attribute list, even though
15686+
* empty, when not using the OF TYPE or PARTITION OF syntax.
1566315687
*/
1566415688
appendPQExpBufferStr(q, " (\n)");
1566515689
}
1566615690

15667-
/*
15668-
* Emit the INHERITS clause (not for partitions), except in
15669-
* binary-upgrade mode.
15670-
*/
15671-
if (numParents > 0 && !tbinfo->ispartition &&
15691+
if (tbinfo->ispartition && !dopt->binary_upgrade)
15692+
{
15693+
appendPQExpBufferChar(q, '\n');
15694+
appendPQExpBufferStr(q, tbinfo->partbound);
15695+
}
15696+
15697+
/* Emit the INHERITS clause, except if this is a partition. */
15698+
if (numParents > 0 &&
15699+
!tbinfo->ispartition &&
1567215700
!dopt->binary_upgrade)
1567315701
{
1567415702
appendPQExpBufferStr(q, "\nINHERITS (");
@@ -15841,16 +15869,30 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1584115869
appendPQExpBufferStr(q, "::pg_catalog.regclass;\n");
1584215870
}
1584315871

15844-
if (numParents > 0 && !tbinfo->ispartition)
15872+
if (numParents > 0)
1584515873
{
15846-
appendPQExpBufferStr(q, "\n-- For binary upgrade, set up inheritance this way.\n");
15874+
appendPQExpBufferStr(q, "\n-- For binary upgrade, set up inheritanceand partitioningthis way.\n");
1584715875
for (k = 0; k < numParents; k++)
1584815876
{
1584915877
TableInfo *parentRel = parents[k];
1585015878

15851-
appendPQExpBuffer(q, "ALTER TABLE ONLY %s INHERIT %s;\n",
15852-
qualrelname,
15853-
fmtQualifiedDumpable(parentRel));
15879+
/* In the partitioning case, we alter the parent */
15880+
if (tbinfo->ispartition)
15881+
appendPQExpBuffer(q,
15882+
"ALTER TABLE ONLY %s ATTACH PARTITION ",
15883+
fmtQualifiedDumpable(parentRel));
15884+
else
15885+
appendPQExpBuffer(q, "ALTER TABLE ONLY %s INHERIT ",
15886+
qualrelname);
15887+
15888+
/* Partition needs specifying the bounds */
15889+
if (tbinfo->ispartition)
15890+
appendPQExpBuffer(q, "%s %s;\n",
15891+
qualrelname,
15892+
tbinfo->partbound);
15893+
else
15894+
appendPQExpBuffer(q, "%s;\n",
15895+
fmtQualifiedDumpable(parentRel));
1585415896
}
1585515897
}
1585615898

@@ -15863,27 +15905,6 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1586315905
}
1586415906
}
1586515907

15866-
/*
15867-
* For partitioned tables, emit the ATTACH PARTITION clause. Note
15868-
* that we always want to create partitions this way instead of using
15869-
* CREATE TABLE .. PARTITION OF, mainly to preserve a possible column
15870-
* layout discrepancy with the parent, but also to ensure it gets the
15871-
* correct tablespace setting if it differs from the parent's.
15872-
*/
15873-
if (tbinfo->ispartition)
15874-
{
15875-
/* With partitions there can only be one parent */
15876-
if (tbinfo->numParents != 1)
15877-
exit_horribly(NULL, "invalid number of parents %d for table \"%s\"\n",
15878-
tbinfo->numParents, tbinfo->dobj.name);
15879-
15880-
/* Perform ALTER TABLE on the parent */
15881-
appendPQExpBuffer(q,
15882-
"ALTER TABLE ONLY %s ATTACH PARTITION %s %s;\n",
15883-
fmtQualifiedDumpable(parents[0]),
15884-
qualrelname, tbinfo->partbound);
15885-
}
15886-
1588715908
/*
1588815909
* In binary_upgrade mode, arrange to restore the old relfrozenxid and
1588915910
* relminmxid of all vacuumable relations. (While vacuum.c processes

‎src/bin/pg_dump/t/002_pg_dump.pl

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,7 @@
732732
\QALTER TABLE ONLY dump_test.measurement ATTACH PARTITION dump_test_second_schema.measurement_y2006m2\E
733733
\QFOR VALUES FROM ('2006-02-01') TO ('2006-03-01');\E\n
734734
/xm,
735-
like=> {
736-
%full_runs,
737-
role=> 1,
738-
section_pre_data=> 1,
739-
binary_upgrade=> 1,
740-
},
735+
like=> {binary_upgrade=> 1, },
741736
},
742737

743738
'ALTER TABLE test_table CLUSTER ON test_table_pkey'=> {
@@ -2355,13 +2350,12 @@
23552350
\QCREATE TABLE dump_test_second_schema.measurement_y2006m2 PARTITION OF dump_test.measurement\E\n
23562351
\QFOR VALUES FROM ('2006-02-01') TO ('2006-03-01');\E\n
23572352
/xm,
2358-
like => {},
2359-
unlike => {
2353+
like => {
23602354
%full_runs,
23612355
role => 1,
23622356
section_pre_data => 1,
2363-
binary_upgrade => 1,
23642357
},
2358+
unlike => { binary_upgrade => 1, },
23652359
},
23662360
23672361
'CREATE TABLE test_fourth_table_zero_col' => {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp