Skip to content

Commit

Permalink
Improve error messages for missing configuration files. (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimCitus committed Aug 3, 2021
1 parent 0a6777b commit 27a41bf
Showing 1 changed file with 43 additions and 37 deletions.
80 changes: 43 additions & 37 deletions src/bin/pg_autoctl/debian.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,24 @@ debian_find_postgres_configuration_files(PostgresSetup *pgSetup,
return true;
}

/* is it a debian postgres-common style setup then? */
if (debian_init_postgres_config_files(pgSetup,
&debianConfFiles,
PG_CONFIG_TYPE_DEBIAN))
/*
* Is it a debian postgresql-common style setup then?
*
* We only search for debian style setup when the main postgresql.conf file
* was not found. The previous call to debian_init_postgres_config_files
* might see a partial failure because of e.g. missing only pg_ident.conf.
*/
if (!file_exists(postgresConfFiles.conf))
{
/* so we're dealing with a "normal" Postgres installation */
*pgConfigFiles = debianConfFiles;
if (debian_init_postgres_config_files(pgSetup,
&debianConfFiles,
PG_CONFIG_TYPE_DEBIAN))
{
/* so we're dealing with a "debian style" Postgres installation */
*pgConfigFiles = debianConfFiles;

return true;
return true;
}
}

/* well that's all we know how to detect at this point */
Expand Down Expand Up @@ -218,21 +227,7 @@ debian_init_postgres_config_files(PostgresSetup *pgSetup,
initPostgresConfigFiles(pgdata, pgConfigFiles,
PG_CONFIG_TYPE_POSTGRES);

if (postgresConfigFilesAllExist(pgConfigFiles))
{
return true;
}
else
{
/*
* WARN the user about the unexpected nature of our setup here,
* even if we then move on to make it the way we expect it.
*/
log_warn("Failed to find Postgres configuration files in PGDATA, "
"as expected: \"%s\" does not exists",
pgConfigFiles->conf);
return false;
}
return postgresConfigFilesAllExist(pgConfigFiles);
}

case PG_CONFIG_TYPE_DEBIAN:
Expand All @@ -251,21 +246,7 @@ debian_init_postgres_config_files(PostgresSetup *pgSetup,
initPostgresConfigFiles(debPathnames.confDirectory,
pgConfigFiles, PG_CONFIG_TYPE_DEBIAN);

if (postgresConfigFilesAllExist(pgConfigFiles))
{
return true;
}
else
{
/*
* WARN the user about the unexpected nature of our setup here,
* even if we then move on to make it the way we expect it.
*/
log_warn("Failed to find Postgres configuration files in PGDATA, "
"as expected: \"%s\" does not exists",
pgConfigFiles->conf);
return false;
}
return postgresConfigFilesAllExist(pgConfigFiles);
}
}

Expand Down Expand Up @@ -501,6 +482,31 @@ initPostgresConfigFiles(const char *dirname,
static bool
postgresConfigFilesAllExist(PostgresConfigFiles *pgConfigFiles)
{
/*
* WARN the user about the unexpected nature of our setup here, even if we
* then move on to make it the way we expect it.
*/
if (!file_exists(pgConfigFiles->conf))
{
log_warn("Failed to find Postgres configuration files in PGDATA, "
"as expected: \"%s\" does not exists",
pgConfigFiles->conf);
}

if (!file_exists(pgConfigFiles->ident))
{
log_warn("Failed to find Postgres configuration files in PGDATA, "
"as expected: \"%s\" does not exists",
pgConfigFiles->ident);
}

if (!file_exists(pgConfigFiles->hba))
{
log_warn("Failed to find Postgres configuration files in PGDATA, "
"as expected: \"%s\" does not exists",
pgConfigFiles->hba);
}

return file_exists(pgConfigFiles->conf) &&
file_exists(pgConfigFiles->ident) &&
file_exists(pgConfigFiles->hba);
Expand Down

0 comments on commit 27a41bf

Please sign in to comment.