@@ -72,6 +72,7 @@ static MultiXactOffset set_mxoff = (MultiXactOffset) -1;
7272static uint32 minXlogTli = 0 ;
7373static XLogSegNo minXlogSegNo = 0 ;
7474static int WalSegSz ;
75+ static int set_wal_segsize ;
7576
7677static void CheckDataVersion (void );
7778static bool ReadControlFile (void );
@@ -100,6 +101,7 @@ main(int argc, char *argv[])
100101 {"next-oid" , required_argument , NULL , 'o' },
101102 {"multixact-offset" , required_argument , NULL , 'O' },
102103 {"next-transaction-id" , required_argument , NULL , 'x' },
104+ {"wal-segsize" , required_argument , NULL , 1 },
103105 {NULL , 0 , NULL , 0 }
104106 };
105107
@@ -290,6 +292,24 @@ main(int argc, char *argv[])
290292 log_fname = pg_strdup (optarg );
291293 break ;
292294
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+
293313 default :
294314 fprintf (stderr , _ ("Try \"%s --help\" for more information.\n" ), progname );
295315 exit (1 );
@@ -372,6 +392,14 @@ main(int argc, char *argv[])
372392 if (!ReadControlFile ())
373393 GuessControlValues ();
374394
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+
375403 if (log_fname != NULL )
376404 XLogFromFileName (log_fname , & minXlogTli , & minXlogSegNo , WalSegSz );
377405
@@ -438,6 +466,9 @@ main(int argc, char *argv[])
438466 ControlFile .checkPointCopy .PrevTimeLineID = minXlogTli ;
439467 }
440468
469+ if (set_wal_segsize != 0 )
470+ ControlFile .xlog_seg_size = WalSegSz ;
471+
441472 if (minXlogSegNo > newXlogSegNo )
442473 newXlogSegNo = minXlogSegNo ;
443474
@@ -608,14 +639,13 @@ ReadControlFile(void)
608639 }
609640
610641 memcpy (& ControlFile , buffer , sizeof (ControlFile ));
611- WalSegSz = ControlFile .xlog_seg_size ;
612642
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 ))
615645 {
616646 fprintf (stderr ,
617647 _ ("%s: pg_control specifies invalid WAL segment size (%d bytes); proceed with caution \n" ),
618- progname , WalSegSz );
648+ progname , ControlFile . xlog_seg_size );
619649 return false;
620650 }
621651
@@ -694,7 +724,7 @@ GuessControlValues(void)
694724 ControlFile .blcksz = BLCKSZ ;
695725 ControlFile .relseg_size = RELSEG_SIZE ;
696726 ControlFile .xlog_blcksz = XLOG_BLCKSZ ;
697- WalSegSz = ControlFile .xlog_seg_size = DEFAULT_XLOG_SEG_SIZE ;
727+ ControlFile .xlog_seg_size = DEFAULT_XLOG_SEG_SIZE ;
698728 ControlFile .nameDataLen = NAMEDATALEN ;
699729 ControlFile .indexMaxKeys = INDEX_MAX_KEYS ;
700730 ControlFile .toast_max_chunk_size = TOAST_MAX_CHUNK_SIZE ;
@@ -859,6 +889,12 @@ PrintNewControlValues(void)
859889 printf (_ ("newestCommitTsXid: %u\n" ),
860890 ControlFile .checkPointCopy .newestCommitTsXid );
861891 }
892+
893+ if (set_wal_segsize != 0 )
894+ {
895+ printf (_ ("Bytes per WAL segment: %u\n" ),
896+ ControlFile .xlog_seg_size );
897+ }
862898}
863899
864900
@@ -910,9 +946,6 @@ RewriteControlFile(void)
910946 ControlFile .max_prepared_xacts = 0 ;
911947 ControlFile .max_locks_per_xact = 64 ;
912948
913- /* Now we can force the recorded xlog seg size to the right thing. */
914- ControlFile .xlog_seg_size = WalSegSz ;
915-
916949 /* Contents are protected with a CRC */
917950 INIT_CRC32C (ControlFile .crc );
918951 COMP_CRC32C (ControlFile .crc ,
@@ -1048,7 +1081,7 @@ FindEndOfXLOG(void)
10481081 * are in virgin territory.
10491082 */
10501083 xlogbytepos = newXlogSegNo * ControlFile .xlog_seg_size ;
1051- newXlogSegNo = (xlogbytepos + WalSegSz - 1 ) / WalSegSz ;
1084+ newXlogSegNo = (xlogbytepos + ControlFile . xlog_seg_size - 1 ) / WalSegSz ;
10521085 newXlogSegNo ++ ;
10531086}
10541087
@@ -1279,6 +1312,7 @@ usage(void)
12791312 printf (_ (" -O, --multixact-offset=OFFSET set next multitransaction offset\n" ));
12801313 printf (_ (" -V, --version output version information, then exit\n" ));
12811314 printf (_ (" -x, --next-transaction-id=XID set next transaction ID\n" ));
1315+ printf (_ (" --wal-segsize=SIZE size of WAL segments, in megabytes\n" ));
12821316 printf (_ (" -?, --help show this help, then exit\n" ));
12831317 printf (_ ("\nReport bugs to <pgsql-bugs@postgresql.org>.\n" ));
12841318}
0 commit comments