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

Commit573e446

Browse files
committed
For pg_upgrade, update template0's datfrozenxid and its relfrozenxids to
match the behavior of autovacuum, which does this as the xid advanceseven if autovacuum is turned off.
1 parent3ef9574 commit573e446

File tree

1 file changed

+42
-15
lines changed

1 file changed

+42
-15
lines changed

‎contrib/pg_upgrade/pg_upgrade.c

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ prepare_new_cluster(migratorContext *ctx)
164164
check_ok(ctx);
165165

166166
/*
167-
* We do freeze after analyze so pg_statistic is also frozen
167+
* We do freeze after analyze so pg_statistic is also frozen.
168+
* template0 is not frozen here, but data rows were frozen by initdb,
169+
* and we set its datfrozenxid and relfrozenxids later to match the
170+
* new xid counter later.
168171
*/
169172
prep_status(ctx,"Freezing all rows on the new cluster");
170173
exec_prog(ctx, true,
@@ -292,48 +295,72 @@ void
292295
set_frozenxids(migratorContext*ctx)
293296
{
294297
intdbnum;
295-
PGconn*conn;
298+
PGconn*conn,*conn_template1;
296299
PGresult*dbres;
297300
intntups;
301+
inti_datname;
302+
inti_datallowconn;
298303

299304
prep_status(ctx,"Setting frozenxid counters in new cluster");
300305

301-
conn=connectToServer(ctx,"template1",CLUSTER_NEW);
306+
conn_template1=connectToServer(ctx,"template1",CLUSTER_NEW);
302307

303308
/* set pg_database.datfrozenxid */
304-
PQclear(executeQueryOrDie(ctx,conn,
309+
PQclear(executeQueryOrDie(ctx,conn_template1,
305310
"UPDATE pg_catalog.pg_database "
306-
"SETdatfrozenxid = '%u' "
307-
"WHERE datallowconn = true",
311+
"SETdatfrozenxid = '%u'",
308312
ctx->old.controldata.chkpnt_nxtxid));
309313

310314
/* get database names */
311-
dbres=executeQueryOrDie(ctx,conn,
312-
"SELECTdatname "
313-
"FROMpg_catalog.pg_database "
314-
"WHERE datallowconn = true");
315+
dbres=executeQueryOrDie(ctx,conn_template1,
316+
"SELECTdatname, datallowconn "
317+
"FROMpg_catalog.pg_database");
315318

316-
/* freedbres below */
317-
PQfinish(conn);
319+
i_datname=PQfnumber(dbres,"datname");
320+
i_datallowconn=PQfnumber(dbres,"datallowconn");
318321

319322
ntups=PQntuples(dbres);
320323
for (dbnum=0;dbnum<ntups;dbnum++)
321324
{
322-
conn=connectToServer(ctx,PQgetvalue(dbres,dbnum,0),CLUSTER_NEW);
325+
char*datname=PQgetvalue(dbres,dbnum,i_datname);
326+
char*datallowconn=PQgetvalue(dbres,dbnum,i_datallowconn);
327+
328+
/*
329+
*We must update databases where datallowconn = false, e.g.
330+
*template0, because autovacuum increments their datfrozenxids and
331+
*relfrozenxids even if autovacuum is turned off, and even though
332+
*all the data rows are already frozen To enable this, we
333+
*temporarily change datallowconn.
334+
*/
335+
if (strcmp(datallowconn,"f")==0)
336+
PQclear(executeQueryOrDie(ctx,conn_template1,
337+
"UPDATE pg_catalog.pg_database "
338+
"SETdatallowconn = true "
339+
"WHERE datname = '%s'",datname));
340+
341+
conn=connectToServer(ctx,datname,CLUSTER_NEW);
323342

324343
/* set pg_class.relfrozenxid */
325344
PQclear(executeQueryOrDie(ctx,conn,
326345
"UPDATEpg_catalog.pg_class "
327346
"SETrelfrozenxid = '%u' "
328347
/* only heap and TOAST are vacuumed */
329-
"WHERErelkind = 'r' OR "
330-
"relkind = 't'",
348+
"WHERErelkind IN ('r', 't')",
331349
ctx->old.controldata.chkpnt_nxtxid));
332350
PQfinish(conn);
351+
352+
/* Reset datallowconn flag */
353+
if (strcmp(datallowconn,"f")==0)
354+
PQclear(executeQueryOrDie(ctx,conn_template1,
355+
"UPDATE pg_catalog.pg_database "
356+
"SETdatallowconn = false "
357+
"WHERE datname = '%s'",datname));
333358
}
334359

335360
PQclear(dbres);
336361

362+
PQfinish(conn_template1);
363+
337364
check_ok(ctx);
338365
}
339366

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp