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

Commitd498e05

Browse files
committed
Preserve relfilenode of pg_largeobject and its index across pg_upgrade.
Commit9a974cb did this for usertables, but pg_upgrade treats pg_largeobject as a user table, and soneeds the same treatment. Without this fix, if you rewrite thepg_largeobject table and then perform an upgrade with pg_upgrade, thetable will apparently be empty on the new cluster, while all of yourobjects will end up with an orphaned file.With this fix, instead of the old cluster's pg_largeobject files endingup orphaned, the original files fro the new cluster do. That's mostlyharmless because we expect the table to be empty, but we might wantto arrange to remove the as part of the upgrade. Since we're stilldebating the best way of doing that, I (rhaas) have decided to postponedealing with that problem and get the basic fix committed.Justin Pryzby, reviewed by Shruthi Gowda and by me.Discussion:http://postgr.es/m/20220701231413.GI13040@telsasoft.com
1 parentbf1f4a3 commitd498e05

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,42 +3134,49 @@ dumpDatabase(Archive *fout)
31343134

31353135
/*
31363136
* pg_largeobject comes from the old system intact, so set its
3137-
* relfrozenxidsandrelminmxids.
3137+
* relfrozenxids, relminmxidsandrelfilenode.
31383138
*/
31393139
if (dopt->binary_upgrade)
31403140
{
31413141
PGresult *lo_res;
31423142
PQExpBuffer loFrozenQry = createPQExpBuffer();
31433143
PQExpBuffer loOutQry = createPQExpBuffer();
31443144
inti_relfrozenxid,
3145+
i_relfilenode,
3146+
i_oid,
31453147
i_relminmxid;
31463148

31473149
/*
31483150
* pg_largeobject
31493151
*/
31503152
if (fout->remoteVersion >= 90300)
3151-
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid\n"
3153+
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n"
31523154
"FROM pg_catalog.pg_class\n"
3153-
"WHERE oid= %u;\n",
3154-
LargeObjectRelationId);
3155+
"WHERE oidIN (%u, %u);\n",
3156+
LargeObjectRelationId, LargeObjectLOidPNIndexId);
31553157
else
3156-
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, 0 AS relminmxid\n"
3158+
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, 0 AS relminmxid, relfilenode, oid\n"
31573159
"FROM pg_catalog.pg_class\n"
3158-
"WHERE oid= %u;\n",
3159-
LargeObjectRelationId);
3160+
"WHERE oidIN (%u, %u);\n",
3161+
LargeObjectRelationId, LargeObjectLOidPNIndexId);
31603162

3161-
lo_res =ExecuteSqlQueryForSingleRow(fout, loFrozenQry->data);
3163+
lo_res =ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK);
31623164

31633165
i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid");
31643166
i_relminmxid = PQfnumber(lo_res, "relminmxid");
3167+
i_relfilenode = PQfnumber(lo_res, "relfilenode");
3168+
i_oid = PQfnumber(lo_res, "oid");
3169+
3170+
appendPQExpBufferStr(loOutQry, "\n-- For binary upgrade, preserve values for pg_largeobject and its index\n");
3171+
for (int i = 0; i < PQntuples(lo_res); ++i)
3172+
appendPQExpBuffer(loOutQry, "UPDATE pg_catalog.pg_class\n"
3173+
"SET relfrozenxid = '%u', relminmxid = '%u', relfilenode = '%u'\n"
3174+
"WHERE oid = %u;\n",
3175+
atooid(PQgetvalue(lo_res, i, i_relfrozenxid)),
3176+
atooid(PQgetvalue(lo_res, i, i_relminmxid)),
3177+
atooid(PQgetvalue(lo_res, i, i_relfilenode)),
3178+
atooid(PQgetvalue(lo_res, i, i_oid)));
31653179

3166-
appendPQExpBufferStr(loOutQry, "\n-- For binary upgrade, set pg_largeobject relfrozenxid and relminmxid\n");
3167-
appendPQExpBuffer(loOutQry, "UPDATE pg_catalog.pg_class\n"
3168-
"SET relfrozenxid = '%u', relminmxid = '%u'\n"
3169-
"WHERE oid = %u;\n",
3170-
atooid(PQgetvalue(lo_res, 0, i_relfrozenxid)),
3171-
atooid(PQgetvalue(lo_res, 0, i_relminmxid)),
3172-
LargeObjectRelationId);
31733180
ArchiveEntry(fout, nilCatalogId, createDumpId(),
31743181
ARCHIVE_OPTS(.tag = "pg_largeobject",
31753182
.description = "pg_largeobject",

‎src/bin/pg_upgrade/t/002_pg_upgrade.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ sub generate_db
208208
}
209209
}
210210

211+
$oldnode->safe_psql("regression","VACUUM FULL pg_largeobject;");
212+
211213
# In a VPATH build, we'll be started in the source directory, but we want
212214
# to run pg_upgrade in the build directory so that any files generated finish
213215
# in it, like delete_old_cluster.{sh,bat}.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp