@@ -72,6 +72,7 @@ static MultiXactOffset set_mxoff = (MultiXactOffset) -1;
72
72
static uint32 minXlogTli = 0 ;
73
73
static XLogSegNo minXlogSegNo = 0 ;
74
74
static int WalSegSz ;
75
+ static int set_wal_segsize ;
75
76
76
77
static void CheckDataVersion (void );
77
78
static bool ReadControlFile (void );
@@ -100,6 +101,7 @@ main(int argc, char *argv[])
100
101
{"next-oid" , required_argument , NULL , 'o' },
101
102
{"multixact-offset" , required_argument , NULL , 'O' },
102
103
{"next-transaction-id" , required_argument , NULL , 'x' },
104
+ {"wal-segsize" , required_argument , NULL , 1 },
103
105
{NULL , 0 , NULL , 0 }
104
106
};
105
107
@@ -290,6 +292,24 @@ main(int argc, char *argv[])
290
292
log_fname = pg_strdup (optarg );
291
293
break ;
292
294
295
+ case 1 :
296
+ set_wal_segsize = strtol (optarg , & endptr , 10 ) * 1024 * 1024 ;
297
+ if (endptr == optarg || * endptr != '\0' )
298
+ {
299
+ fprintf (stderr ,
300
+ _ ("%s: argument of --wal-segsize must be a number\n" ),
301
+ progname );
302
+ exit (1 );
303
+ }
304
+ if (!IsValidWalSegSize (set_wal_segsize ))
305
+ {
306
+ fprintf (stderr ,
307
+ _ ("%s: argument of --wal-segsize must be a power of 2 between 1 and 1024\n" ),
308
+ progname );
309
+ exit (1 );
310
+ }
311
+ break ;
312
+
293
313
default :
294
314
fprintf (stderr , _ ("Try \"%s --help\" for more information.\n" ), progname );
295
315
exit (1 );
@@ -372,6 +392,14 @@ main(int argc, char *argv[])
372
392
if (!ReadControlFile ())
373
393
GuessControlValues ();
374
394
395
+ /*
396
+ * If no new WAL segment size was specified, use the control file value.
397
+ */
398
+ if (set_wal_segsize != 0 )
399
+ WalSegSz = set_wal_segsize ;
400
+ else
401
+ WalSegSz = ControlFile .xlog_seg_size ;
402
+
375
403
if (log_fname != NULL )
376
404
XLogFromFileName (log_fname , & minXlogTli , & minXlogSegNo , WalSegSz );
377
405
@@ -438,6 +466,9 @@ main(int argc, char *argv[])
438
466
ControlFile .checkPointCopy .PrevTimeLineID = minXlogTli ;
439
467
}
440
468
469
+ if (set_wal_segsize != 0 )
470
+ ControlFile .xlog_seg_size = WalSegSz ;
471
+
441
472
if (minXlogSegNo > newXlogSegNo )
442
473
newXlogSegNo = minXlogSegNo ;
443
474
@@ -608,14 +639,13 @@ ReadControlFile(void)
608
639
}
609
640
610
641
memcpy (& ControlFile , buffer , sizeof (ControlFile ));
611
- WalSegSz = ControlFile .xlog_seg_size ;
612
642
613
- /* return false if WalSegSz is not valid */
614
- if (!IsValidWalSegSize (WalSegSz ))
643
+ /* return false if WAL segment size is not valid */
644
+ if (!IsValidWalSegSize (ControlFile . xlog_seg_size ))
615
645
{
616
646
fprintf (stderr ,
617
647
_ ("%s: pg_control specifies invalid WAL segment size (%d bytes); proceed with caution \n" ),
618
- progname , WalSegSz );
648
+ progname , ControlFile . xlog_seg_size );
619
649
return false;
620
650
}
621
651
@@ -694,7 +724,7 @@ GuessControlValues(void)
694
724
ControlFile .blcksz = BLCKSZ ;
695
725
ControlFile .relseg_size = RELSEG_SIZE ;
696
726
ControlFile .xlog_blcksz = XLOG_BLCKSZ ;
697
- WalSegSz = ControlFile .xlog_seg_size = DEFAULT_XLOG_SEG_SIZE ;
727
+ ControlFile .xlog_seg_size = DEFAULT_XLOG_SEG_SIZE ;
698
728
ControlFile .nameDataLen = NAMEDATALEN ;
699
729
ControlFile .indexMaxKeys = INDEX_MAX_KEYS ;
700
730
ControlFile .toast_max_chunk_size = TOAST_MAX_CHUNK_SIZE ;
@@ -859,6 +889,12 @@ PrintNewControlValues(void)
859
889
printf (_ ("newestCommitTsXid: %u\n" ),
860
890
ControlFile .checkPointCopy .newestCommitTsXid );
861
891
}
892
+
893
+ if (set_wal_segsize != 0 )
894
+ {
895
+ printf (_ ("Bytes per WAL segment: %u\n" ),
896
+ ControlFile .xlog_seg_size );
897
+ }
862
898
}
863
899
864
900
@@ -910,9 +946,6 @@ RewriteControlFile(void)
910
946
ControlFile .max_prepared_xacts = 0 ;
911
947
ControlFile .max_locks_per_xact = 64 ;
912
948
913
- /* Now we can force the recorded xlog seg size to the right thing. */
914
- ControlFile .xlog_seg_size = WalSegSz ;
915
-
916
949
/* Contents are protected with a CRC */
917
950
INIT_CRC32C (ControlFile .crc );
918
951
COMP_CRC32C (ControlFile .crc ,
@@ -1048,7 +1081,7 @@ FindEndOfXLOG(void)
1048
1081
* are in virgin territory.
1049
1082
*/
1050
1083
xlogbytepos = newXlogSegNo * ControlFile .xlog_seg_size ;
1051
- newXlogSegNo = (xlogbytepos + WalSegSz - 1 ) / WalSegSz ;
1084
+ newXlogSegNo = (xlogbytepos + ControlFile . xlog_seg_size - 1 ) / WalSegSz ;
1052
1085
newXlogSegNo ++ ;
1053
1086
}
1054
1087
@@ -1279,6 +1312,7 @@ usage(void)
1279
1312
printf (_ (" -O, --multixact-offset=OFFSET set next multitransaction offset\n" ));
1280
1313
printf (_ (" -V, --version output version information, then exit\n" ));
1281
1314
printf (_ (" -x, --next-transaction-id=XID set next transaction ID\n" ));
1315
+ printf (_ (" --wal-segsize=SIZE size of WAL segments, in megabytes\n" ));
1282
1316
printf (_ (" -?, --help show this help, then exit\n" ));
1283
1317
printf (_ ("\nReport bugs to <pgsql-bugs@postgresql.org>.\n" ));
1284
1318
}
0 commit comments