Skip to content

Commit 5ffaa90

Browse files
committed
Add restart_after_crash GUC.
Normally, we automatically restart after a backend crash, but in some cases when PostgreSQL is invoked by clusterware it may be desirable to suppress this behavior, so we provide an option which does this. Since no existing GUC group quite fits, create a new group called "error handling options" for this and the previously undocumented GUC exit_on_error, which is now documented. Review by Fujii Masao.
1 parent 0839f31 commit 5ffaa90

File tree

7 files changed

+79
-16
lines changed

7 files changed

+79
-16
lines changed

doc/src/sgml/config.sgml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.297 2010/07/20 00:34:44 rhaas Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.298 2010/07/20 00:47:52 rhaas Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -5330,6 +5330,47 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
53305330
</sect2>
53315331
</sect1>
53325332

5333+
<sect1 id="runtime-config-error-handling">
5334+
<title>Error Handling</title>
5335+
5336+
<variablelist>
5337+
5338+
<varlistentry id="guc-exit-on-error" xreflabel="exit_on_error">
5339+
<term><varname>exit_on_error</varname> (<type>boolean</type>)</term>
5340+
<indexterm>
5341+
<primary><varname>exit_on_error</> configuration parameter</primary>
5342+
</indexterm>
5343+
<listitem>
5344+
<para>
5345+
If true, any error will terminate the current session. By default,
5346+
this is set to false, so that only FATAL errors will terminate the
5347+
session.
5348+
</para>
5349+
</listitem>
5350+
</varlistentry>
5351+
5352+
<varlistentry id="guc-restart-after-crash" xreflabel="restart_after_crash">
5353+
<term><varname>restart_after_crash</varname> (<type>boolean</type>)</term>
5354+
<indexterm>
5355+
<primary><varname>restart_after_crash</> configuration parameter</primary>
5356+
</indexterm>
5357+
<listitem>
5358+
<para>
5359+
When set to true, which is the default, <productname>PostgreSQL</>
5360+
will automatically reinitialize after a backend crash. Leaving this
5361+
value set to true is normally the best way to maximize the availability
5362+
of the database. However, in some circumstances, such as when
5363+
<productname>PostgreSQL</> is being invoked by clusterware, it may be
5364+
useful to disable this behavior, so that the clusterware can gain
5365+
control and take any actions it deems appropriate.
5366+
</para>
5367+
</listitem>
5368+
</varlistentry>
5369+
5370+
</variablelist>
5371+
5372+
</sect1>
5373+
53335374
<sect1 id="runtime-config-preset">
53345375
<title>Preset Options</title>
53355376

src/backend/postmaster/postmaster.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.614 2010/07/06 19:18:57 momjian Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.615 2010/07/20 00:47:52 rhaas Exp $
4141
*
4242
* NOTES
4343
*
@@ -203,6 +203,7 @@ bool Db_user_namespace = false;
203203

204204
bool enable_bonjour = false;
205205
char *bonjour_name;
206+
bool restart_after_crash = true;
206207

207208
/* PIDs of special child processes; 0 when not running */
208209
static pid_t StartupPID = 0,
@@ -3048,12 +3049,13 @@ PostmasterStateMachine(void)
30483049
}
30493050

30503051
/*
3051-
* If recovery failed, wait for all non-syslogger children to exit, and
3052-
* then exit postmaster. We don't try to reinitialize when recovery fails,
3053-
* because more than likely it will just fail again and we will keep
3054-
* trying forever.
3052+
* If recovery failed, or the user does not want an automatic restart after
3053+
* backend crashes, wait for all non-syslogger children to exit, and then
3054+
* exit postmaster. We don't try to reinitialize when recovery fails,
3055+
* because more than likely it will just fail again and we will keep trying
3056+
* forever.
30553057
*/
3056-
if (RecoveryError && pmState == PM_NO_CHILDREN)
3058+
if (pmState == PM_NO_CHILDREN && (RecoveryError || !restart_after_crash))
30573059
ExitPostmaster(1);
30583060

30593061
/*

src/backend/utils/misc/check_guc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
## if an option is valid but shows up in only one file (guc.c but not
1717
## postgresql.conf.sample), it should be listed here so that it
1818
## can be ignored
19-
INTENTIONALLY_NOT_INCLUDED="autocommit debug_deadlocks exit_on_error \
19+
INTENTIONALLY_NOT_INCLUDED="autocommit debug_deadlocks \
2020
is_superuser lc_collate lc_ctype lc_messages lc_monetary lc_numeric lc_time \
2121
pre_auth_delay role seed server_encoding server_version server_version_int \
2222
session_authorization trace_lock_oidmin trace_lock_table trace_locks trace_lwlocks \

src/backend/utils/misc/guc.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.563 2010/07/20 00:34:44 rhaas Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.564 2010/07/20 00:47:53 rhaas Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -550,6 +550,8 @@ const char *const config_group_names[] =
550550
gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
551551
/* COMPAT_OPTIONS_CLIENT */
552552
gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
553+
/* ERROR_HANDLING */
554+
gettext_noop("Error Handling"),
553555
/* PRESET_OPTIONS */
554556
gettext_noop("Preset Options"),
555557
/* CUSTOM_OPTIONS */
@@ -813,16 +815,24 @@ static struct config_bool ConfigureNamesBool[] =
813815
#endif
814816
assign_debug_assertions, NULL
815817
},
818+
816819
{
817-
/* currently undocumented, so don't show in SHOW ALL */
818-
{"exit_on_error", PGC_USERSET, UNGROUPED,
819-
gettext_noop("No description available."),
820-
NULL,
821-
GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
820+
{"exit_on_error", PGC_USERSET, ERROR_HANDLING_OPTIONS,
821+
gettext_noop("Terminate session on any error."),
822+
NULL
822823
},
823824
&ExitOnAnyError,
824825
false, NULL, NULL
825826
},
827+
{
828+
{"restart_after_crash", PGC_SIGHUP, ERROR_HANDLING_OPTIONS,
829+
gettext_noop("Reinitialize after backend crash."),
830+
NULL
831+
},
832+
&restart_after_crash,
833+
true, NULL, NULL
834+
},
835+
826836
{
827837
{"log_duration", PGC_SUSET, LOGGING_WHAT,
828838
gettext_noop("Logs the duration of each completed SQL statement."),

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,14 @@
519519
#transform_null_equals = off
520520

521521

522+
#------------------------------------------------------------------------------
523+
# ERROR HANDLING
524+
#------------------------------------------------------------------------------
525+
526+
#exit_on_error = false # terminate session on any error?
527+
#restart_after_crash = true # reinitialize after backend crash?
528+
529+
522530
#------------------------------------------------------------------------------
523531
# CUSTOMIZED OPTIONS
524532
#------------------------------------------------------------------------------

src/include/postmaster/postmaster.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/postmaster/postmaster.h,v 1.22 2010/01/02 16:58:08 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/postmaster/postmaster.h,v 1.23 2010/07/20 00:47:53 rhaas Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -29,6 +29,7 @@ extern bool Log_connections;
2929
extern bool log_hostname;
3030
extern bool enable_bonjour;
3131
extern char *bonjour_name;
32+
extern bool restart_after_crash;
3233

3334
#ifdef WIN32
3435
extern HANDLE PostmasterHandle;

src/include/utils/guc_tables.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.49 2010/06/15 07:52:11 itagaki Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.50 2010/07/20 00:47:53 rhaas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -80,6 +80,7 @@ enum config_group
8080
COMPAT_OPTIONS,
8181
COMPAT_OPTIONS_PREVIOUS,
8282
COMPAT_OPTIONS_CLIENT,
83+
ERROR_HANDLING_OPTIONS,
8384
PRESET_OPTIONS,
8485
CUSTOM_OPTIONS,
8586
DEVELOPER_OPTIONS

0 commit comments

Comments
 (0)