If no configuration is specified, postmaster operates as it always has.
The configuration file is specified with the "-C" parameter, as:
postmaster -C /somepath/somefile.conf
Within the configuration file, there are three new parameters: data_dir, hba_conf, and ident_conf. They are used as:
hba_conf = 'pathanme_to_pg_hba.conf'
ident_conf='pathname_to_pg_ident.conf'
data_dir='path_to_data'
If the above parameters are not specified, then the default is to look for these file in the PGDATA directory.
Command line arguments take precedent over configuration file.
This patch is not a be-all end-all of configuration. It should be able to fit PostgreSQL into a FHS with the exception of the '/var/run' requirement.
diff -u -r postgresql-7.3.2/src/backend/libpq/hba.c postgresql-7.3.2.ec/src/backend/libpq/hba.c --- postgresql-7.3.2/src/backend/libpq/hba.c Sat Dec 14 13:49:43 2002 +++ postgresql-7.3.2.ec/src/backend/libpq/hba.c Thu Feb 13 12:15:16 2003 @@ -35,6 +35,7 @@ #include "miscadmin.h" #include "nodes/pg_list.h" #include "storage/fd.h" +#include "utils/guc.h" #define IDENT_USERNAME_MAX 512 @@ -837,10 +838,20 @@ if (hba_lines) free_lines(&hba_lines); - /* Put together the full pathname to the config file. */ - bufsize = (strlen(DataDir) + strlen(CONF_FILE) + 2) * sizeof(char); - conf_file = (char *) palloc(bufsize); - snprintf(conf_file, bufsize, "%s/%s", DataDir, CONF_FILE); + /* Explicit HBA in config file */ + if(explicit_hbafile && strlen(explicit_hbafile)) + { + bufsize = strlen(explicit_hbafile)+1; + conf_file = (char *) palloc(bufsize); + strcpy(conf_file, explicit_hbafile); + } + else + { + /* put together the full pathname to the config file */ + bufsize = (strlen(DataDir) + strlen(CONF_FILE) + 2) * sizeof(char); + conf_file = (char *) palloc(bufsize); + snprintf(conf_file, bufsize, "%s/%s", DataDir, CONF_FILE); + } file = AllocateFile(conf_file, "r"); if (file == NULL) @@ -979,10 +990,20 @@ if (ident_lines) free_lines(&ident_lines); - /* put together the full pathname to the map file */ - bufsize = (strlen(DataDir) + strlen(USERMAP_FILE) + 2) * sizeof(char); - map_file = (char *) palloc(bufsize); - snprintf(map_file, bufsize, "%s/%s", DataDir, USERMAP_FILE); + /* Explicit IDENT in config file */ + if(explicit_identfile && strlen(explicit_identfile)) + { + bufsize = strlen(explicit_identfile)+1; + map_file = (char *) palloc(bufsize); + strcpy(map_file, explicit_identfile); + } + else + { + /* put together the full pathname to the map file */ + bufsize = (strlen(DataDir) + strlen(USERMAP_FILE) + 2) * sizeof(char); + map_file = (char *) palloc(bufsize); + snprintf(map_file, bufsize, "%s/%s", DataDir, USERMAP_FILE); + } file = AllocateFile(map_file, "r"); if (file == NULL) diff -u -r postgresql-7.3.2/src/backend/postmaster/postmaster.c postgresql-7.3.2.ec/src/backend/postmaster/postmaster.c --- postgresql-7.3.2/src/backend/postmaster/postmaster.c Wed Jan 15 19:27:17 2003 +++ postgresql-7.3.2.ec/src/backend/postmaster/postmaster.c Thu Feb 13 22:53:08 +2003 @@ -421,7 +421,7 @@ opterr = 1; - while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:Ss-:")) != -1) + while ((opt = getopt(argc, argv, "A:a:B:b:C:c:D:d:Fh:ik:lm:MN:no:p:Ss-:")) != +-1) { switch (opt) { @@ -441,6 +441,9 @@ case 'b': /* Can no longer set the backend executable file to use. */ break; + case 'C': // MLW + explicit_pgconfig = optarg; + break; case 'D': potential_DataDir = optarg; break; @@ -564,13 +567,23 @@ ExitPostmaster(1); } - /* - * Now we can set the data directory, and then read postgresql.conf. - */ - checkDataDir(potential_DataDir); /* issues error messages */ - SetDataDir(potential_DataDir); - - ProcessConfigFile(PGC_POSTMASTER); + if(explicit_pgconfig) + { + ProcessConfigFile(PGC_POSTMASTER); + if(!potential_DataDir && pgdatadir) + potential_DataDir = pgdatadir; + checkDataDir(potential_DataDir); /* issues error messages */ + SetDataDir(potential_DataDir); + } + else + { + /* + * Now we can set the data directory, and then read postgresql.conf. + */ + checkDataDir(potential_DataDir); /* issues error messages */ + SetDataDir(potential_DataDir); + ProcessConfigFile(PGC_POSTMASTER); + } /* * Check for invalid combinations of GUC settings. diff -u -r postgresql-7.3.2/src/backend/utils/misc/guc-file.c postgresql-7.3.2.ec/src/backend/utils/misc/guc-file.c --- postgresql-7.3.2/src/backend/utils/misc/guc-file.c Mon Feb 3 15:22:34 2003 +++ postgresql-7.3.2.ec/src/backend/utils/misc/guc-file.c Thu Feb 13 22:53:12 +2003 @@ -2,7 +2,6 @@ /* Scanner skeleton version: * $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.91 96/09/10 16:58:48 vern Exp $ - * $FreeBSD: src/usr.bin/lex/flex.skl,v 1.4 1999/10/27 07:56:44 obrien Exp $ */ #define FLEX_SCANNER @@ -10,6 +9,7 @@ #define YY_FLEX_MINOR_VERSION 5 #include <stdio.h> +#include <unistd.h> /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ @@ -23,7 +23,6 @@ #ifdef __cplusplus #include <stdlib.h> -#include <unistd.h> /* Use prototypes in function declarations. */ #define YY_USE_PROTOS @@ -443,7 +442,7 @@ char *GUC_scanstr(char *); #define YY_NEVER_INTERACTIVE 1 #define YY_NO_UNPUT 1 -#line 447 "lex.GUC_yy.c" +#line 446 "lex.GUC_yy.c" /* Macros after this point can all be overridden by user definitions in * section 1. @@ -591,13 +590,13 @@ YY_DECL { register GUC_yy_state_type GUC_yy_current_state; - register char *GUC_yy_cp, *GUC_yy_bp; + register char *GUC_yy_cp = NULL, *GUC_yy_bp = NULL; register int GUC_yy_act; #line 71 "guc-file.l" -#line 601 "lex.GUC_yy.c" +#line 600 "lex.GUC_yy.c" if ( GUC_yy_init ) { @@ -738,7 +737,7 @@ #line 86 "guc-file.l" ECHO; YY_BREAK -#line 742 "lex.GUC_yy.c" +#line 741 "lex.GUC_yy.c" case YY_STATE_EOF(INITIAL): GUC_yyterminate(); @@ -1302,11 +1301,6 @@ } -#ifndef YY_ALWAYS_INTERACTIVE -#ifndef YY_NEVER_INTERACTIVE -extern int isatty YY_PROTO(( int )); -#endif -#endif #ifdef YY_USE_PROTOS void GUC_yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) @@ -1682,16 +1676,28 @@ Assert(DataDir); elevel = (context == PGC_SIGHUP) ? DEBUG3 : ERROR; - /* - * Open file - */ - filename = malloc(strlen(DataDir) + strlen(CONFIG_FILENAME) + 2); + /* Added for explicit config file */ + if(explicit_pgconfig) + { + /* + * Use explicit file + */ + filename = strdup(explicit_pgconfig); + } + else + { + /* + * Use environmental config + */ + filename = malloc(strlen(DataDir) + strlen(CONFIG_FILENAME) + 2); + sprintf(filename, "%s/" CONFIG_FILENAME, DataDir); + } + if (filename == NULL) { elog(elevel, "out of memory"); return; } - sprintf(filename, "%s/" CONFIG_FILENAME, DataDir); fp = AllocateFile(filename, "r"); if (!fp) diff -u -r postgresql-7.3.2/src/backend/utils/misc/guc-file.l postgresql-7.3.2.ec/src/backend/utils/misc/guc-file.l --- postgresql-7.3.2/src/backend/utils/misc/guc-file.l Tue Jul 30 12:33:08 2002 +++ postgresql-7.3.2.ec/src/backend/utils/misc/guc-file.l Thu Feb 13 22:52:35 +2003 @@ -140,16 +140,28 @@ Assert(DataDir); elevel = (context == PGC_SIGHUP) ? DEBUG3 : ERROR; - /* - * Open file - */ - filename = malloc(strlen(DataDir) + strlen(CONFIG_FILENAME) + 2); + /* Added for explicit config file */ + if(explicit_pgconfig) + { + /* + * Use explicit file + */ + filename = strdup(explicit_pgconfig); + } + else + { + /* + * Use environmental config + */ + filename = malloc(strlen(DataDir) + strlen(CONFIG_FILENAME) + 2); + sprintf(filename, "%s/" CONFIG_FILENAME, DataDir); + } + if (filename == NULL) { elog(elevel, "out of memory"); return; } - sprintf(filename, "%s/" CONFIG_FILENAME, DataDir); fp = AllocateFile(filename, "r"); if (!fp) diff -u -r postgresql-7.3.2/src/backend/utils/misc/guc.c postgresql-7.3.2.ec/src/backend/utils/misc/guc.c --- postgresql-7.3.2/src/backend/utils/misc/guc.c Tue Jan 28 13:04:13 2003 +++ postgresql-7.3.2.ec/src/backend/utils/misc/guc.c Thu Feb 13 22:34:15 2003 @@ -51,6 +51,11 @@ #include "utils/pg_locale.h" #include "pgstat.h" +/* Added for config file only startup MLW */ +char *explicit_pgconfig = NULL; +char *explicit_hbafile = NULL; +char *explicit_identfile = NULL; +char *pgdatadir = NULL; /* XXX these should be in other modules' header files */ extern bool Log_connections; @@ -853,6 +858,21 @@ }, { + {"data_dir", PGC_POSTMASTER}, &pgdatadir, + "", NULL, NULL + }, + + { + {"hba_conf", PGC_POSTMASTER}, &explicit_hbafile, + "", NULL, NULL + }, + + { + {"ident_conf", PGC_POSTMASTER}, &explicit_identfile, + "", NULL, NULL + }, + + { {NULL, 0}, NULL, NULL, NULL, NULL } }; diff -u -r postgresql-7.3.2/src/backend/utils/misc/postgresql.conf.sample postgresql-7.3.2.ec/src/backend/utils/misc/postgresql.conf.sample --- postgresql-7.3.2/src/backend/utils/misc/postgresql.conf.sample Mon Jan 27 22:44:09 2003 +++ postgresql-7.3.2.ec/src/backend/utils/misc/postgresql.conf.sample Thu Feb 13 +11:43:53 2003 @@ -22,6 +22,19 @@ #======================================================================== +# Explicit Configuration Parameters + +# Allows PostgreSQL to use a pg_hba.conf file +# which is not in the database directory. +# hbafile = '/etc/postgres/pg_hba.conf' + +# Allows PostgreSQL to use a pg_ident.conf file +# which is not in the database directory. +# identfile = '/etc/postgres/pg_ident.conf' + +# Allows Postgres to find its data directory +# from this configuration file. +# datadir = '/RAID0/postgres' # diff -u -r postgresql-7.3.2/src/include/utils/guc.h postgresql-7.3.2.ec/src/include/utils/guc.h --- postgresql-7.3.2/src/include/utils/guc.h Mon Oct 21 14:57:35 2002 +++ postgresql-7.3.2.ec/src/include/utils/guc.h Thu Feb 13 11:44:32 2003 @@ -137,5 +137,10 @@ extern char *client_min_messages_str; extern const char client_min_messages_str_default[]; +/* Added MLW */ +extern char *explicit_pgconfig; +extern char *explicit_hbafile; +extern char *explicit_identfile; +extern char *pgdatadir; #endif /* GUC_H */
---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster