From cf9f6c8d8e9df28f3fbe1850ca7f042b2c01252e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 2 May 2008 19:52:37 +0000 Subject: [PATCH] Extend yesterday's patch making BLCKSZ and RELSEG_SIZE configurable to also let XLOG_BLCKSZ and XLOG_SEG_SIZE be set via configure. Per a proposal by Mark Wong, though I thought it better to call the switches after "wal" rather than "xlog". --- configure | 116 ++++++++++++++++++++++++++++++++- configure.in | 63 ++++++++++++++++-- doc/src/sgml/installation.sgml | 30 ++++++++- doc/src/sgml/wal.sgml | 9 ++- src/include/pg_config.h.in | 12 ++++ src/include/pg_config_manual.h | 21 +----- 6 files changed, 220 insertions(+), 31 deletions(-) diff --git a/configure b/configure index 31c163b654..bb7145e5d7 100755 --- a/configure +++ b/configure @@ -1373,8 +1373,10 @@ Optional Packages: --with-libraries=DIRS look for additional libraries in DIRS --with-libs=DIRS alternative spelling of --with-libraries --with-pgport=PORTNUM set default port number [5432] - --with-blocksize=BLOCKSIZE set block size in kB [8] - --with-segsize=SEGSIZE set segment size in GB [1] + --with-blocksize=BLOCKSIZE set table block size in kB [8] + --with-segsize=SEGSIZE set table segment size in GB [1] + --with-wal-blocksize=BLOCKSIZE set WAL block size in kB [8] + --with-wal-segsize=SEGSIZE set WAL segment size in MB [16] --with-tcl build Tcl modules (PL/Tcl) --with-tclconfig=DIR tclConfig.sh is in DIR --with-perl build Perl modules (PL/Perl) @@ -2603,7 +2605,7 @@ _ACEOF # -# File segment size +# Relation segment size # { echo "$as_me:$LINENO: checking for segment size" >&5 echo $ECHO_N "checking for segment size... $ECHO_C" >&6; } @@ -2647,6 +2649,114 @@ cat >>confdefs.h <<_ACEOF _ACEOF +# +# WAL block size +# +{ echo "$as_me:$LINENO: checking for WAL block size" >&5 +echo $ECHO_N "checking for WAL block size... $ECHO_C" >&6; } + +pgac_args="$pgac_args with_wal_blocksize" + + +# Check whether --with-wal-blocksize was given. +if test "${with_wal_blocksize+set}" = set; then + withval=$with_wal_blocksize; + case $withval in + yes) + { { echo "$as_me:$LINENO: error: argument required for --with-wal-blocksize option" >&5 +echo "$as_me: error: argument required for --with-wal-blocksize option" >&2;} + { (exit 1); exit 1; }; } + ;; + no) + { { echo "$as_me:$LINENO: error: argument required for --with-wal-blocksize option" >&5 +echo "$as_me: error: argument required for --with-wal-blocksize option" >&2;} + { (exit 1); exit 1; }; } + ;; + *) + wal_blocksize=$withval + ;; + esac + +else + wal_blocksize=8 +fi + + +case ${wal_blocksize} in + 1) XLOG_BLCKSZ=1024;; + 2) XLOG_BLCKSZ=2048;; + 4) XLOG_BLCKSZ=4096;; + 8) XLOG_BLCKSZ=8192;; + 16) XLOG_BLCKSZ=16384;; + 32) XLOG_BLCKSZ=32768;; + 64) XLOG_BLCKSZ=65536;; + *) { { echo "$as_me:$LINENO: error: Invalid WAL block size. Allowed values are 1,2,4,8,16,32,64." >&5 +echo "$as_me: error: Invalid WAL block size. Allowed values are 1,2,4,8,16,32,64." >&2;} + { (exit 1); exit 1; }; } +esac +{ echo "$as_me:$LINENO: result: ${wal_blocksize}kB" >&5 +echo "${ECHO_T}${wal_blocksize}kB" >&6; } + + +cat >>confdefs.h <<_ACEOF +#define XLOG_BLCKSZ ${XLOG_BLCKSZ} +_ACEOF + + +# +# WAL segment size +# +{ echo "$as_me:$LINENO: checking for WAL segment size" >&5 +echo $ECHO_N "checking for WAL segment size... $ECHO_C" >&6; } + +pgac_args="$pgac_args with_wal_segsize" + + +# Check whether --with-wal-segsize was given. +if test "${with_wal_segsize+set}" = set; then + withval=$with_wal_segsize; + case $withval in + yes) + { { echo "$as_me:$LINENO: error: argument required for --with-wal-segsize option" >&5 +echo "$as_me: error: argument required for --with-wal-segsize option" >&2;} + { (exit 1); exit 1; }; } + ;; + no) + { { echo "$as_me:$LINENO: error: argument required for --with-wal-segsize option" >&5 +echo "$as_me: error: argument required for --with-wal-segsize option" >&2;} + { (exit 1); exit 1; }; } + ;; + *) + wal_segsize=$withval + ;; + esac + +else + wal_segsize=16 +fi + + +case ${wal_segsize} in + 1) ;; + 2) ;; + 4) ;; + 8) ;; + 16) ;; + 32) ;; + 64) ;; + *) { { echo "$as_me:$LINENO: error: Invalid WAL segment size. Allowed values are 1,2,4,8,16,32,64." >&5 +echo "$as_me: error: Invalid WAL segment size. Allowed values are 1,2,4,8,16,32,64." >&2;} + { (exit 1); exit 1; }; } +esac +{ echo "$as_me:$LINENO: result: ${wal_segsize}MB" >&5 +echo "${ECHO_T}${wal_segsize}MB" >&6; } + + +cat >>confdefs.h <<_ACEOF +#define XLOG_SEG_SIZE (${wal_segsize} * 1024 * 1024) +_ACEOF + + # # C compiler # diff --git a/configure.in b/configure.in index ca84960dbf..9925389a47 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -dnl $PostgreSQL: pgsql/configure.in,v 1.558 2008/05/02 01:08:26 tgl Exp $ +dnl $PostgreSQL: pgsql/configure.in,v 1.559 2008/05/02 19:52:37 tgl Exp $ dnl dnl Developers, please strive to achieve this order: dnl @@ -221,7 +221,7 @@ AC_SUBST(enable_dtrace) # Block size # AC_MSG_CHECKING([for block size]) -PGAC_ARG_REQ(with, blocksize, [ --with-blocksize=BLOCKSIZE set block size in kB [[8]]], +PGAC_ARG_REQ(with, blocksize, [ --with-blocksize=BLOCKSIZE set table block size in kB [[8]]], [blocksize=$withval], [blocksize=8]) case ${blocksize} in @@ -250,10 +250,10 @@ AC_DEFINE_UNQUOTED([BLCKSZ], ${BLCKSZ}, [ ]) # -# File segment size +# Relation segment size # AC_MSG_CHECKING([for segment size]) -PGAC_ARG_REQ(with, segsize, [ --with-segsize=SEGSIZE set segment size in GB [[1]]], +PGAC_ARG_REQ(with, segsize, [ --with-segsize=SEGSIZE set table segment size in GB [[1]]], [segsize=$withval], [segsize=1]) # this expression is set up to avoid unnecessary integer overflow @@ -280,6 +280,61 @@ AC_DEFINE_UNQUOTED([RELSEG_SIZE], ${RELSEG_SIZE}, [ Changing RELSEG_SIZE requires an initdb. ]) +# +# WAL block size +# +AC_MSG_CHECKING([for WAL block size]) +PGAC_ARG_REQ(with, wal-blocksize, [ --with-wal-blocksize=BLOCKSIZE set WAL block size in kB [[8]]], + [wal_blocksize=$withval], + [wal_blocksize=8]) +case ${wal_blocksize} in + 1) XLOG_BLCKSZ=1024;; + 2) XLOG_BLCKSZ=2048;; + 4) XLOG_BLCKSZ=4096;; + 8) XLOG_BLCKSZ=8192;; + 16) XLOG_BLCKSZ=16384;; + 32) XLOG_BLCKSZ=32768;; + 64) XLOG_BLCKSZ=65536;; + *) AC_MSG_ERROR([Invalid WAL block size. Allowed values are 1,2,4,8,16,32,64.]) +esac +AC_MSG_RESULT([${wal_blocksize}kB]) + +AC_DEFINE_UNQUOTED([XLOG_BLCKSZ], ${XLOG_BLCKSZ}, [ + Size of a WAL file block. This need have no particular relation to BLCKSZ. + XLOG_BLCKSZ must be a power of 2, and if your system supports O_DIRECT I/O, + XLOG_BLCKSZ must be a multiple of the alignment requirement for direct-I/O + buffers, else direct I/O may fail. + + Changing XLOG_BLCKSZ requires an initdb. +]) + +# +# WAL segment size +# +AC_MSG_CHECKING([for WAL segment size]) +PGAC_ARG_REQ(with, wal-segsize, [ --with-wal-segsize=SEGSIZE set WAL segment size in MB [[16]]], + [wal_segsize=$withval], + [wal_segsize=16]) +case ${wal_segsize} in + 1) ;; + 2) ;; + 4) ;; + 8) ;; + 16) ;; + 32) ;; + 64) ;; + *) AC_MSG_ERROR([Invalid WAL segment size. Allowed values are 1,2,4,8,16,32,64.]) +esac +AC_MSG_RESULT([${wal_segsize}MB]) + +AC_DEFINE_UNQUOTED([XLOG_SEG_SIZE], [(${wal_segsize} * 1024 * 1024)], [ + XLOG_SEG_SIZE is the size of a single WAL file. This must be a power of 2 + and larger than XLOG_BLCKSZ (preferably, a great deal larger than + XLOG_BLCKSZ). + + Changing XLOG_SEG_SIZE requires an initdb. +]) + # # C compiler # diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml index d0933bf7d1..e6de85f8c7 100644 --- a/doc/src/sgml/installation.sgml +++ b/doc/src/sgml/installation.sgml @@ -1,4 +1,4 @@ - + <![%standalone-include[<productname>PostgreSQL</>]]> @@ -1103,6 +1103,34 @@ su - postgres </listitem> </varlistentry> + <varlistentry> + <term><option>--with-wal-segsize=<replaceable>SEGSIZE</replaceable></option></term> + <listitem> + <para> + Set the <firstterm>WAL segment size</>, in megabytes. This is + the size of each individual file in the WAL log. It may be useful + to adjust this size to control the granularity of WAL log shipping. + The default size is 16 megabytes. + The value must be a power of 2 between 1 and 64 (megabytes). + Note that changing this value requires an initdb. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><option>--with-wal-blocksize=<replaceable>BLOCKSIZE</replaceable></option></term> + <listitem> + <para> + Set the <firstterm>WAL block size</>, in kilobytes. This is the unit + of storage and I/O within the WAL log. The default, 8 kilobytes, + is suitable for most situations; but other values may be useful + in special cases. + The value must be a power of 2 between 1 and 64 (kilobytes). + Note that changing this value requires an initdb. + </para> + </listitem> + </varlistentry> + <varlistentry> <term><option>--disable-spinlocks</option></term> <listitem> diff --git a/doc/src/sgml/wal.sgml b/doc/src/sgml/wal.sgml index 090a133185..373aa961dc 100644 --- a/doc/src/sgml/wal.sgml +++ b/doc/src/sgml/wal.sgml @@ -1,4 +1,4 @@ -<!-- $PostgreSQL: pgsql/doc/src/sgml/wal.sgml,v 1.52 2007/12/29 17:55:07 momjian Exp $ --> +<!-- $PostgreSQL: pgsql/doc/src/sgml/wal.sgml,v 1.53 2008/05/02 19:52:37 tgl Exp $ --> <chapter id="wal"> <title>Reliability and the Write-Ahead Log @@ -487,8 +487,11 @@ WAL logs are stored in the directory pg_xlog under the data directory, as a set of - segment files, normally each 16 MB in size. Each segment is divided into - pages, normally 8 kB each. The log record headers are described in + segment files, normally each 16 MB in size (but the size can be changed + by altering the