Explicit configuration file

Поиск
Список
Период
Сортировка
От mlw
Тема Explicit configuration file
Дата
Msg-id 3C1238B2.766A6F37@mohawksoft.com
обсуждение исходный текст
Ответы Re: Explicit configuration file  (Bruce Momjian <pgman@candle.pha.pa.us>)
Re: Explicit configuration file  (Peter Eisentraut <peter_e@gmx.net>)
Список pgsql-hackers
I have added the option of explicitly specifying a postgresql.conf (-C) file on
the command line. I have also added two config file entries:

pghbaconfig, and pgdatadir.

"pghbaconfig" allows multiple different databases running on the same machine
to use the same hba file, rather than the hard coded $PGDATA/pg_hba.conf.

"pgdatadir" works with the explicit configuration file so that the data
directory can be specified in the configuration file, not on the command line
or environment.

One can start postgres as:

postmaster -C /etc/pgsql/mydb1.conf

Postgres will get all its required information from "mydb1.conf."

Does anyone see any value to these mods? I wanted to be able to run multiple
PostgreSQL instances on the same machine, and having the ability to keep these
control files in a central location and share the HBA control files between
databases may be helpful for admins. It will certainly make my life easier.diff -r -u
postgresql-7.2b3/src/backend/libpq/hba.cpostgresql-7.2b3_conf/src/backend/libpq/hba.c 
--- postgresql-7.2b3/src/backend/libpq/hba.c    Sun Nov 11 23:29:23 2001
+++ postgresql-7.2b3_conf/src/backend/libpq/hba.c    Sat Dec  8 10:46:51 2001
@@ -31,6 +31,8 @@
 #include <unistd.h>

 #include "libpq/libpq.h"
+#include "utils/guc.h"
+
 #include "miscadmin.h"
 #include "nodes/pg_list.h"
 #include "storage/fd.h"
