Tom Lane wrote:
> I'd view this as a postmaster state that propagates to backends.
> Probably you'd enable it by means of a postmaster option, and the
> only way to get out of it is to shut down and restart the postmaster
> without the option.

I've created a patch to make a postmaster read-only.
(attached patch can be applied to 8.0.1)

Read-only state can be enabled/disabled by the postmaster option,
or the postgresql.conf option.

If you start the postmaster with "-r" options,
the cluster will go to read-only.

% pg_ctl -o "-i -r" -D $PGDATA start

Or if you set "readonly_cluster = true" in the postgresql.conf,
the cluster will also become read-only.

Any comments?
-- 
NAGAYASU Satoshi <[EMAIL PROTECTED]>
OpenSource Development Center,
NTT DATA Corp. http://www.nttdata.co.jp
diff -ru postgresql-8.0.1.orig/src/backend/executor/execMain.c 
postgresql-8.0.1/src/backend/executor/execMain.c
--- postgresql-8.0.1.orig/src/backend/executor/execMain.c       2005-01-15 
02:53:33.000000000 +0900
+++ postgresql-8.0.1/src/backend/executor/execMain.c    2005-03-21 
13:12:22.000000000 +0900
@@ -43,6 +43,7 @@
 #include "optimizer/clauses.h"
 #include "optimizer/var.h"
 #include "parser/parsetree.h"
+#include "postmaster/postmaster.h"
 #include "utils/acl.h"
 #include "utils/guc.h"
 #include "utils/lsyscache.h"
@@ -127,7 +128,7 @@
         * If the transaction is read-only, we need to check if any writes are
         * planned to non-temporary tables.
         */
-       if (XactReadOnly && !explainOnly)
+       if ( (XactReadOnly || ReadOnlyCluster) && !explainOnly)
                ExecCheckXactReadOnly(queryDesc->parsetree);
 
        /*
diff -ru postgresql-8.0.1.orig/src/backend/postmaster/postmaster.c 
postgresql-8.0.1/src/backend/postmaster/postmaster.c
--- postgresql-8.0.1.orig/src/backend/postmaster/postmaster.c   2005-01-13 
01:38:17.000000000 +0900
+++ postgresql-8.0.1/src/backend/postmaster/postmaster.c        2005-03-21 
13:21:17.000000000 +0900
@@ -236,6 +236,8 @@
 extern int     optreset;
 #endif
 
+bool           ReadOnlyCluster = false;
+
 /*
  * postmaster.c - function prototypes
  */
@@ -440,7 +442,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:D:d:Fh:ik:lm:MN:no:p:rSs-:")) != -1)
        {
                switch (opt)
                {
@@ -515,6 +517,9 @@
                        case 'p':
                                SetConfigOption("port", optarg, PGC_POSTMASTER, 
PGC_S_ARGV);
                                break;
+                       case 'r':
+                               SetConfigOption("readonly_cluster", "true", 
PGC_POSTMASTER, PGC_S_ARGV);
+                               break;
                        case 'S':
 
                                /*
diff -ru postgresql-8.0.1.orig/src/backend/tcop/utility.c 
postgresql-8.0.1/src/backend/tcop/utility.c
--- postgresql-8.0.1.orig/src/backend/tcop/utility.c    2005-01-25 
02:46:29.000000000 +0900
+++ postgresql-8.0.1/src/backend/tcop/utility.c 2005-03-21 13:13:45.000000000 
+0900
@@ -47,6 +47,7 @@
 #include "parser/parse_expr.h"
 #include "parser/parse_type.h"
 #include "postmaster/bgwriter.h"
+#include "postmaster/postmaster.h"
 #include "rewrite/rewriteDefine.h"
 #include "rewrite/rewriteRemove.h"
 #include "storage/fd.h"
@@ -265,7 +266,7 @@
 static void
 check_xact_readonly(Node *parsetree)
 {
-       if (!XactReadOnly)
+       if (!XactReadOnly && !ReadOnlyCluster)
                return;
 
        /*
diff -ru postgresql-8.0.1.orig/src/backend/utils/misc/guc.c 
postgresql-8.0.1/src/backend/utils/misc/guc.c
--- postgresql-8.0.1.orig/src/backend/utils/misc/guc.c  2005-01-01 
14:43:08.000000000 +0900
+++ postgresql-8.0.1/src/backend/utils/misc/guc.c       2005-03-21 
13:06:42.000000000 +0900
@@ -851,6 +851,15 @@
 #endif
        },
 
+       {
+               {"readonly_cluster", PGC_POSTMASTER, UNGROUPED,
+                       gettext_noop("Enables the postmaster read-only."),
+                       NULL
+               },
+               &ReadOnlyCluster,
+               false, NULL, NULL
+       },
+
        /* End-of-list marker */
        {
                {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
diff -ru postgresql-8.0.1.orig/src/include/postmaster/postmaster.h 
postgresql-8.0.1/src/include/postmaster/postmaster.h
--- postgresql-8.0.1.orig/src/include/postmaster/postmaster.h   2005-01-01 
07:03:39.000000000 +0900
+++ postgresql-8.0.1/src/include/postmaster/postmaster.h        2005-03-21 
13:03:16.000000000 +0900
@@ -34,6 +34,7 @@
 extern HANDLE PostmasterHandle;
 #endif
 
+extern bool ReadOnlyCluster;
 
 extern int     PostmasterMain(int argc, char *argv[]);
 extern void ClosePostmasterPorts(bool am_syslogger);
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Reply via email to