@@ -46,7 +46,7 @@ static void prepare_new_cluster(void);
46
46
static void prepare_new_databases (void );
47
47
static void create_new_objects (void );
48
48
static void copy_clog_xlog_xid (void );
49
- static void set_frozenxids (void );
49
+ static void set_frozenxids (bool minmxid_only );
50
50
static void setup (char * argv0 , bool * live_check );
51
51
static void cleanup (void );
52
52
@@ -250,8 +250,8 @@ prepare_new_cluster(void)
250
250
/*
251
251
* We do freeze after analyze so pg_statistic is also frozen. template0 is
252
252
* not frozen here, but data rows were frozen by initdb, and we set its
253
- * datfrozenxid and relfrozenxids later to match the new xid counter
254
- * later.
253
+ * datfrozenxid, relfrozenxids, and relminmxid later to match the new xid
254
+ * counter later.
255
255
*/
256
256
prep_status ("Freezing all rows on the new cluster" );
257
257
exec_prog (UTILITY_LOG_FILE , NULL , true,
@@ -273,7 +273,7 @@ prepare_new_databases(void)
273
273
* set.
274
274
*/
275
275
276
- set_frozenxids ();
276
+ set_frozenxids (false );
277
277
278
278
prep_status ("Restoring global objects in the new cluster" );
279
279
@@ -356,6 +356,13 @@ create_new_objects(void)
356
356
end_progress_output ();
357
357
check_ok ();
358
358
359
+ /*
360
+ * We don't have minmxids for databases or relations in pre-9.3
361
+ * clusters, so set those after we have restores the schemas.
362
+ */
363
+ if (GET_MAJOR_VERSION (old_cluster .major_version ) < 903 )
364
+ set_frozenxids (true);
365
+
359
366
/* regenerate now that we have objects in the databases */
360
367
get_db_and_rel_infos (& new_cluster );
361
368
@@ -489,15 +496,15 @@ copy_clog_xlog_xid(void)
489
496
/*
490
497
* set_frozenxids()
491
498
*
492
- * We have frozen all xids, so set relfrozenxid and datfrozenxid
493
- * to be the old cluster's xid counter, which we just set in the new
494
- * cluster. User-table frozenxid values will be set by pg_dump
495
- * --binary-upgrade, but objects not set by the pg_dump must have
496
- * proper frozen counters.
499
+ * We have frozen all xids, so set datfrozenxid, relfrozenxid, and
500
+ * relminmxid to be the old cluster's xid counter, which we just set
501
+ * in the new cluster. User-table frozenxid and minmxid values will
502
+ * be set by pg_dump --binary-upgrade, but objects not set by the pg_dump
503
+ * must have proper frozen counters.
497
504
*/
498
505
static
499
506
void
500
- set_frozenxids (void )
507
+ set_frozenxids (bool minmxid_only )
501
508
{
502
509
int dbnum ;
503
510
PGconn * conn ,
@@ -507,15 +514,25 @@ set_frozenxids(void)
507
514
int i_datname ;
508
515
int i_datallowconn ;
509
516
510
- prep_status ("Setting frozenxid counters in new cluster" );
517
+ if (!minmxid_only )
518
+ prep_status ("Setting frozenxid and minmxid counters in new cluster" );
519
+ else
520
+ prep_status ("Setting minmxid counter in new cluster" );
511
521
512
522
conn_template1 = connectToServer (& new_cluster , "template1" );
513
523
514
- /* set pg_database.datfrozenxid */
524
+ if (!minmxid_only )
525
+ /* set pg_database.datfrozenxid */
526
+ PQclear (executeQueryOrDie (conn_template1 ,
527
+ "UPDATE pg_catalog.pg_database "
528
+ "SET datfrozenxid = '%u'" ,
529
+ old_cluster .controldata .chkpnt_nxtxid ));
530
+
531
+ /* set pg_database.datminmxid */
515
532
PQclear (executeQueryOrDie (conn_template1 ,
516
533
"UPDATE pg_catalog.pg_database "
517
- "SET datfrozenxid = '%u'" ,
518
- old_cluster .controldata .chkpnt_nxtxid ));
534
+ "SET datminmxid = '%u'" ,
535
+ old_cluster .controldata .chkpnt_nxtmulti ));
519
536
520
537
/* get database names */
521
538
dbres = executeQueryOrDie (conn_template1 ,
@@ -533,10 +550,10 @@ set_frozenxids(void)
533
550
534
551
/*
535
552
* We must update databases where datallowconn = false, e.g.
536
- * template0, because autovacuum increments their datfrozenxids and
537
- * relfrozenxids even if autovacuum is turned off, and even though all
538
- * the data rows are already frozen To enable this, we temporarily
539
- * change datallowconn.
553
+ * template0, because autovacuum increments their datfrozenxids,
554
+ * relfrozenxids, and relminmxid even if autovacuum is turned off,
555
+ * and even though all the data rows are already frozen To enable
556
+ * this, we temporarily change datallowconn.
540
557
*/
541
558
if (strcmp (datallowconn , "f" ) == 0 )
542
559
PQclear (executeQueryOrDie (conn_template1 ,
@@ -545,13 +562,22 @@ set_frozenxids(void)
545
562
546
563
conn = connectToServer (& new_cluster , datname );
547
564
548
- /* set pg_class.relfrozenxid */
565
+ if (!minmxid_only )
566
+ /* set pg_class.relfrozenxid */
567
+ PQclear (executeQueryOrDie (conn ,
568
+ "UPDATE pg_catalog.pg_class "
569
+ "SET relfrozenxid = '%u' "
570
+ /* only heap, materialized view, and TOAST are vacuumed */
571
+ "WHERE relkind IN ('r', 'm', 't')" ,
572
+ old_cluster .controldata .chkpnt_nxtxid ));
573
+
574
+ /* set pg_class.relminmxid */
549
575
PQclear (executeQueryOrDie (conn ,
550
576
"UPDATE pg_catalog.pg_class "
551
- "SET relfrozenxid = '%u' "
577
+ "SET relminmxid = '%u' "
552
578
/* only heap, materialized view, and TOAST are vacuumed */
553
579
"WHERE relkind IN ('r', 'm', 't')" ,
554
- old_cluster .controldata .chkpnt_nxtxid ));
580
+ old_cluster .controldata .chkpnt_nxtmulti ));
555
581
PQfinish (conn );
556
582
557
583
/* Reset datallowconn flag */
0 commit comments