1616
1717static void check_new_cluster_is_empty (void );
1818static void check_is_install_user (ClusterInfo * cluster );
19- static void check_proper_datallowconn (ClusterInfo * cluster );
19+ static void check_for_connection_status (ClusterInfo * cluster );
2020static void check_for_prepared_transactions (ClusterInfo * cluster );
2121static void check_for_isn_and_int8_passing_mismatch (ClusterInfo * cluster );
2222static void check_for_user_defined_postfix_ops (ClusterInfo * cluster );
@@ -590,6 +590,12 @@ check_and_dump_old_cluster(void)
590590if (!user_opts .live_check )
591591start_postmaster (& old_cluster , true);
592592
593+ /*
594+ * First check that all databases allow connections since we'll otherwise
595+ * fail in later stages.
596+ */
597+ check_for_connection_status (& old_cluster );
598+
593599/*
594600 * Extract a list of databases, tables, and logical replication slots from
595601 * the old cluster.
@@ -605,7 +611,6 @@ check_and_dump_old_cluster(void)
605611 * Check for various failure cases
606612 */
607613check_is_install_user (& old_cluster );
608- check_proper_datallowconn (& old_cluster );
609614check_for_prepared_transactions (& old_cluster );
610615check_for_isn_and_int8_passing_mismatch (& old_cluster );
611616
@@ -1087,45 +1092,48 @@ check_is_install_user(ClusterInfo *cluster)
10871092
10881093
10891094/*
1090- *check_proper_datallowconn
1095+ *check_for_connection_status
10911096 *
10921097 *Ensure that all non-template0 databases allow connections since they
10931098 *otherwise won't be restored; and that template0 explicitly doesn't allow
10941099 *connections since it would make pg_dumpall --globals restore fail.
10951100 */
10961101static void
1097- check_proper_datallowconn (ClusterInfo * cluster )
1102+ check_for_connection_status (ClusterInfo * cluster )
10981103{
10991104int dbnum ;
11001105PGconn * conn_template1 ;
11011106PGresult * dbres ;
11021107int ntups ;
11031108int i_datname ;
11041109int i_datallowconn ;
1110+ int i_datconnlimit ;
11051111FILE * script = NULL ;
11061112char output_path [MAXPGPATH ];
11071113
11081114prep_status ("Checking database connection settings" );
11091115
11101116snprintf (output_path ,sizeof (output_path ),"%s/%s" ,
11111117log_opts .basedir ,
1112- "databases_with_datallowconn_false .txt" );
1118+ "databases_cannot_connect_to .txt" );
11131119
11141120conn_template1 = connectToServer (cluster ,"template1" );
11151121
11161122/* get database names */
11171123dbres = executeQueryOrDie (conn_template1 ,
1118- "SELECTdatname, datallowconn "
1124+ "SELECTdatname, datallowconn, datconnlimit "
11191125"FROMpg_catalog.pg_database" );
11201126
11211127i_datname = PQfnumber (dbres ,"datname" );
11221128i_datallowconn = PQfnumber (dbres ,"datallowconn" );
1129+ i_datconnlimit = PQfnumber (dbres ,"datconnlimit" );
11231130
11241131ntups = PQntuples (dbres );
11251132for (dbnum = 0 ;dbnum < ntups ;dbnum ++ )
11261133{
11271134char * datname = PQgetvalue (dbres ,dbnum ,i_datname );
11281135char * datallowconn = PQgetvalue (dbres ,dbnum ,i_datallowconn );
1136+ char * datconnlimit = PQgetvalue (dbres ,dbnum ,i_datconnlimit );
11291137
11301138if (strcmp (datname ,"template0" )== 0 )
11311139{
@@ -1137,10 +1145,11 @@ check_proper_datallowconn(ClusterInfo *cluster)
11371145else
11381146{
11391147/*
1140- * avoid datallowconn == false databases from being skipped on
1141- * restore
1148+ * Avoid datallowconn == false databases from being skipped on
1149+ * restore, and ensure that no databases are marked invalid with
1150+ * datconnlimit == -2.
11421151 */
1143- if (strcmp (datallowconn ,"f" )== 0 )
1152+ if (( strcmp (datallowconn ,"f" ) == 0 ) || strcmp ( datconnlimit , "-2 " )== 0 )
11441153{
11451154if (script == NULL && (script = fopen_priv (output_path ,"w" ))== NULL )
11461155pg_fatal ("could not open file \"%s\": %m" ,output_path );
@@ -1159,11 +1168,11 @@ check_proper_datallowconn(ClusterInfo *cluster)
11591168fclose (script );
11601169pg_log (PG_REPORT ,"fatal" );
11611170pg_fatal ("All non-template0 databases must allow connections, i.e. their\n"
1162- "pg_database.datallowconn must be true. Your installation contains \n"
1163- "non-template0 databases with their pg_database.datallowconn set to \n"
1164- "false . Consider allowing connection for all non-template0 databases \n"
1165- "or drop the databases which do not allow connections. A list of \n"
1166- "databases with the problem is in the file:\n"
1171+ "pg_database.datallowconn must be true and pg_database.datconnlimit \n"
1172+ "must not be -2. Your installation contains non-template0 databases \n"
1173+ "which cannot be connected to . Consider allowing connection for all\n"
1174+ "non-template0 databases or drop the databases which do not allow\n"
1175+ "connections. A list of databases with the problem is in the file:\n"
11671176" %s" ,output_path );
11681177}
11691178else