@@ -476,11 +478,20 @@
     {
         char       *conf_file;    /* The name of the config file we have to
                                  * read */
-
-        /* 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_hbaconfig && strlen(explicit_hbaconfig))
+        {
+            bufsize = strlen(explicit_hbaconfig)+1;
+            conf_file = (char *) palloc(bufsize);
+            strcpy(conf_file, explicit_hbaconfig);
+        }
+        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)
diff -r -u postgresql-7.2b3/src/backend/postmaster/postmaster.c
postgresql-7.2b3_conf/src/backend/postmaster/postmaster.c
--- postgresql-7.2b3/src/backend/postmaster/postmaster.c    Mon Nov 12 00:43:24 2001
+++ postgresql-7.2b3_conf/src/backend/postmaster/postmaster.c    Sat Dec  8 10:38:04 2001
@@ -409,10 +409,13 @@
      * with the wrong argument. Death and destruction will occur.
      */
     opterr = 1;
-    while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:Ss-:")) != EOF)
+    while ((opt = getopt(argc, argv, "A:a:B:b:c:C:D:d:Fh:ik:lm:MN:no:p:Ss-:")) != EOF)
     {
         switch (opt)
         {
+            case 'C':
+                explicit_pgconfig = optarg;
+                break;
             case 'D':
                 potential_DataDir = optarg;
                 break;
@@ -434,10 +437,24 @@
         ExitPostmaster(1);
     }

-    checkDataDir(potential_DataDir);    /* issues error messages */
-    SetDataDir(potential_DataDir);
+    if(explicit_pgconfig)
+    {
+        char *datadir;
+        ProcessConfigFile(PGC_POSTMASTER);
+
+        datadir = (pgdatadir) ? pgdatadir : potential_DataDir;
+
+        checkDataDir(datadir);
+        SetDataDir(datadir);
+
+    }
+    else
+    {
+        checkDataDir(potential_DataDir);    /* issues error messages */
+        SetDataDir(potential_DataDir);

-    ProcessConfigFile(PGC_POSTMASTER);
+        ProcessConfigFile(PGC_POSTMASTER);
+    }

     IgnoreSystemIndexes(false);

@@ -447,7 +464,7 @@
     optreset = 1;                /* some systems need this too */
 #endif

-    while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:Ss-:")) != EOF)
+    while ((opt = getopt(argc, argv, "A:a:B:b:c:C:D:d:Fh:ik:lm:MN:no:p:Ss-:")) != EOF)
     {
         switch (opt)
         {
@@ -467,6 +484,9 @@
             case 'b':
                 /* Can no longer set the backend executable file to use. */
                 break;
+            case 'C':
+                /* Can no longer set configuration file */
+                break;
             case 'D':
                 /* already done above */
                 break;
diff -r -u postgresql-7.2b3/src/backend/utils/misc/guc-file.c postgresql-7.2b3_conf/src/backend/utils/misc/guc-file.c
--- postgresql-7.2b3/src/backend/utils/misc/guc-file.c    Fri Nov 23 08:27:33 2001
+++ postgresql-7.2b3_conf/src/backend/utils/misc/guc-file.c    Sat Dec  8 09:48:55 2001
@@ -1682,16 +1682,24 @@
     Assert(DataDir);
     elevel = (context == PGC_SIGHUP) ? DEBUG : ERROR;

-    /*
-     * Open file
-     */
-    filename = malloc(strlen(DataDir) + strlen(CONFIG_FILENAME) + 2);
-    if (filename == NULL)
+    /* Added for explicit config file */
+    if(!explicit_pgconfig)
     {
-        elog(elevel, "out of memory");
-        return;
+        /*
+         * Open file
+         */
+        filename = malloc(strlen(DataDir) + strlen(CONFIG_FILENAME) + 2);
+        if (filename == NULL)
+        {
+            elog(elevel, "out of memory");
+            return;
+        }
+        sprintf(filename, "%s/" CONFIG_FILENAME, DataDir);
+    }
+    else
+    {
+        filename = strdup(explicit_pgconfig);
     }
-    sprintf(filename, "%s/" CONFIG_FILENAME, DataDir);

     fp = AllocateFile(filename, "r");
     if (!fp)
diff -r -u postgresql-7.2b3/src/backend/utils/misc/guc.c postgresql-7.2b3_conf/src/backend/utils/misc/guc.c
--- postgresql-7.2b3/src/backend/utils/misc/guc.c    Tue Oct 30 00:38:56 2001
+++ postgresql-7.2b3_conf/src/backend/utils/misc/guc.c    Sat Dec  8 09:54:22 2001
@@ -39,6 +39,10 @@
 #include "utils/datetime.h"
 #include "pgstat.h"

+/* Added for config file only startup MLW */
+char *explicit_pgconfig = NULL;
+char *explicit_hbaconfig = NULL;
+char *pgdatadir = NULL;

 /* XXX these should be in other modules' header files */
 extern bool Log_connections;
@@ -594,7 +598,14 @@
         XLOG_sync_method_default, check_xlog_sync_method,
         assign_xlog_sync_method
     },
-
+    {
+        "hbaconfig", PGC_POSTMASTER, &explicit_hbaconfig,
+        "", NULL, NULL
+    },
+    {
+        "pgdatadir", PGC_POSTMASTER, &pgdatadir,
+        "", NULL, NULL
+    },
     {
         NULL, 0, NULL, NULL, NULL, NULL
     }
diff -r -u postgresql-7.2b3/src/backend/utils/misc/postgresql.conf.sample
postgresql-7.2b3_conf/src/backend/utils/misc/postgresql.conf.sample
--- postgresql-7.2b3/src/backend/utils/misc/postgresql.conf.sample    Sun Sep 30 14:57:45 2001
+++ postgresql-7.2b3_conf/src/backend/utils/misc/postgresql.conf.sample    Sat Dec  8 10:52:28 2001
@@ -19,6 +19,15 @@

 #========================================================================

+#    Explicit configuration
+
+# Allows postgres to use an pg_hba.conf file
+# which is not in the database directory.
+# hbaconfig = '/etc/pghba.conf'
+
+# Allows Postgres to find its data directory
+# from this configuration file.
+# pgdatadir = '/u01/postgres'

 #
 #    Connection Parameters
diff -r -u postgresql-7.2b3/src/include/utils/guc.h postgresql-7.2b3_conf/src/include/utils/guc.h
--- postgresql-7.2b3/src/include/utils/guc.h    Mon Nov  5 12:46:36 2001
+++ postgresql-7.2b3_conf/src/include/utils/guc.h    Sat Dec  8 10:04:36 2001
@@ -73,4 +73,9 @@
 extern bool SQL_inheritance;
 extern bool Australian_timezones;

+/* Added MLW */
+extern char *explicit_pgconfig;
+extern char *explicit_hbaconfig;
+extern char *pgdatadir;
+
 #endif   /* GUC_H */

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Thomas Lockhart
Дата:
Сообщение: Re: text -> time cast problem
Следующее
От: "Serguei Mokhov"
Дата:
Сообщение: Re: New NLS status page