On 2021/03/19 23:35, James Coleman wrote:
Here's an updated patch; I think I've gotten what Alvaro suggested.

Thanks for updating the patch! But I was thinking that our consensus is
something like the attached patch. Could you check this patch?

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
diff --git a/src/backend/postmaster/postmaster.c 
b/src/backend/postmaster/postmaster.c
index ef0be4ca38..a800568d14 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -2294,6 +2294,19 @@ retry1:
                                        (errcode(ERRCODE_CANNOT_CONNECT_NOW),
                                         errmsg("the database system is 
starting up")));
                        break;
+               case CAC_NOCONSISTENT:
+                       if (EnableHotStandby)
+                               ereport(FATAL,
+                                               
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
+                                                errmsg("the database system is 
not accepting connections"),
+                                                errdetail("Consistent recovery 
state has not been yet reached.")));
+                       else
+                               ereport(FATAL,
+                                               
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
+                                                errmsg("the database system is 
not accepting connections"),
+                                                errdetail("Hot standby mode is 
disabled.")));
+                       break;
+
                case CAC_SHUTDOWN:
                        ereport(FATAL,
                                        (errcode(ERRCODE_CANNOT_CONNECT_NOW),
@@ -2435,10 +2448,11 @@ canAcceptConnections(int backend_type)
        {
                if (Shutdown > NoShutdown)
                        return CAC_SHUTDOWN;    /* shutdown is pending */
-               else if (!FatalError &&
-                                (pmState == PM_STARTUP ||
-                                 pmState == PM_RECOVERY))
+               else if (!FatalError && pmState == PM_STARTUP)
                        return CAC_STARTUP; /* normal startup */
+               else if (!FatalError && pmState == PM_RECOVERY)
+                       return CAC_NOCONSISTENT;        /* consistent recovery 
state has not
+                                                                               
 * been yet reached */
                else
                        return CAC_RECOVERY;    /* else must be crash recovery 
*/
        }
diff --git a/src/include/libpq/libpq-be.h b/src/include/libpq/libpq-be.h
index 30fb4e613d..299528255c 100644
--- a/src/include/libpq/libpq-be.h
+++ b/src/include/libpq/libpq-be.h
@@ -70,7 +70,12 @@ typedef struct
 
 typedef enum CAC_state
 {
-       CAC_OK, CAC_STARTUP, CAC_SHUTDOWN, CAC_RECOVERY, CAC_TOOMANY,
+       CAC_OK,
+       CAC_STARTUP,
+       CAC_NOCONSISTENT,
+       CAC_SHUTDOWN,
+       CAC_RECOVERY,
+       CAC_TOOMANY,
        CAC_SUPERUSER
 } CAC_state;
 

Reply via email to