Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 130f89e

Browse files
committed
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.
1 parent b4a98c5 commit 130f89e

File tree

10 files changed

+303
-81
lines changed

10 files changed

+303
-81
lines changed

doc/src/sgml/ref/postmaster.sgml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/postmaster.sgml,v 1.50 2004/06/21 04:06:04 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/postmaster.sgml,v 1.51 2004/07/11 00:18:41 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -67,15 +67,28 @@ PostgreSQL documentation
6767
One <command>postmaster</command> always manages the data
6868
from exactly one database cluster. A database cluster is a
6969
collection of databases that is stored at a common file system
70-
location. When the <command>postmaster</command> starts it needs to know the location
71-
of the database cluster files (<quote>data area</quote>). This is
72-
done with the <option>-D</option> invocation option or the
73-
<envar>PGDATA</envar> environment variable; there is no default.
74-
More than one <command>postmaster</command> process can run on a system at one time,
75-
as long as they use different data areas and different
70+
location. When the <command>postmaster</command> starts it needs
71+
to know the location of the database cluster files (<quote>data
72+
area</quote>).
73+
More than one <command>postmaster</command> process can run on a system
74+
at one time as long as they use different data areas and different
7675
communication ports (see below). A data area is created with <xref
7776
linkend="app-initdb">.
7877
</para>
78+
79+
<para>
80+
The <quote>data area</> is specified by the <option>-D</option> option
81+
or the <envar>PGDATA</envar> environment variable; there is no default.
82+
Typically, it points to a directory created by <application>
83+
initdb</>. However, for administrative flexibility, you can
84+
point to a directory containing only configuration files:
85+
<filename>postgresql.conf</>, <filename>pg_hba.conf</>, and
86+
<filename>pg_ident.conf</>. You can then set
87+
<filename>postgresql.conf</>'s <varname>pgdata</> to point to the
88+
data directory. You can also point just to the server configuration file
89+
like <filename>postgresql.conf</> and set its variables to point to the
90+
other configuration files and the data directory.
91+
</para>
7992
</refsect1>
8093

8194
<refsect1 id="app-postmaster-options">

doc/src/sgml/runtime.sgml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.268 2004/06/27 22:58:19 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.269 2004/07/11 00:18:40 momjian Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -563,6 +563,54 @@ SET ENABLE_SEQSCAN TO OFF;
563563
any desired selection condition.
564564
</para>
565565

566+
<sect2 id="runtime-config-configuration-files">
567+
<title>Configuration Files</title>
568+
569+
<variablelist>
570+
571+
<varlistentry id="guc-pgdata" xreflabel="pgdata">
572+
<term><varname>pgdata</varname> (<type>string</type>)</term>
573+
<listitem>
574+
<para>
575+
Specifies the directory to use for data storage (everything except
576+
configuration files).
577+
</para>
578+
</listitem>
579+
</varlistentry>
580+
581+
<varlistentry id="guc-hba-conf" xreflabel="hba-conf">
582+
<term><varname>hba_conf</varname> (<type>string</type>)</term>
583+
<listitem>
584+
<para>
585+
Specifies the file name to use for configuration of host-based
586+
authentication (HBA).
587+
</para>
588+
</listitem>
589+
</varlistentry>
590+
591+
<varlistentry id="guc-ident-conf" xreflabel="ident-conf">
592+
<term><varname>ident_conf</varname> (<type>string</type>)</term>
593+
<listitem>
594+
<para>
595+
Specifies the file name to use for configuration of
596+
<application>ident</> authentication.
597+
</para>
598+
</listitem>
599+
</varlistentry>
600+
601+
<varlistentry id="external-pidfile" xreflabel="external-pidfile">
602+
<term><varname>external_pidfile</varname> (<type>string</type>)</term>
603+
<listitem>
604+
<para>
605+
Specifies the location of an additional <application>postmaster</>
606+
process-id (PID) file for use by server administration programs.
607+
</para>
608+
</listitem>
609+
</varlistentry>
610+
611+
</variablelist>
612+
</sect2>
613+
566614
<sect2 id="runtime-config-connection">
567615
<title>Connections and Authentication</title>
568616

src/backend/bootstrap/bootstrap.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.185 2004/06/24 21:02:24 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.186 2004/07/11 00:18:43 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -212,7 +212,7 @@ BootstrapMain(int argc, char *argv[])
212212
char *dbname;
213213
int flag;
214214
int xlogop = BS_XLOG_NOP;
215-
char *potential_DataDir = NULL;
215+
char *userPGDATA = NULL;
216216

217217
/*
218218
* initialize globals
@@ -236,8 +236,7 @@ BootstrapMain(int argc, char *argv[])
236236
if (!IsUnderPostmaster)
237237
{
238238
InitializeGUCOptions();
239-
potential_DataDir = getenv("PGDATA"); /* Null if no PGDATA
240-
* variable */
239+
userPGDATA = getenv("PGDATA"); /* Null if no PGDATA variable */
241240
}
242241

