summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2015-11-17 11:47:18 +0000
committerPeter Eisentraut2016-02-03 02:03:19 +0000
commitac7238dc0faccb0ad077aa9922df6e75b0b1bda3 (patch)
tree06f3036ee9ddcc06f277fe56a080cb3b3812b160
parent2808a2e0f3e7dd98f5dc3041183fd5f389e0a8e1 (diff)
Improve error reporting when location specified by postgres -D does not exist
Previously, the first error seen would be that postgresql.conf does not exist. But for the case where the whole directory does not exist, give an error message about that, together with a hint for how to create one.
-rw-r--r--src/backend/utils/misc/guc.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 38ba82fe4b6..b8d34b59f58 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -4463,6 +4463,17 @@ SelectConfigFiles(const char *userDoption, const char *progname)
else
configdir = make_absolute_path(getenv("PGDATA"));
+ if (configdir && stat(configdir, &stat_buf) != 0)
+ {
+ write_stderr("%s: could not access \"%s\": %s\n",
+ progname,
+ configdir,
+ strerror(errno));
+ if (errno == ENOENT)
+ write_stderr("Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
+ return false;
+ }
+
/*
* Find the configuration file: if config_file was specified on the
* command line, use it, else use configdir/postgresql.conf. In any case
@@ -4498,7 +4509,7 @@ SelectConfigFiles(const char *userDoption, const char *progname)
*/
if (stat(ConfigFileName, &stat_buf) != 0)
{
- write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
+ write_stderr("%s: could not access the server configuration file \"%s\": %s\n",
progname, ConfigFileName, strerror(errno));
free(configdir);
return false;