16
16
17
17
static void check_new_cluster_is_empty (void );
18
18
static void check_is_install_user (ClusterInfo * cluster );
19
- static void check_proper_datallowconn (ClusterInfo * cluster );
19
+ static void check_for_connection_status (ClusterInfo * cluster );
20
20
static void check_for_prepared_transactions (ClusterInfo * cluster );
21
21
static void check_for_isn_and_int8_passing_mismatch (ClusterInfo * cluster );
22
22
static void check_for_user_defined_postfix_ops (ClusterInfo * cluster );
@@ -590,6 +590,12 @@ check_and_dump_old_cluster(void)
590
590
if (!user_opts .live_check )
591
591
start_postmaster (& old_cluster , true);
592
592
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
+
593
599
/*
594
600
* Extract a list of databases, tables, and logical replication slots from
595
601
* the old cluster.
@@ -605,7 +611,6 @@ check_and_dump_old_cluster(void)
605
611
* Check for various failure cases
606
612
*/
607
613
check_is_install_user (& old_cluster );
608
- check_proper_datallowconn (& old_cluster );
609
614
check_for_prepared_transactions (& old_cluster );
610
615
check_for_isn_and_int8_passing_mismatch (& old_cluster );
611
616
@@ -1087,45 +1092,48 @@ check_is_install_user(ClusterInfo *cluster)
1087
1092
1088
1093
1089
1094
/*
1090
- * check_proper_datallowconn
1095
+ * check_for_connection_status
1091
1096
*
1092
1097
* Ensure that all non-template0 databases allow connections since they
1093
1098
* otherwise won't be restored; and that template0 explicitly doesn't allow
1094
1099
* connections since it would make pg_dumpall --globals restore fail.
1095
1100
*/
1096
1101
static void
1097
- check_proper_datallowconn (ClusterInfo * cluster )
1102
+ check_for_connection_status (ClusterInfo * cluster )
1098
1103
{
1099
1104
int dbnum ;
1100
1105
PGconn * conn_template1 ;
1101
1106
PGresult * dbres ;
1102
1107
int ntups ;
1103
1108
int i_datname ;
1104
1109
int i_datallowconn ;
1110
+ int i_datconnlimit ;
1105
1111
FILE * script = NULL ;
1106
1112
char output_path [MAXPGPATH ];
1107
1113
1108
1114
prep_status ("Checking database connection settings" );
1109
1115
1110
1116
snprintf (output_path , sizeof (output_path ), "%s/%s" ,
1111
1117
log_opts .basedir ,
1112
- "databases_with_datallowconn_false .txt" );
1118
+ "databases_cannot_connect_to .txt" );
1113
1119
1114
1120
conn_template1 = connectToServer (cluster , "template1" );
1115
1121
1116
1122
/* get database names */
1117
1123
dbres = executeQueryOrDie (conn_template1 ,
1118
- "SELECT datname, datallowconn "
1124
+ "SELECT datname, datallowconn, datconnlimit "
1119
1125
"FROM pg_catalog.pg_database" );
1120
1126
1121
1127
i_datname = PQfnumber (dbres , "datname" );
1122
1128
i_datallowconn = PQfnumber (dbres , "datallowconn" );
1129
+ i_datconnlimit = PQfnumber (dbres , "datconnlimit" );
1123
1130
1124
1131
ntups = PQntuples (dbres );
1125
1132
for (dbnum = 0 ; dbnum < ntups ; dbnum ++ )
1126
1133
{
1127
1134
char * datname = PQgetvalue (dbres , dbnum , i_datname );
1128
1135
char * datallowconn = PQgetvalue (dbres , dbnum , i_datallowconn );
1136
+ char * datconnlimit = PQgetvalue (dbres , dbnum , i_datconnlimit );
1129
1137
1130
1138
if (strcmp (datname , "template0" ) == 0 )
1131
1139
{
@@ -1137,10 +1145,11 @@ check_proper_datallowconn(ClusterInfo *cluster)
1137
1145
else
1138
1146
{
1139
1147
/*
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.
1142
1151
*/
1143
- if (strcmp (datallowconn , "f" ) == 0 )
1152
+ if (( strcmp (datallowconn , "f" ) == 0 ) || strcmp ( datconnlimit , "-2 " ) == 0 )
1144
1153
{
1145
1154
if (script == NULL && (script = fopen_priv (output_path , "w" )) == NULL )
1146
1155
pg_fatal ("could not open file \"%s\": %m" , output_path );
@@ -1159,11 +1168,11 @@ check_proper_datallowconn(ClusterInfo *cluster)
1159
1168
fclose (script );
1160
1169
pg_log (PG_REPORT , "fatal" );
1161
1170
pg_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"
1167
1176
" %s" , output_path );
1168
1177
}
1169
1178
else
0 commit comments