1764
1766
NULL, /* Dumper */
1765
1767
NULL); /* Dumper Arg */
1770
* pg_largeobject comes from the old system intact, so set
1776
PQExpBuffer loFrozenQry = createPQExpBuffer();
1777
PQExpBuffer loOutQry = createPQExpBuffer();
1780
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid\n"
1781
"FROM pg_catalog.pg_class\n"
1782
"WHERE oid = %d;\n",
1783
LargeObjectRelationId);
1785
lo_res = PQexec(g_conn, loFrozenQry->data);
1786
check_sql_result(lo_res, g_conn, loFrozenQry->data, PGRES_TUPLES_OK);
1788
if (PQntuples(lo_res) != 1)
1790
write_msg(NULL, "dumpDatabase(): could not find pg_largeobject.relfrozenxid\n");
1794
i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid");
1796
appendPQExpBuffer(loOutQry, "\n-- For binary upgrade, set pg_largeobject relfrozenxid.\n");
1797
appendPQExpBuffer(loOutQry, "UPDATE pg_catalog.pg_class\n"
1798
"SET relfrozenxid = '%u'\n"
1799
"WHERE oid = %d;\n",
1800
atoi(PQgetvalue(lo_res, 0, i_relfrozenxid)),
1801
LargeObjectRelationId);
1802
ArchiveEntry(AH, nilCatalogId, createDumpId(),
1803
"pg_largeobject", NULL, NULL, "",
1804
false, "pg_largeobject", SECTION_PRE_DATA,
1805
loOutQry->data, "", NULL,
1810
destroyPQExpBuffer(loFrozenQry);
1811
destroyPQExpBuffer(loOutQry);
1767
1814
/* Dump DB comment if any */
1768
1815
if (g_fout->remoteVersion >= 80200)
9783
9816
actual_atts = 0;
9784
9817
for (j = 0; j < tbinfo->numatts; j++)
9786
/* Is this one of the table's own attrs, and not dropped ? */
9787
if (!tbinfo->inhAttrs[j] &&
9788
(!tbinfo->attisdropped[j] || binary_upgrade))
9820
* Normally, dump if it's one of the table's own attrs, and not
9821
* dropped. But for binary upgrade, dump all the columns.
9823
if ((!tbinfo->inhAttrs[j] && !tbinfo->attisdropped[j]) ||
9790
9826
/* Format properly if not first attr */
9791
9827
if (actual_atts > 0)
9792
9828
appendPQExpBuffer(q, ",");
9793
9829
appendPQExpBuffer(q, "\n ");
9795
9832
/* Attribute name */
9796
9833
appendPQExpBuffer(q, "%s ",
9797
9834
fmtId(tbinfo->attnames[j]));
9836
if (tbinfo->attisdropped[j])
9839
* ALTER TABLE DROP COLUMN clears pg_attribute.atttypid,
9840
* so we will not have gotten a valid type name; insert
9841
* INTEGER as a stopgap. We'll clean things up later.
9843
appendPQExpBuffer(q, "INTEGER /* dummy */");
9844
/* Skip all the rest, too */
9799
9848
/* Attribute type */
9800
9849
if (g_fout->remoteVersion >= 70100)
9814
* Default value --- suppress if inherited or to be printed
9863
* Default value --- suppress if inherited (except in
9864
* binary-upgrade case, where we're not doing normal
9865
* inheritance) or if it's to be printed separately.
9817
9867
if (tbinfo->attrdefs[j] != NULL &&
9818
!tbinfo->inhAttrDef[j] &&
9868
(!tbinfo->inhAttrDef[j] || binary_upgrade) &&
9819
9869
!tbinfo->attrdefs[j]->separate)
9820
9870
appendPQExpBuffer(q, " DEFAULT %s",
9821
9871
tbinfo->attrdefs[j]->adef_expr);
9824
* Not Null constraint --- suppress if inherited
9874
* Not Null constraint --- suppress if inherited, except
9875
* in binary-upgrade case.
9826
if (tbinfo->notnull[j] && !tbinfo->inhNotNull[j])
9877
if (tbinfo->notnull[j] &&
9878
(!tbinfo->inhNotNull[j] || binary_upgrade))
9827
9879
appendPQExpBuffer(q, " NOT NULL");
9902
9960
if (tbinfo->attisdropped[j])
9904
appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
9905
fmtId(tbinfo->dobj.name));
9906
appendPQExpBuffer(q, "DROP COLUMN %s;\n",
9907
fmtId(tbinfo->attnames[j]));
9910
* ALTER TABLE DROP COLUMN clears pg_attribute.atttypid,
9911
* so we have to set pg_attribute.attlen and
9912
* pg_attribute.attalign values because that is what is
9913
* used to skip over dropped columns in the heap tuples.
9914
* We have atttypmod, but it seems impossible to know the
9915
* correct data type that will yield pg_attribute values
9916
* that match the old installation. See comment in
9917
* backend/catalog/heap.c::RemoveAttributeById()
9919
appendPQExpBuffer(q, "\n-- For binary upgrade, recreate dropped column's length and alignment.\n");
9920
appendPQExpBuffer(q, "UPDATE pg_attribute\n"
9962
appendPQExpBuffer(q, "\n-- For binary upgrade, recreate dropped column.\n");
9963
appendPQExpBuffer(q, "UPDATE pg_catalog.pg_attribute\n"
9921
9964
"SET attlen = %d, "
9923
"WHERE attname = '%s'\n"
9924
" AND attrelid = \n"
9928
" WHERE relnamespace = "
9929
"(SELECT oid FROM pg_namespace "
9930
"WHERE nspname = CURRENT_SCHEMA)\n"
9965
"attalign = '%c', attbyval = false\n"
9932
9967
tbinfo->attlen[j],
9933
tbinfo->attalign[j],
9934
tbinfo->attnames[j]);
9935
appendStringLiteralAH(q, tbinfo->dobj.name, fout);
9936
appendPQExpBuffer(q, "\n );\n");
9968
tbinfo->attalign[j]);
9969
appendStringLiteralAH(q, tbinfo->attnames[j], fout);
9970
appendPQExpBuffer(q, "\n AND attrelid = ");
9971
appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);
9972
appendPQExpBuffer(q, "::pg_catalog.regclass;\n");
9974
appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
9975
fmtId(tbinfo->dobj.name));
9976
appendPQExpBuffer(q, "DROP COLUMN %s;\n",
9977
fmtId(tbinfo->attnames[j]));
9979
else if (!tbinfo->attislocal[j])
9981
appendPQExpBuffer(q, "\n-- For binary upgrade, recreate inherited column.\n");
9982
appendPQExpBuffer(q, "UPDATE pg_catalog.pg_attribute\n"
9983
"SET attislocal = false\n"
9984
"WHERE attname = ");
9985
appendStringLiteralAH(q, tbinfo->attnames[j], fout);
9986
appendPQExpBuffer(q, "\n AND attrelid = ");
9987
appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);
9988
appendPQExpBuffer(q, "::pg_catalog.regclass;\n");
9992
for (k = 0; k < tbinfo->ncheck; k++)
9994
ConstraintInfo *constr = &(tbinfo->checkexprs[k]);
9996
if (constr->separate || constr->conislocal)
9999
appendPQExpBuffer(q, "\n-- For binary upgrade, set up inherited constraint.\n");
10000
appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
10001
fmtId(tbinfo->dobj.name));
10002
appendPQExpBuffer(q, " ADD CONSTRAINT %s ",
10003
fmtId(constr->dobj.name));
10004
appendPQExpBuffer(q, "%s;\n", constr->condef);
10005
appendPQExpBuffer(q, "UPDATE pg_catalog.pg_constraint\n"
10006
"SET conislocal = false\n"
10007
"WHERE contype = 'c' AND conname = ");
10008
appendStringLiteralAH(q, constr->dobj.name, fout);
10009
appendPQExpBuffer(q, "\n AND conrelid = ");
10010
appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);
10011
appendPQExpBuffer(q, "::pg_catalog.regclass;\n");
10014
if (numParents > 0)
10016
appendPQExpBuffer(q, "\n-- For binary upgrade, set up inheritance this way.\n");
10017
for (k = 0; k < numParents; k++)
10019
TableInfo *parentRel = parents[k];
10021
appendPQExpBuffer(q, "ALTER TABLE ONLY %s INHERIT ",
10022
fmtId(tbinfo->dobj.name));
10023
if (parentRel->dobj.namespace != tbinfo->dobj.namespace)
10024
appendPQExpBuffer(q, "%s.",
10025
fmtId(parentRel->dobj.namespace->dobj.name));
10026
appendPQExpBuffer(q, "%s;\n",
10027
fmtId(parentRel->dobj.name));
9939
10031
appendPQExpBuffer(q, "\n-- For binary upgrade, set relfrozenxid.\n");
9940
appendPQExpBuffer(q, "UPDATE pg_class\n"
10032
appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n"
9941
10033
"SET relfrozenxid = '%u'\n"
9943
10035
tbinfo->frozenxid);
9944
appendStringLiteralAH(q, tbinfo->dobj.name, fout);
9945
appendPQExpBuffer(q, "\n AND relnamespace = "
9946
"(SELECT oid FROM pg_namespace "
9947
"WHERE nspname = CURRENT_SCHEMA);\n");
10036
appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);
10037
appendPQExpBuffer(q, "::pg_catalog.regclass;\n");
9950
10040
/* Loop dumping statistics and storage statements */