suppress automatic recovery after back crash

Started by Robert Haasover 15 years ago10 messages
#1Robert Haas
robertmhaas@gmail.com
1 attachment(s)

[moving from -performance to -hackers; original subject is: PostgreSQL
as a local in-memory cache]

On Thu, Jun 17, 2010 at 7:25 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Josh Berkus <josh@agliodbs.com> writes:

(a) and (d) are probably simple, if by "reprovisioning" you mean
"rm -rf $PGDATA; initdb".

Exactly.  Followed by "scp database_image".  Or heck, just replacing the
whole VM.

Right, that would work.  I don't think you really need to implement that
inside Postgres.  I would envision having the startup script do it, ie

       rm -rf $PGDATA
       cp -pr prepared-database-image $PGDATA

       # this loop exits when postmaster exits normally
       while ! postmaster ...
       do
               rm -rf $PGDATA
               cp -pr prepared-database-image $PGDATA
       done

Then all you need is a tweak to make the postmaster exit(1) after
a crash instead of trying to launch recovery.

This seems useful to me so here's a patch to implement it.

There didn't seem to be a suitable GUC category for it, until I
noticed that we have a currently-undocumented GUC called
exit_on_error. I thought it might make sense to document both that
and this in a new section called "Error Handling".

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company

Attachments:

guc_automatic_restart.patchapplication/octet-stream; name=guc_automatic_restart.patchDownload
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 04a6c41..124f08c 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5241,6 +5241,47 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
     </sect2>
    </sect1>
 
+   <sect1 id="runtime-config-error-handling">
+    <title>Error Handling</title>
+
+    <variablelist>
+
+     <varlistentry id="guc-exit-on-error" xreflabel="exit_on_error">
+      <term><varname>exit_on_error</varname> (<type>boolean</type>)</term>
+      <indexterm>
+       <primary><varname>exit_on_error</> configuration parameter</primary>
+      </indexterm>
+      <listitem>
+       <para>
+        If true, any error will terminate the current session.  Normally,
+        this is set to false, so that only FATAL errors will terminate the
+        session.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry id="guc-automatic-restart" xreflabel="automatic_restart">
+      <term><varname>automatic_restart</varname> (<type>boolean</type>)</term>
+      <indexterm>
+       <primary><varname>automatic_restart</> configuration parameter</primary>
+      </indexterm>
+      <listitem>
+       <para>
+        When set to true, which is the default, <productname>PostgreSQL</>
+        will automatically reinitialize after a backend crash.  Leaving this
+        value set to true is normally the best way to maximize the availability
+        of the database.  However, in some circumstances, such as when
+        <productname>PostgreSQL</> is being invoked by clusterware, it may be
+        useful to disable this behavior, so that the clusterware can gain
+        control and take any actions it deems appropriate.
+       </para>
+      </listitem>
+     </varlistentry>
+
+    </variablelist>
+
+   </sect1>
+
    <sect1 id="runtime-config-preset">
     <title>Preset Options</title>
 
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 7cf3a41..b04551c 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -203,6 +203,7 @@ bool		Db_user_namespace = false;
 
 bool		enable_bonjour = false;
 char	   *bonjour_name;
+bool		automatic_restart = true;
 
 /* PIDs of special child processes; 0 when not running */
 static pid_t StartupPID = 0,
@@ -3047,12 +3048,12 @@ PostmasterStateMachine(void)
 	}
 
 	/*
-	 * If recovery failed, wait for all non-syslogger children to exit, and
-	 * then exit postmaster. We don't try to reinitialize when recovery fails,
-	 * because more than likely it will just fail again and we will keep
-	 * trying forever.
+	 * If recovery failed, or if automatic restart has been disabled, wait for
+	 * all non-syslogger children to exit, and then exit postmaster. We don't
+	 * try to reinitialize when recovery fails, because more than likely it
+	 * will just fail again and we will keep trying forever.
 	 */
