From 7a97abe818798b710d468e2994e211227c95e0d1 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu, 10 Jul 2008 22:08:17 +0000
Subject: [PATCH] Add unchangeable GUC "variables" segment_size,
 wal_block_size, and wal_segment_size to make those configuration parameters
 available to clients, in the same way that block_size was previously exposed.
  Bernd Helmle, with comments from Abhijit Menon-Sen and some further tweaking
 by me.

---
 doc/src/sgml/config.sgml     | 50 ++++++++++++++++++++++++++++++++++--
 src/backend/utils/misc/guc.c | 38 ++++++++++++++++++++++++++-
 2 files changed, 85 insertions(+), 3 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 6a0f039e719..d212d084d8c 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.182 2008/07/01 21:49:04 momjian Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.183 2008/07/10 22:08:17 tgl Exp $ -->
 
 <chapter Id="runtime-config">
   <title>Server Configuration</title>
@@ -4865,6 +4865,22 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-segment-size" xreflabel="segment_size">
+      <term><varname>segment_size</varname> (<type>integer</type>)</term>
+      <indexterm>
+       <primary><varname>segment_size</> configuration parameter</primary>
+      </indexterm>
+      <listitem>
+       <para>
+        Reports the number of blocks (pages) that can be stored within a file
+        segment.  It is determined by the value of <literal>RELSEG_SIZE</>
+        when building the server.  The maximum size of a segment file in bytes
+        is equal to <varname>segment_size</> multiplied by
+        <varname>block_size</>; by default this is 1GB.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry id="guc-server-encoding" xreflabel="server_encoding">
       <term><varname>server_encoding</varname> (<type>string</type>)</term>
       <indexterm>
@@ -4901,12 +4917,42 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
       </indexterm>
       <listitem>
        <para>
-        Reports the version number of the server as an integer. It is determined 
+        Reports the version number of the server as an integer. It is determined
         by the value of <literal>PG_VERSION_NUM</> when building the server.
        </para>
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-wal-block-size" xreflabel="wal_block_size">
+      <term><varname>wal_block_size</varname> (<type>integer</type>)</term>
+      <indexterm>
+       <primary><varname>wal_block_size</> configuration parameter</primary>
+      </indexterm>
+      <listitem>
+       <para>
+        Reports the size of a WAL disk block.  It is determined by the value
+        of <literal>XLOG_BLCKSZ</> when building the server. The default value
+        is 8192 bytes.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry id="guc-wal-segment-size" xreflabel="wal_segment_size">
+      <term><varname>wal_segment_size</varname> (<type>integer</type>)</term>
+      <indexterm>
+       <primary><varname>wal_segment_size</> configuration parameter</primary>
+      </indexterm>
+      <listitem>
+       <para>
+        Reports the number of blocks (pages) in a WAL segment file.
+        The total size of a WAL segment file in bytes is equal to
+        <varname>wal_segment_size</> multiplied by <varname>wal_block_size</>;
+        by default this is 16MB.  See <xref linkend="wal-configuration"> for
+        more information.
+       </para>
+      </listitem>
+     </varlistentry>
+
     </variablelist>
    </sect1>
 
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index ddf9d424024..8b072895b1e 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -10,7 +10,7 @@
  * Written by Peter Eisentraut <peter_e@gmx.net>.
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.463 2008/07/08 02:07:29 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.464 2008/07/10 22:08:17 tgl Exp $
  *
  *--------------------------------------------------------------------
  */
@@ -377,6 +377,9 @@ static int	max_function_args;
 static int	max_index_keys;
 static int	max_identifier_length;
 static int	block_size;
+static int	segment_size;
+static int	wal_block_size;
+static int	wal_segment_size;
 static bool integer_datetimes;
 
 /* should be static, but commands/variable.c needs to get at these */
@@ -1753,6 +1756,39 @@ static struct config_int ConfigureNamesInt[] =
 		BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
 	},
 
+	{
+		{"segment_size", PGC_INTERNAL, PRESET_OPTIONS,
+		    gettext_noop("Shows the number of pages per disk file."),
+		    NULL,
+		    GUC_UNIT_BLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
+		},
+		&segment_size,
+		RELSEG_SIZE, RELSEG_SIZE, RELSEG_SIZE, NULL, NULL
+	},
+
+	{
+		{"wal_block_size", PGC_INTERNAL, PRESET_OPTIONS,
+			gettext_noop("Shows the block size in the write ahead log."),
+			NULL,
+			GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
+		},
+		&wal_block_size,
+		XLOG_BLCKSZ, XLOG_BLCKSZ, XLOG_BLCKSZ, NULL, NULL
+	},
+
+	{
+		{"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS,
+			gettext_noop("Shows the number of pages per write ahead log segment."),
+			NULL,
+			GUC_UNIT_XBLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
+		},
+		&wal_segment_size,
+		(XLOG_SEG_SIZE / XLOG_BLCKSZ), 
+		(XLOG_SEG_SIZE / XLOG_BLCKSZ), 
+		(XLOG_SEG_SIZE / XLOG_BLCKSZ),
+		NULL, NULL
+	},
+
 	{
 		{"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
 			gettext_noop("Time to sleep between autovacuum runs."),
-- 
GitLab