1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +03:00

Allow configuration files to be placed outside the data directory.

Add new postgresql.conf variables to point to data, pg_hba.conf, and
pg_ident.conf files.

Needs more documentation.
This commit is contained in:
Bruce Momjian
2004-07-11 00:18:45 +00:00
parent b4a98c5fcc
commit 130f89e93f
10 changed files with 303 additions and 81 deletions

View File

@@ -4,7 +4,7 @@
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.22 2004/05/26 15:07:38 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.23 2004/07/11 00:18:44 momjian Exp $
*/
%{
@@ -129,43 +129,24 @@ free_name_value_list(struct name_value_pair * list)
* function does not return if an error occurs. If an error occurs, no
* values will be changed.
*/
void
ProcessConfigFile(GucContext context)
static void
ReadConfigFile(char *filename, GucContext context)
{
int token, parse_state;
char *opt_name, *opt_value;
char *filename;
struct name_value_pair *item, *head, *tail;
int elevel;
FILE * fp;
Assert(context == PGC_POSTMASTER || context == PGC_BACKEND
|| context == PGC_SIGHUP);
Assert(DataDir);
elevel = (context == PGC_SIGHUP) ? DEBUG4 : ERROR;
/*
* Open file
*/
filename = malloc(strlen(DataDir) + strlen(CONFIG_FILENAME) + 2);
if (filename == NULL)
{
ereport(elevel,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
return;
}
sprintf(filename, "%s/" CONFIG_FILENAME, DataDir);
fp = AllocateFile(filename, "r");
if (!fp)
{
free(filename);
/* File not found is fine */
if (errno != ENOENT)
ereport(elevel,
(errcode_for_file_access(),
errmsg("could not open configuration file \"%s\": %m", CONFIG_FILENAME)));
ereport(elevel,
(errcode_for_file_access(),
errmsg("could not open configuration file \"%s\": %m", filename)));
return;
}
@@ -197,7 +178,8 @@ ProcessConfigFile(GucContext context)
token = yylex();
if (token != GUC_ID && token != GUC_STRING &&
token != GUC_INTEGER && token != GUC_REAL &&
token != GUC_INTEGER &&
token != GUC_REAL &&
token != GUC_UNQUOTED_STRING)
goto parse_error;
opt_value = strdup(yytext);
@@ -259,7 +241,6 @@ ProcessConfigFile(GucContext context)
}
FreeFile(fp);
free(filename);
/*
* Check if all options are valid
@@ -282,12 +263,11 @@ ProcessConfigFile(GucContext context)
parse_error:
FreeFile(fp);
free(filename);
free_name_value_list(head);
ereport(elevel,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error in file \"%s\" line %u, near token \"%s\"",
CONFIG_FILENAME, ConfigFileLineno, yytext)));
filename, ConfigFileLineno, yytext)));
return;
out_of_memory:
@@ -300,6 +280,65 @@ ProcessConfigFile(GucContext context)
return;
}
/*
* Function to read and process the configuration file. The
* parameter indicates the context that the file is being read
* (postmaster startup, backend startup, or SIGHUP). All options
* mentioned in the configuration file are set to new values. This
* function does not return if an error occurs. If an error occurs, no
* values will be changed.
*/
void
ProcessConfigFile(GucContext context)
{
char *filename;
Assert(context == PGC_POSTMASTER || context == PGC_BACKEND || context == PGC_SIGHUP);
/* Added for explicit config file */
if (user_pgconfig)
{
struct stat sb;
if (stat(user_pgconfig, &sb) != 0)
{
int elevel = (context == PGC_SIGHUP) ? DEBUG3 : ERROR;
elog(elevel, "Configuration file \"%s\" does not exist", user_pgconfig);
return;
}
if (S_ISDIR(sb.st_mode))
{
/* This will cause a small one time memory leak
* if the user also specifies hba_conf,
* ident_conf, and data_dir
*/
filename = malloc(strlen(user_pgconfig) + strlen(CONFIG_FILENAME) + 2);
sprintf(filename, "%s/%s", user_pgconfig, CONFIG_FILENAME);
user_pgconfig_is_dir = true;
}
else
filename = strdup(user_pgconfig); /* Use explicit file */
}
else
{
/* Use datadir for config */
filename = malloc(strlen(DataDir) + strlen(CONFIG_FILENAME) + 2);
sprintf(filename, "%s/%s", DataDir, CONFIG_FILENAME);
}
if (filename == NULL)
{
int elevel = (context == PGC_SIGHUP) ? DEBUG3 : ERROR;
elog(elevel, "out of memory");
return;
}
ReadConfigFile(filename, context);
free(filename);
}
/* ----------------

View File

@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.213 2004/07/05 23:14:14 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.214 2004/07/11 00:18:44 momjian Exp $
*
*--------------------------------------------------------------------
*/
@@ -57,6 +57,13 @@
#include "utils/pg_locale.h"
#include "pgstat.h"
char *guc_pgdata;
char *guc_hbafile;
char *guc_identfile;
char *external_pidfile;
char *user_pgconfig = NULL;
bool user_pgconfig_is_dir = false;
#ifndef PG_KRB_SRVTAB
#define PG_KRB_SRVTAB ""
@@ -107,6 +114,7 @@ static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
static bool assign_log_stats(bool newval, bool doit, GucSource source);
static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
static void ReadConfigFile(char *filename, GucContext context);
/*
* Debugging options
@@ -1701,15 +1709,40 @@ static struct config_string ConfigureNamesString[] =
NULL, assign_custom_variable_classes, NULL
},
{
{"pgdata", PGC_POSTMASTER, 0, gettext_noop("Sets the location of the data directory"), NULL},
&guc_pgdata,
NULL, NULL, NULL
},
{
{"hba_conf", PGC_SIGHUP, 0, gettext_noop("Sets the location of the \"hba\" configuration file"), NULL},
&guc_hbafile,
NULL, NULL, NULL
},
{
{"ident_conf", PGC_SIGHUP, 0, gettext_noop("Sets the location of the \"ident\" configuration file"), NULL},
&guc_identfile,
NULL, NULL, NULL
},
{
{"external_pidfile", PGC_POSTMASTER, 0, gettext_noop("Writes the postmaster PID to the specified file"), NULL},
&external_pidfile,
NULL, NULL, NULL
},
/* End-of-list marker */
{
{NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
}
};
/******** end of options list ********/
/*
* To allow continued support of obsolete names for GUC variables, we apply
* the following mappings to any unrecognized name. Note that an old name

View File

@@ -21,6 +21,16 @@
# "pg_ctl reload".
#---------------------------------------------------------------------------
# CONFIGURATION FILES
#---------------------------------------------------------------------------
# pgdata = '/usr/local/pgsql/data' # use data in another directory
# hba_conf = '/etc/pgsql/pg_hba.conf' # use hba info in another directory
# ident_conf = '/etc/pgsql/pg_ident.conf' # use ident info in another directory
# external_pidfile= '/var/run/postgresql.pid' # write an extra pid file
#---------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#---------------------------------------------------------------------------