-	if (RecoveryError && pmState == PM_NO_CHILDREN)
+	if (pmState == PM_NO_CHILDREN && (RecoveryError || !automatic_restart))
 		ExitPostmaster(1);
 
 	/*
diff --git a/src/backend/utils/misc/check_guc b/src/backend/utils/misc/check_guc
index df597b4..5152b4e 100755
--- a/src/backend/utils/misc/check_guc
+++ b/src/backend/utils/misc/check_guc
@@ -16,7 +16,7 @@
 ## if an option is valid but shows up in only one file (guc.c but not
 ## postgresql.conf.sample), it should be listed here so that it 
 ## can be ignored
-INTENTIONALLY_NOT_INCLUDED="autocommit debug_deadlocks exit_on_error \
+INTENTIONALLY_NOT_INCLUDED="autocommit debug_deadlocks \
 is_superuser lc_collate lc_ctype lc_messages lc_monetary lc_numeric lc_time \
 pre_auth_delay role seed server_encoding server_version server_version_int \
 session_authorization trace_lock_oidmin trace_lock_table trace_locks trace_lwlocks \
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index b423d80..d34e0e0 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -548,6 +548,8 @@ const char *const config_group_names[] =
 	gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
 	/* COMPAT_OPTIONS_CLIENT */
 	gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
+	/* ERROR_HANDING */
+	gettext_noop("Error Handling"),
 	/* PRESET_OPTIONS */
 	gettext_noop("Preset Options"),
 	/* CUSTOM_OPTIONS */
@@ -811,17 +813,25 @@ static struct config_bool ConfigureNamesBool[] =
 #endif
 		assign_debug_assertions, NULL
 	},
