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