243242
/* Ignore the initial -boot argument, if present */
@@ -252,7 +251,7 @@ BootstrapMain(int argc, char *argv[])
252251
switch (flag)
253252
{
254253
case 'D':
255-
potential_DataDir = optarg;
254+
userPGDATA = optarg;
256255
break;
257256
case 'd':
258257
{
@@ -326,7 +325,7 @@ BootstrapMain(int argc, char *argv[])
326325

327326
if (!IsUnderPostmaster)
328327
{
329-
if (!potential_DataDir)
328+
if (!userPGDATA)
330329
{
331330
write_stderr("%s does not know where to find the database system data.\n"
332331
"You must specify the directory that contains the database system\n"
@@ -335,7 +334,7 @@ BootstrapMain(int argc, char *argv[])
335334
argv[0]);
336335
proc_exit(1);
337336
}
338-
SetDataDir(potential_DataDir);
337+
SetDataDir(userPGDATA);
339338
}
340339

341340
/* Validate we have been given a reasonable-looking DataDir */

src/backend/libpq/hba.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.125 2004/05/30 23:40:26 neilc Exp $
13+
* $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.126 2004/07/11 00:18:43 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -35,6 +35,7 @@
3535
#include "miscadmin.h"
3636
#include "nodes/pg_list.h"
3737
#include "storage/fd.h"
38+
#include "utils/guc.h"
3839

3940

4041
/* Max size of username ident server can return */
@@ -1029,17 +1030,22 @@ load_user(void)
10291030
void
10301031
load_hba(void)
10311032
{
1032-
int bufsize;
10331033
FILE *file; /* The config file we have to read */
10341034
char *conf_file; /* The name of the config file */
10351035

10361036
if (hba_lines || hba_line_nums)
10371037
free_lines(&hba_lines, &hba_line_nums);
10381038

1039-
/* Put together the full pathname to the config file. */
1040-
bufsize = (strlen(DataDir) + strlen(CONF_FILE) + 2) * sizeof(char);
1041-
conf_file = (char *) palloc(bufsize);
1042-
snprintf(conf_file, bufsize, "%s/%s", DataDir, CONF_FILE);
1039+
/* HBA filename in config file */
1040+
if (guc_hbafile)
1041+
conf_file = pstrdup(guc_hbafile);
1042+
else
1043+
{
1044+
char *confloc = (user_pgconfig_is_dir) ? user_pgconfig : DataDir;
1045+
/* put together the full pathname to the config file */
1046+
conf_file = palloc(strlen(confloc) + strlen(CONF_FILE) + 2);
1047+
sprintf(conf_file, "%s/%s", confloc, CONF_FILE);
1048+
}
10431049

10441050
file = AllocateFile(conf_file, "r");
10451051
if (file == NULL)
@@ -1178,16 +1184,20 @@ load_ident(void)
11781184
FILE *file; /* The map file we have to read */
11791185
char *map_file; /* The name of the map file we have to
11801186
* read */
1181-
int bufsize;
1182-
11831187
if (ident_lines || ident_line_nums)
11841188
free_lines(&ident_lines, &ident_line_nums);
11851189

1186-
/* put together the full pathname to the map file */
1187-
bufsize = (strlen(DataDir) + strlen(USERMAP_FILE) + 2) * sizeof(char);
1188-
map_file = (char *) palloc(bufsize);
1189-
snprintf(map_file, bufsize, "%s/%s", DataDir, USERMAP_FILE);
1190-
1190+
/* IDENT filename in config file */
1191+
if (guc_identfile)
1192+
map_file = pstrdup(guc_identfile);
1193+
else
1194+
{
1195+
/* put together the full pathname to the map file */
1196+
char *confloc = (user_pgconfig_is_dir) ? user_pgconfig : DataDir;
1197+
map_file = (char *) palloc(strlen(confloc) + strlen(USERMAP_FILE) + 2);
1198+
sprintf(map_file, "%s/%s", confloc, USERMAP_FILE);
1199+
}
1200+
11911201
file = AllocateFile(map_file, "r");
11921202
if (file == NULL)
11931203
{

src/backend/postmaster/postmaster.c

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.406 2004/07/10 23:29:16 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.407 2004/07/11 00:18:43 momjian Exp $
4141
*
4242
* NOTES
4343
*
@@ -233,6 +233,7 @@ extern int optreset;
233233
* postmaster.c - function prototypes
234234
*/
235235
static void checkDataDir(const char *checkdir);
236+
static bool onlyConfigSpecified(const char *checkdir);
236237
#ifdef USE_RENDEZVOUS
237238
static void reg_reply(DNSServiceRegistrationReplyErrorType errorCode,
238239
void *context);
@@ -306,7 +307,7 @@ PostmasterMain(int argc, char *argv[])
306307
{
307308
int opt;
308309
int status;
309-
char *potential_DataDir = NULL;
310+
char *userPGDATA = NULL;
310311
int i;
311312

312313
progname = get_progname(argv[0]);
@@ -370,7 +371,7 @@ PostmasterMain(int argc, char *argv[])
370371
*/
371372
InitializeGUCOptions();
372373

373-
potential_DataDir = getenv("PGDATA"); /* default value */
374+
userPGDATA = getenv("PGDATA"); /* default value */
374375

375376
opterr = 1;
376377

@@ -395,7 +396,7 @@ PostmasterMain(int argc, char *argv[])
395396
/* Can no longer set the backend executable file to use. */
396397
break;
397398
case 'D':
398-
potential_DataDir = optarg;
399+
userPGDATA = optarg;
399400
break;
400401
case 'd':
401402
{
@@ -524,13 +525,49 @@ PostmasterMain(int argc, char *argv[])
524525
ExitPostmaster(1);
525526
}
526527

527-
/*
528-
* Now we can set the data directory, and then read postgresql.conf.
529-
*/
530-
checkDataDir(potential_DataDir); /* issues error messages */
531-
SetDataDir(potential_DataDir);
528+
if (onlyConfigSpecified(userPGDATA))
529+
{
530+
/*
531+
* It is either a file name or a directory with no
532+
* global/pg_control file, and hence not a data directory.
533+
*/
534+
user_pgconfig = userPGDATA;
535+
ProcessConfigFile(PGC_POSTMASTER);
532536

533-
ProcessConfigFile(PGC_POSTMASTER);
537+
if (!guc_pgdata) /* Got a pgdata from the config file? */
538+
{
539+
write_stderr("%s does not know where to find the database system data.\n"
540+
"This should be specified as 'pgdata' in %s%s.\n",
541+
progname, userPGDATA,
542+
user_pgconfig_is_dir ? "/postgresql.conf" : "");
543+
ExitPostmaster(2);
544+
}
545+
checkDataDir(guc_pgdata);
546+
SetDataDir(guc_pgdata);
547+
}
548+
else
549+
{
550+
/* Now we can set the data directory, and then read postgresql.conf. */
551+
checkDataDir(userPGDATA);
552+
SetDataDir(userPGDATA);
553+
ProcessConfigFile(PGC_POSTMASTER);
554+
}
555+
556+
if (external_pidfile)
557+
{
558+
FILE *fpidfile = fopen(external_pidfile, "w");
559+
560+
if (fpidfile)
561+
{
562+
fprintf(fpidfile, "%d\n", MyProcPid);
563+
fclose(fpidfile);
564+
/* Should we remove the pid file on postmaster exit? */
565+
}
566+
else
567+
fprintf(stderr,
568+
gettext("%s could not write to external pid file %s\n"),
569+
progname, external_pidfile);
570+
}
534571

535572
/* If timezone is not set, determine what the OS uses */
536573
pg_timezone_initialize();
@@ -848,6 +885,32 @@ PostmasterMain(int argc, char *argv[])
848885
}
849886

850887

888+
889+
static bool
890+
onlyConfigSpecified(const char *checkdir)
891+
{
892+
char path[MAXPGPATH];
893+
struct stat stat_buf;
894+
895+
if (checkdir == NULL) /* checkDataDir handles this */
896+
return FALSE;
897+
898+
if (stat(checkdir, &stat_buf) == -1) /* ditto */
899+
return FALSE;
900+
901+
if (S_ISREG(stat_buf.st_mode)) /* It's a regular file, so assume it's explict */
902+
return TRUE;
903+
else if (S_ISDIR(stat_buf.st_mode)) /* It's a directory, is it a config or system dir? */
904+
{
905+
snprintf(path, MAXPGPATH, "%s/global/pg_control", checkdir);
906+
/* If this is not found, it is a config-only directory */
907+
if (stat(path, &stat_buf) == -1)
908+
return TRUE;
909+
}
910+
return FALSE;
911+
}
912+
913+
851914
/*
852915
* Validate the proposed data directory
853916
*/
@@ -862,8 +925,8 @@ checkDataDir(const char *checkdir)
862925
{
863926
write_stderr("%s does not know where to find the database system data.\n"
864927
"You must specify the directory that contains the database system\n"
865-
"either by specifying the -D invocation option or by setting the\n"
866-
"PGDATA environment variable.\n",
928+
"or configuration files by either specifying the -D invocation option\n"
929+
"or by setting the PGDATA environment variable.\n",
867930
progname);
868931
ExitPostmaster(2);
869932
}
@@ -873,12 +936,12 @@ checkDataDir(const char *checkdir)
873936
if (errno == ENOENT)
874937
ereport(FATAL,
875938
(errcode_for_file_access(),
876-
errmsg("data directory \"%s\" does not exist",
939+
errmsg("data or configuration location \"%s\" does not exist",
877940
checkdir)));
878941
else
879942
ereport(FATAL,
880943
(errcode_for_file_access(),
881-
errmsg("could not read permissions of directory \"%s\": %m",
944+
errmsg("could not read permissions of \"%s\": %m",
882945
checkdir)));
883946
}
884947

0 commit comments

Comments
 (0)