aboutsummaryrefslogtreecommitdiff
path: root/src/bin/initdb/initdb.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-09-09 17:59:11 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2011-09-09 17:59:11 -0400
commitca4af308c32d03db5fbacb54d6e583ceb904f268 (patch)
tree352fb06319a1c8e3efd78acaca9cc8b8ff0e7eda /src/bin/initdb/initdb.c
parenta7801b62f21bd051444bd1119cd3745ecc8e14ec (diff)
downloadpostgresql-ca4af308c32d03db5fbacb54d6e583ceb904f268.tar.gz
postgresql-ca4af308c32d03db5fbacb54d6e583ceb904f268.zip
Simplify handling of the timezone GUC by making initdb choose the default.
We were doing some amazingly complicated things in order to avoid running the very expensive identify_system_timezone() procedure during GUC initialization. But there is an obvious fix for that, which is to do it once during initdb and have initdb install the system-specific default into postgresql.conf, as it already does for most other GUC variables that need system-environment-dependent defaults. This means that the timezone (and log_timezone) settings no longer have any magic behavior in the server. Per discussion.
Diffstat (limited to 'src/bin/initdb/initdb.c')
-rw-r--r--src/bin/initdb/initdb.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 1dbd6f603a3..e535fdad1e9 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -61,6 +61,9 @@
#include "getopt_long.h"
#include "miscadmin.h"
+/* Ideally this would be in a .h file, but it hardly seems worth the trouble */
+extern const char *select_default_timezone(const char *share_path);
+
/*
* these values are passed in by makefile defines
@@ -947,8 +950,9 @@ static void
setup_config(void)
{
char **conflines;
- char repltok[100];
+ char repltok[TZ_STRLEN_MAX + 100];
char path[MAXPGPATH];
+ const char *default_timezone;
fputs(_("creating configuration files ... "), stdout);
fflush(stdout);
@@ -1011,6 +1015,17 @@ setup_config(void)
"#default_text_search_config = 'pg_catalog.simple'",
repltok);
+ default_timezone = select_default_timezone(share_path);
+ if (default_timezone)
+ {
+ snprintf(repltok, sizeof(repltok), "timezone = '%s'",
+ escape_quotes(default_timezone));
+ conflines = replace_token(conflines, "#timezone = 'GMT'", repltok);
+ snprintf(repltok, sizeof(repltok), "log_timezone = '%s'",
+ escape_quotes(default_timezone));
+ conflines = replace_token(conflines, "#log_timezone = 'GMT'", repltok);
+ }
+
snprintf(path, sizeof(path), "%s/postgresql.conf", pg_data);
writefile(path, conflines);
@@ -2796,14 +2811,6 @@ main(int argc, char *argv[])
sprintf(pgdenv, "PGDATA=%s", pg_data);
putenv(pgdenv);
- /*
- * Also ensure that TZ is set, so that we don't waste time identifying the
- * system timezone each of the many times we start a standalone backend.
- * It's okay to use a hard-wired value here because nothing done during
- * initdb cares about the timezone setting.
- */
- putenv("TZ=GMT");
-
if ((ret = find_other_exec(argv[0], "postgres", PG_BACKEND_VERSIONSTR,
backend_exec)) < 0)
{