+
 	{
-		/* currently undocumented, so don't show in SHOW ALL */
-		{"exit_on_error", PGC_USERSET, UNGROUPED,
-			gettext_noop("No description available."),
-			NULL,
-			GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
+		{"exit_on_error", PGC_USERSET, ERROR_HANDLING,
+			gettext_noop("Terminate session on any error."),
+			NULL
 		},
 		&ExitOnAnyError,
 		false, NULL, NULL
 	},
 	{
+		{"automatic_restart", PGC_SIGHUP, ERROR_HANDLING,
+			gettext_noop("Reinitialize after backend crash."),
+			NULL
+		},
+		&automatic_restart,
+		true, NULL, NULL
+	},
+
+	{
 		{"log_duration", PGC_SUSET, LOGGING_WHAT,
 			gettext_noop("Logs the duration of each completed SQL statement."),
 			NULL
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 5ea568a..189ccb1 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -514,6 +514,14 @@
 
 
 #------------------------------------------------------------------------------
+# ERROR HANDING
+#------------------------------------------------------------------------------
+
+#exit_on_error = false				# terminate session on any error?
+#automatic_restart = true			# reinitialize after backend crash?
+
+
+#------------------------------------------------------------------------------
 # CUSTOMIZED OPTIONS
 #------------------------------------------------------------------------------
 
diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h
index 56d7d8e..948e1a0 100644
--- a/src/include/postmaster/postmaster.h
+++ b/src/include/postmaster/postmaster.h
@@ -29,6 +29,7 @@ extern bool Log_connections;
 extern bool log_hostname;
 extern bool enable_bonjour;
 extern char *bonjour_name;
+extern bool automatic_restart;
 
 #ifdef WIN32
 extern HANDLE PostmasterHandle;
diff --git a/src/include/utils/guc_tables.h b/src/include/utils/guc_tables.h
index a4c32fa..c6c3d06 100644
--- a/src/include/utils/guc_tables.h
+++ b/src/include/utils/guc_tables.h
@@ -80,6 +80,7 @@ enum config_group
 	COMPAT_OPTIONS,
 	COMPAT_OPTIONS_PREVIOUS,
 	COMPAT_OPTIONS_CLIENT,
+	ERROR_HANDLING,
 	PRESET_OPTIONS,
 	CUSTOM_OPTIONS,
 	DEVELOPER_OPTIONS
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Haas (#1)
Re: suppress automatic recovery after back crash

Robert Haas <robertmhaas@gmail.com> writes:

On Thu, Jun 17, 2010 at 7:25 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Then all you need is a tweak to make the postmaster exit(1) after
a crash instead of trying to launch recovery.

This seems useful to me so here's a patch to implement it.

Hm, is it useful in the absence of the other components of the proposed
feature?

One stylistic gripe:

@@ -80,6 +80,7 @@ enum config_group
COMPAT_OPTIONS,
COMPAT_OPTIONS_PREVIOUS,
COMPAT_OPTIONS_CLIENT,
+ ERROR_HANDLING,
PRESET_OPTIONS,
CUSTOM_OPTIONS,
DEVELOPER_OPTIONS

Please spell that "ERROR_HANDLING_OPTIONS", both for consistency with
the other enum members and to avoid likely conflicts with other uses of
such a generic-looking identifier.

regards, tom lane

#3Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#2)
1 attachment(s)
Re: suppress automatic recovery after back crash

On Sun, Jun 27, 2010 at 9:02 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Robert Haas <robertmhaas@gmail.com> writes:

On Thu, Jun 17, 2010 at 7:25 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Then all you need is a tweak to make the postmaster exit(1) after
a crash instead of trying to launch recovery.

This seems useful to me so here's a patch to implement it.

Hm, is it useful in the absence of the other components of the proposed
feature?

I think so. People are already using PostgreSQL as a feature-rich
cache; the point of the other changes Josh mentioned is just to make
it more performant. Specifically, he mentioned: (a) Eliminate WAL
logging entirely, (b) Eliminate checkpointing, and (c) Turn off the
background writer. I'm worked on unlogged tables, which will take us
about as far as we're likely to go in the direction of (a), per the
discussion on -performance. I haven't thought too much about (b) and
(c) so I'm not sure how involved that is, or how far we get just by
setting bgwriter_lru_maxpagess=0 as Greg Smith suggested, but, again,
it's just a performance optimization of something people are already
doing.

One stylistic gripe:

@@ -80,6 +80,7 @@ enum config_group
       COMPAT_OPTIONS,
       COMPAT_OPTIONS_PREVIOUS,
       COMPAT_OPTIONS_CLIENT,
+       ERROR_HANDLING,
       PRESET_OPTIONS,
       CUSTOM_OPTIONS,
       DEVELOPER_OPTIONS

Please spell that "ERROR_HANDLING_OPTIONS", both for consistency with
the other enum members and to avoid likely conflicts with other uses of
such a generic-looking identifier.

I mulled over which of those names was better; updated version,
reflecting your proposed naming, attached.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company

Attachments:

guc_automatic_restart-v2.patchapplication/octet-stream; name=guc_automatic_restart-v2.patchDownload
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 04a6c41..124f08c 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5241,6 +5241,47 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
     </sect2>
    </sect1>
 
+   <sect1 id="runtime-config-error-handling">
+    <title>Error Handling</title>
+
+    <variablelist>
+
+     <varlistentry id="guc-exit-on-error" xreflabel="exit_on_error">
+      <term><varname>exit_on_error</varname> (<type>boolean</type>)</term>
+      <indexterm>
+       <primary><varname>exit_on_error</> configuration parameter</primary>
+      </indexterm>
+      <listitem>
+       <para>
+        If true, any error will terminate the current session.  Normally,
+        this is set to false, so that only FATAL errors will terminate the
+        session.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry id="guc-automatic-restart" xreflabel="automatic_restart">
+      <term><varname>automatic_restart</varname> (<type>boolean</type>)</term>
+      <indexterm>
+       <primary><varname>automatic_restart</> configuration parameter</primary>
+      </indexterm>
+      <listitem>
+       <para>
+        When set to true, which is the default, <productname>PostgreSQL</>
+        will automatically reinitialize after a backend crash.  Leaving this
+        value set to true is normally the best way to maximize the availability
+        of the database.  However, in some circumstances, such as when
+        <productname>PostgreSQL</> is being invoked by clusterware, it may be
+        useful to disable this behavior, so that the clusterware can gain
+        control and take any actions it deems appropriate.
+       </para>
+      </listitem>
+     </varlistentry>
+
+    </variablelist>
+
+   </sect1>
+
    <sect1 id="runtime-config-preset">
     <title>Preset Options</title>
 
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 7cf3a41..b04551c 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -203,6 +203,7 @@ bool		Db_user_namespace = false;
 
 bool		enable_bonjour = false;
 char	   *bonjour_name;
+bool		automatic_restart = true;
 
 /* PIDs of special child processes; 0 when not running */
 static pid_t StartupPID = 0,
@@ -3047,12 +3048,12 @@ PostmasterStateMachine(void)
 	}
 
 	/*
-	 * If recovery failed, wait for all non-syslogger children to exit, and
-	 * then exit postmaster. We don't try to reinitialize when recovery fails,
-	 * because more than likely it will just fail again and we will keep
-	 * trying forever.
+	 * If recovery failed, or if automatic restart has been disabled, wait for
+	 * all non-syslogger children to exit, and then exit postmaster. We don't
+	 * try to reinitialize when recovery fails, because more than likely it
+	 * will just fail again and we will keep trying forever.
 	 */
-	if (RecoveryError && pmState == PM_NO_CHILDREN)
+	if (pmState == PM_NO_CHILDREN && (RecoveryError || !automatic_restart))
 		ExitPostmaster(1);
 
 	/*
diff --git a/src/backend/utils/misc/check_guc b/src/backend/utils/misc/check_guc
index df597b4..5152b4e 100755
--- a/src/backend/utils/misc/check_guc
+++ b/src/backend/utils/misc/check_guc
@@ -16,7 +16,7 @@
 ## if an option is valid but shows up in only one file (guc.c but not
 ## postgresql.conf.sample), it should be listed here so that it 
 ## can be ignored
-INTENTIONALLY_NOT_INCLUDED="autocommit debug_deadlocks exit_on_error \
+INTENTIONALLY_NOT_INCLUDED="autocommit debug_deadlocks \
 is_superuser lc_collate lc_ctype lc_messages lc_monetary lc_numeric lc_time \
 pre_auth_delay role seed server_encoding server_version server_version_int \
 session_authorization trace_lock_oidmin trace_lock_table trace_locks trace_lwlocks \
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index b423d80..5cc8cdb 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -548,6 +548,8 @@ const char *const config_group_names[] =
 	gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
 	/* COMPAT_OPTIONS_CLIENT */
 	gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
+	/* ERROR_HANDING */
+	gettext_noop("Error Handling"),
 	/* PRESET_OPTIONS */
 	gettext_noop("Preset Options"),
 	/* CUSTOM_OPTIONS */
@@ -811,17 +813,25 @@ static struct config_bool ConfigureNamesBool[] =
 #endif
 		assign_debug_assertions, NULL
 	},
+
 	{
-		/* currently undocumented, so don't show in SHOW ALL */
-		{"exit_on_error", PGC_USERSET, UNGROUPED,
-			gettext_noop("No description available."),
-			NULL,
-			GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
+		{"exit_on_error", PGC_USERSET, ERROR_HANDLING_OPTIONS,
+			gettext_noop("Terminate session on any error."),
+			NULL
 		},
 		&ExitOnAnyError,
 		false, NULL, NULL
 	},
 	{
+		{"automatic_restart", PGC_SIGHUP, ERROR_HANDLING_OPTIONS,
+			gettext_noop("Reinitialize after backend crash."),
+			NULL
+		},
+		&automatic_restart,
+		true, NULL, NULL
+	},
+
+	{
 		{"log_duration", PGC_SUSET, LOGGING_WHAT,
 			gettext_noop("Logs the duration of each completed SQL statement."),
 			NULL
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 5ea568a..189ccb1 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -514,6 +514,14 @@
 
 
 #------------------------------------------------------------------------------
+# ERROR HANDING
+#------------------------------------------------------------------------------
+
+#exit_on_error = false				# terminate session on any error?
+#automatic_restart = true			# reinitialize after backend crash?
+
+
+#------------------------------------------------------------------------------
 # CUSTOMIZED OPTIONS
 #------------------------------------------------------------------------------
 
diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h
index 56d7d8e..948e1a0 100644
--- a/src/include/postmaster/postmaster.h
+++ b/src/include/postmaster/postmaster.h
@@ -29,6 +29,7 @@ extern bool Log_connections;
 extern bool log_hostname;
 extern bool enable_bonjour;
 extern char *bonjour_name;
+extern bool automatic_restart;
 
 #ifdef WIN32
 extern HANDLE PostmasterHandle;
diff --git a/src/include/utils/guc_tables.h b/src/include/utils/guc_tables.h
index a4c32fa..b577fd2 100644
--- a/src/include/utils/guc_tables.h
+++ b/src/include/utils/guc_tables.h
@@ -80,6 +80,7 @@ enum config_group
 	COMPAT_OPTIONS,
 	COMPAT_OPTIONS_PREVIOUS,
 	COMPAT_OPTIONS_CLIENT,
+	ERROR_HANDLING_OPTIONS,
 	PRESET_OPTIONS,
 	CUSTOM_OPTIONS,
 	DEVELOPER_OPTIONS
#4Fujii Masao
masao.fujii@gmail.com
In reply to: Robert Haas (#1)
Re: suppress automatic recovery after back crash

On Mon, Jun 28, 2010 at 9:54 AM, Robert Haas <robertmhaas@gmail.com> wrote:

This seems useful to me so here's a patch to implement it.

+1

This would be very useful for people who want to give a clusterware
control of postgres.

Regards,

--
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center

#5Fujii Masao
masao.fujii@gmail.com
In reply to: Robert Haas (#3)
Re: suppress automatic recovery after back crash

On Mon, Jun 28, 2010 at 9:09 PM, Robert Haas <robertmhaas@gmail.com> wrote:

I mulled over which of those names was better; updated version,
reflecting your proposed naming, attached.

I read the patch and found some small typos.

+        If true, any error will terminate the current session.  Normally,
+        this is set to false, so that only FATAL errors will terminate the

"s/Normally/By default" seems better.

+        When set to true, which is the default, <productname>PostgreSQL</>
+        will automatically reinitialize after a backend crash.  Leaving this
+        value set to true is normally the best way to maximize the availability
+        of the database.  However, in some circumstances, such as when
+        <productname>PostgreSQL</> is being invoked by clusterware, it may be
+        useful to disable this behavior, so that the clusterware can gain
+        control and take any actions it deems appropriate.

We should add something like?:

---------
Even if this value is set to true, a backend crash during hot standby doesn't
reinitialize the database.
---------

+ /* ERROR_HANDING */
+ gettext_noop("Error Handling"),

You seems to have forgotten to reflect Tom's proposal here.

#------------------------------------------------------------------------------
+# ERROR HANDING
+#------------------------------------------------------------------------------

Typo: s/HANDING/HANDLING

Regards,

--
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center

#6Robert Haas
robertmhaas@gmail.com
In reply to: Fujii Masao (#5)
1 attachment(s)
Re: suppress automatic recovery after back crash

On Wed, Jul 14, 2010 at 3:41 AM, Fujii Masao <masao.fujii@gmail.com> wrote:

I read the patch and found some small typos.

Thanks. Corrected version attached.

We should add something like?:

---------
Even if this value is set to true, a backend crash during hot standby doesn't
reinitialize the database.
---------

Is that actually true? AFAICS, RecoveryError only gets set if the
*startup* process crashes.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company

Attachments:

guc_automatic_restart-v3.patchtext/x-patch; charset=US-ASCII; name=guc_automatic_restart-v3.patchDownload
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 1aff181..7eb6521 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5299,6 +5299,47 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
     </sect2>
    </sect1>
 
+   <sect1 id="runtime-config-error-handling">
+    <title>Error Handling</title>
+
+    <variablelist>
+
+     <varlistentry id="guc-exit-on-error" xreflabel="exit_on_error">
+      <term><varname>exit_on_error</varname> (<type>boolean</type>)</term>
+      <indexterm>
+       <primary><varname>exit_on_error</> configuration parameter</primary>
+      </indexterm>
+      <listitem>
+       <para>
+        If true, any error will terminate the current session.  By default,
+        this is set to false, so that only FATAL errors will terminate the
+        session.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry id="guc-automatic-restart" xreflabel="automatic_restart">
+      <term><varname>automatic_restart</varname> (<type>boolean</type>)</term>
+      <indexterm>
+       <primary><varname>automatic_restart</> configuration parameter</primary>
+      </indexterm>
+      <listitem>
+       <para>
+        When set to true, which is the default, <productname>PostgreSQL</>
+        will automatically reinitialize after a backend crash.  Leaving this
+        value set to true is normally the best way to maximize the availability
+        of the database.  However, in some circumstances, such as when
+        <productname>PostgreSQL</> is being invoked by clusterware, it may be
+        useful to disable this behavior, so that the clusterware can gain
+        control and take any actions it deems appropriate.
+       </para>
+      </listitem>
+     </varlistentry>
+
+    </variablelist>
+
+   </sect1>
+
    <sect1 id="runtime-config-preset">
     <title>Preset Options</title>
 
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 11f5022..7e911c1 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -203,6 +203,7 @@ bool		Db_user_namespace = false;
 
 bool		enable_bonjour = false;
 char	   *bonjour_name;
+bool		automatic_restart = true;
 
 /* PIDs of special child processes; 0 when not running */
 static pid_t StartupPID = 0,
@@ -3048,12 +3049,12 @@ PostmasterStateMachine(void)
 	}
 
 	/*
-	 * If recovery failed, wait for all non-syslogger children to exit, and
-	 * then exit postmaster. We don't try to reinitialize when recovery fails,
-	 * because more than likely it will just fail again and we will keep
-	 * trying forever.
+	 * If recovery failed, or if automatic restart has been disabled, wait for
+	 * all non-syslogger children to exit, and then exit postmaster. We don't
+	 * try to reinitialize when recovery fails, because more than likely it
+	 * will just fail again and we will keep trying forever.
 	 */
-	if (RecoveryError && pmState == PM_NO_CHILDREN)
+	if (pmState == PM_NO_CHILDREN && (RecoveryError || !automatic_restart))
 		ExitPostmaster(1);
 
 	/*
diff --git a/src/backend/utils/misc/check_guc b/src/backend/utils/misc/check_guc
index df597b4..5152b4e 100755
--- a/src/backend/utils/misc/check_guc
+++ b/src/backend/utils/misc/check_guc
@@ -16,7 +16,7 @@
 ## if an option is valid but shows up in only one file (guc.c but not
 ## postgresql.conf.sample), it should be listed here so that it 
 ## can be ignored
-INTENTIONALLY_NOT_INCLUDED="autocommit debug_deadlocks exit_on_error \
+INTENTIONALLY_NOT_INCLUDED="autocommit debug_deadlocks \
 is_superuser lc_collate lc_ctype lc_messages lc_monetary lc_numeric lc_time \
 pre_auth_delay role seed server_encoding server_version server_version_int \
 session_authorization trace_lock_oidmin trace_lock_table trace_locks trace_lwlocks \
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index e839639..bae5ae9 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -548,6 +548,8 @@ const char *const config_group_names[] =
 	gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
 	/* COMPAT_OPTIONS_CLIENT */
 	gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
+	/* ERROR_HANDLING */
+	gettext_noop("Error Handling"),
 	/* PRESET_OPTIONS */
 	gettext_noop("Preset Options"),
 	/* CUSTOM_OPTIONS */
@@ -811,17 +813,25 @@ static struct config_bool ConfigureNamesBool[] =
 #endif
 		assign_debug_assertions, NULL
 	},
+
 	{
-		/* currently undocumented, so don't show in SHOW ALL */
-		{"exit_on_error", PGC_USERSET, UNGROUPED,
-			gettext_noop("No description available."),
-			NULL,
-			GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
+		{"exit_on_error", PGC_USERSET, ERROR_HANDLING_OPTIONS,
+			gettext_noop("Terminate session on any error."),
+			NULL
 		},
 		&ExitOnAnyError,
 		false, NULL, NULL
 	},
 	{
+		{"automatic_restart", PGC_SIGHUP, ERROR_HANDLING_OPTIONS,
+			gettext_noop("Reinitialize after backend crash."),
+			NULL
+		},
+		&automatic_restart,
+		true, NULL, NULL
+	},
+
+	{
 		{"log_duration", PGC_SUSET, LOGGING_WHAT,
 			gettext_noop("Logs the duration of each completed SQL statement."),
 			NULL
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index a3b1457..c2cfbe3 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -518,6 +518,14 @@
 
 
 #------------------------------------------------------------------------------
+# ERROR HANDLING
+#------------------------------------------------------------------------------
+
+#exit_on_error = false				# terminate session on any error?
+#automatic_restart = true			# reinitialize after backend crash?
+
+
+#------------------------------------------------------------------------------
 # CUSTOMIZED OPTIONS
 #------------------------------------------------------------------------------
 
diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h
index 56d7d8e..948e1a0 100644
--- a/src/include/postmaster/postmaster.h
+++ b/src/include/postmaster/postmaster.h
@@ -29,6 +29,7 @@ extern bool Log_connections;
 extern bool log_hostname;
 extern bool enable_bonjour;
 extern char *bonjour_name;
+extern bool automatic_restart;
 
 #ifdef WIN32
 extern HANDLE PostmasterHandle;
diff --git a/src/include/utils/guc_tables.h b/src/include/utils/guc_tables.h
index a4c32fa..b577fd2 100644
--- a/src/include/utils/guc_tables.h
+++ b/src/include/utils/guc_tables.h
@@ -80,6 +80,7 @@ enum config_group
 	COMPAT_OPTIONS,
 	COMPAT_OPTIONS_PREVIOUS,
 	COMPAT_OPTIONS_CLIENT,
+	ERROR_HANDLING_OPTIONS,
 	PRESET_OPTIONS,
 	CUSTOM_OPTIONS,
 	DEVELOPER_OPTIONS
#7Fujii Masao
masao.fujii@gmail.com
In reply to: Robert Haas (#6)
Re: suppress automatic recovery after back crash

On Wed, Jul 14, 2010 at 11:59 PM, Robert Haas <robertmhaas@gmail.com> wrote:

On Wed, Jul 14, 2010 at 3:41 AM, Fujii Masao <masao.fujii@gmail.com> wrote:

I read the patch and found some small typos.

Thanks.  Corrected version attached.

We should add something like?:

---------
Even if this value is set to true, a backend crash during hot standby doesn't
reinitialize the database.
---------

Is that actually true? AFAICS, RecoveryError only gets set if the
*startup* process crashes.

Oh, true. Sorry for noise.

I changed the status of the patch to "ready for committer".

Regards,

--
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center

#8Simon Riggs
simon@2ndQuadrant.com
In reply to: Robert Haas (#1)
Re: suppress automatic recovery after back crash

On Sun, 2010-06-27 at 20:54 -0400, Robert Haas wrote:

automatic_restart = true # reinitialize after backend crash?

"automatic_restart" makes me think "when does that happen?".

Can we call this "restart_after_crash"? Or similar. So we are explicit
about when the restart will kick in.

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Training and Services

#9Tom Lane
tgl@sss.pgh.pa.us
In reply to: Simon Riggs (#8)
Re: suppress automatic recovery after back crash

Simon Riggs <simon@2ndQuadrant.com> writes:

On Sun, 2010-06-27 at 20:54 -0400, Robert Haas wrote:

automatic_restart = true # reinitialize after backend crash?

"automatic_restart" makes me think "when does that happen?".

Can we call this "restart_after_crash"? Or similar.

+1. "automatic_restart" is close to content-free.

regards, tom lane

#10Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#9)
Re: suppress automatic recovery after back crash

On Sat, Jul 17, 2010 at 10:16 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Simon Riggs <simon@2ndQuadrant.com> writes:

On Sun, 2010-06-27 at 20:54 -0400, Robert Haas wrote:

automatic_restart = true      # reinitialize after backend crash?

"automatic_restart" makes me think "when does that happen?".

Can we call this "restart_after_crash"? Or similar.

+1.  "automatic_restart" is close to content-free.

OK, committed that way.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company