@@ -17,18 +17,13 @@ DO $d$
17
17
OPTIONS (dbname '$$||current_database()||$$',
18
18
port '$$||current_setting('port')||$$'
19
19
)$$;
20
- EXECUTE $$CREATE SERVER loopback4 FOREIGN DATA WRAPPER postgres_fdw
21
- OPTIONS (dbname '$$||current_database()||$$',
22
- port '$$||current_setting('port')||$$'
23
- )$$;
24
20
END;
25
21
$d$;
26
22
CREATE USER MAPPING FOR public SERVER testserver1
27
23
OPTIONS (user 'value', password 'value');
28
24
CREATE USER MAPPING FOR CURRENT_USER SERVER loopback;
29
25
CREATE USER MAPPING FOR CURRENT_USER SERVER loopback2;
30
26
CREATE USER MAPPING FOR public SERVER loopback3;
31
- CREATE USER MAPPING FOR public SERVER loopback4;
32
27
-- ===================================================================
33
28
-- create objects used through FDW loopback server
34
29
-- ===================================================================
@@ -144,11 +139,6 @@ CREATE FOREIGN TABLE ft7 (
144
139
c2 int NOT NULL,
145
140
c3 text
146
141
) SERVER loopback3 OPTIONS (schema_name 'S 1', table_name 'T 4');
147
- CREATE FOREIGN TABLE ft8 (
148
- c1 int NOT NULL,
149
- c2 int NOT NULL,
150
- c3 text
151
- ) SERVER loopback4 OPTIONS (schema_name 'S 1', table_name 'T 4');
152
142
-- ===================================================================
153
143
-- tests for validator
154
144
-- ===================================================================
@@ -220,8 +210,7 @@ ALTER FOREIGN TABLE ft2 ALTER COLUMN c1 OPTIONS (column_name 'C 1');
220
210
public | ft5 | loopback | (schema_name 'S 1', table_name 'T 4') |
221
211
public | ft6 | loopback2 | (schema_name 'S 1', table_name 'T 4') |
222
212
public | ft7 | loopback3 | (schema_name 'S 1', table_name 'T 4') |
223
- public | ft8 | loopback4 | (schema_name 'S 1', table_name 'T 4') |
224
- (7 rows)
213
+ (6 rows)
225
214
226
215
-- Test that alteration of server options causes reconnection
227
216
-- Remote's errors might be non-English, so hide them to ensure stable results
@@ -9066,15 +9055,21 @@ DROP PROCEDURE terminate_backend_and_wait(text);
9066
9055
-- =============================================================================
9067
9056
-- test connection invalidation cases and postgres_fdw_get_connections function
9068
9057
-- =============================================================================
9069
- -- This test case is for closing the connection in pgfdw_xact_callback
9070
- BEGIN;
9071
- -- List all the existing cached connections. Only loopback2 should be output.
9072
- SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;
9073
- server_name | valid
9074
- -------------+-------
9075
- loopback2 | t
9058
+ -- Let's ensure to close all the existing cached connections.
9059
+ SELECT 1 FROM postgres_fdw_disconnect_all();
9060
+ ?column?
9061
+ ----------
9062
+ 1
9076
9063
(1 row)
9077
9064
9065
+ -- No cached connections, so no records should be output.
9066
+ SELECT server_name FROM postgres_fdw_get_connections() ORDER BY 1;
9067
+ server_name
9068
+ -------------
9069
+ (0 rows)
9070
+
9071
+ -- This test case is for closing the connection in pgfdw_xact_callback
9072
+ BEGIN;
9078
9073
-- Connection xact depth becomes 1 i.e. the connection is in midst of the xact.
9079
9074
SELECT 1 FROM ft1 LIMIT 1;
9080
9075
?column?
@@ -9088,19 +9083,18 @@ SELECT 1 FROM ft7 LIMIT 1;
9088
9083
1
9089
9084
(1 row)
9090
9085
9091
- -- List all the existing cached connections. loopback and loopback3
9092
- -- also should be output as valid connections.
9093
- SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;
9094
- server_name | valid
9095
- -------------+-------
9096
- loopback | t
9097
- loopback2 | t
9098
- loopback3 | t
9099
- (3 rows)
9086
+ -- List all the existing cached connections. loopback and loopback3 should be
9087
+ -- output.
9088
+ SELECT server_name FROM postgres_fdw_get_connections() ORDER BY 1;
9089
+ server_name
9090
+ -------------
9091
+ loopback
9092
+ loopback3
9093
+ (2 rows)
9100
9094
9101
- -- Connection is not closed at the end of the alter statement in
9102
- -- pgfdw_inval_callback. That's because the connection is in midst of this
9103
- -- xact, it is just marked as invalid.
9095
+ -- Connections are not closed at the end of the alter and drop statements.
9096
+ -- That's because the connections are in midst of this xact,
9097
+ -- they are just marked as invalid in pgfdw_inval_callback .
9104
9098
ALTER SERVER loopback OPTIONS (ADD use_remote_estimate 'off');
9105
9099
DROP SERVER loopback3 CASCADE;
9106
9100
NOTICE: drop cascades to 2 other objects
@@ -9113,39 +9107,29 @@ SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;
9113
9107
server_name | valid
9114
9108
-------------+-------
9115
9109
loopback | f
9116
- loopback2 | t
9117
9110
| f
9118
- (3 rows)
9111
+ (2 rows)
9119
9112
9120
- -- The invalid connection gets closed in pgfdw_xact_callback during commit.
9113
+ -- The invalid connections get closed in pgfdw_xact_callback during commit.
9121
9114
COMMIT;
9122
- -- List all the existing cached connections. loopback and loopback3
9123
- -- should not be output because they should be closed at the end of
9124
- -- the above transaction.
9125
- SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;
9126
- server_name | valid
9127
- -------------+-------
9128
- loopback2 | t
9129
- (1 row)
9115
+ -- All cached connections were closed while committing above xact, so no
9116
+ -- records should be output.
9117
+ SELECT server_name FROM postgres_fdw_get_connections() ORDER BY 1;
9118
+ server_name
9119
+ -------------
9120
+ (0 rows)
9130
9121
9131
9122
-- =======================================================================
9132
9123
-- test postgres_fdw_disconnect and postgres_fdw_disconnect_all functions
9133
9124
-- =======================================================================
9134
- -- Return true as all cached connections are closed.
9135
- SELECT postgres_fdw_disconnect_all();
9136
- postgres_fdw_disconnect_all
9137
- -----------------------------
9138
- t
9139
- (1 row)
9140
-
9125
+ BEGIN;
9141
9126
-- Ensure to cache loopback connection.
9142
9127
SELECT 1 FROM ft1 LIMIT 1;
9143
9128
?column?
9144
9129
----------
9145
9130
1
9146
9131
(1 row)
9147
9132
9148
- BEGIN;
9149
9133
-- Ensure to cache loopback2 connection.
9150
9134
SELECT 1 FROM ft6 LIMIT 1;
9151
9135
?column?
@@ -9155,66 +9139,31 @@ SELECT 1 FROM ft6 LIMIT 1;
9155
9139
9156
9140
-- List all the existing cached connections. loopback and loopback2 should be
9157
9141
-- output.
9158
- SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;
9159
- server_name | valid
9160
- -------------+-------
9161
- loopback | t
9162
- loopback2 | t
9142
+ SELECT server_name FROM postgres_fdw_get_connections() ORDER BY 1;
9143
+ server_name
9144
+ -------------
9145
+ loopback
9146
+ loopback2
9163
9147
(2 rows)
9164
9148
9165
- -- Issue a warning and return false as loopback2 connection is still in use and
9149
+ -- Issue a warning and return false as loopback connection is still in use and
9166
9150
-- can not be closed.
9167
- SELECT postgres_fdw_disconnect('loopback2 ');
9168
- WARNING: cannot close connection for server "loopback2 " because it is still in use
9151
+ SELECT postgres_fdw_disconnect('loopback ');
9152
+ WARNING: cannot close connection for server "loopback " because it is still in use
9169
9153
postgres_fdw_disconnect
9170
9154
-------------------------
9171
9155
f
9172
9156
(1 row)
9173
9157
9174
- -- Close loopback connection, return true and issue a warning as loopback2
9175
- -- connection is still in use and can not be closed.
9176
- SELECT postgres_fdw_disconnect_all();
9177
- WARNING: cannot close connection for server "loopback2" because it is still in use
9178
- postgres_fdw_disconnect_all
9179
- -----------------------------
9180
- t
9181
- (1 row)
9182
-
9183
- -- List all the existing cached connections. loopback2 should be output.
9184
- SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;
9185
- server_name | valid
9186
- -------------+-------
9187
- loopback2 | t
9188
- (1 row)
9189
-
9190
- -- Ensure to cache loopback connection.
9191
- SELECT 1 FROM ft1 LIMIT 1;
9192
- ?column?
9193
- ----------
9194
- 1
9195
- (1 row)
9196
-
9197
- -- Ensure to cache loopback4 connection.
9198
- SELECT 1 FROM ft8 LIMIT 1;
9199
- ?column?
9200
- ----------
9201
- 1
9202
- (1 row)
9203
-
9204
- -- List all the existing cached connections. loopback, loopback2, loopback4
9205
- -- should be output.
9206
- SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;
9207
- server_name | valid
9208
- -------------+-------
9209
- loopback | t
9210
- loopback2 | t
9211
- loopback4 | t
9212
- (3 rows)
9158
+ -- List all the existing cached connections. loopback and loopback2 should be
9159
+ -- output.
9160
+ SELECT server_name FROM postgres_fdw_get_connections() ORDER BY 1;
9161
+ server_name
9162
+ -------------
9163
+ loopback
9164
+ loopback2
9165
+ (2 rows)
9213
9166
9214
- DROP SERVER loopback4 CASCADE;
9215
- NOTICE: drop cascades to 2 other objects
9216
- DETAIL: drop cascades to user mapping for public on server loopback4
9217
- drop cascades to foreign table ft8
9218
9167
-- Return false as connections are still in use, warnings are issued.
9219
9168
-- But disable warnings temporarily because the order of them is not stable.
9220
9169
SET client_min_messages = 'ERROR';
@@ -9226,21 +9175,19 @@ SELECT postgres_fdw_disconnect_all();
9226
9175
9227
9176
RESET client_min_messages;
9228
9177
COMMIT;
9229
- -- Close loopback2 connection and return true .
9230
- SELECT postgres_fdw_disconnect('loopback2');
9231
- postgres_fdw_disconnect
9232
- -------------------------
9233
- t
9178
+ -- Ensure that loopback2 connection is closed .
9179
+ SELECT 1 FROM postgres_fdw_disconnect('loopback2');
9180
+ ?column?
9181
+ ----------
9182
+ 1
9234
9183
(1 row)
9235
9184
9236
- -- List all the existing cached connections. loopback should be output.
9237
- SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;
9238
- server_name | valid
9239
- -------------+-------
9240
- loopback | t
9241
- (1 row)
9185
+ SELECT server_name FROM postgres_fdw_get_connections() WHERE server_name = 'loopback2';
9186
+ server_name
9187
+ -------------
9188
+ (0 rows)
9242
9189
9243
- -- Return false as loopback2 connectin is closed already.
9190
+ -- Return false as loopback2 connection is closed already.
9244
9191
SELECT postgres_fdw_disconnect('loopback2');
9245
9192
postgres_fdw_disconnect
9246
9193
-------------------------
@@ -9250,18 +9197,17 @@ SELECT postgres_fdw_disconnect('loopback2');
9250
9197
-- Return an error as there is no foreign server with given name.
9251
9198
SELECT postgres_fdw_disconnect('unknownserver');
9252
9199
ERROR: server "unknownserver" does not exist
9253
- -- Close loopback connection and return true .
9254
- SELECT postgres_fdw_disconnect_all();
9255
- postgres_fdw_disconnect_all
9256
- -----------------------------
9257
- t
9200
+ -- Let's ensure to close all the existing cached connections .
9201
+ SELECT 1 FROM postgres_fdw_disconnect_all();
9202
+ ?column?
9203
+ ----------
9204
+ 1
9258
9205
(1 row)
9259
9206
9260
- -- List all the existing cached connections. No connection exists, so NULL
9261
- -- should be output.
9262
- SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;
9263
- server_name | valid
9264
- -------------+-------
9207
+ -- No cached connections, so no records should be output.
9208
+ SELECT server_name FROM postgres_fdw_get_connections() ORDER BY 1;
9209
+ server_name
9210
+ -------------
9265
9211
(0 rows)
9266
9212
9267
9213
-- =============================================================================
@@ -9271,6 +9217,7 @@ CREATE ROLE regress_multi_conn_user1 SUPERUSER;
9271
9217
CREATE ROLE regress_multi_conn_user2 SUPERUSER;
9272
9218
CREATE USER MAPPING FOR regress_multi_conn_user1 SERVER loopback;
9273
9219
CREATE USER MAPPING FOR regress_multi_conn_user2 SERVER loopback;
9220
+ BEGIN;
9274
9221
-- Will cache loopback connection with user mapping for regress_multi_conn_user1
9275
9222
SET ROLE regress_multi_conn_user1;
9276
9223
SELECT 1 FROM ft1 LIMIT 1;
@@ -9290,25 +9237,25 @@ SELECT 1 FROM ft1 LIMIT 1;
9290
9237
9291
9238
RESET ROLE;
9292
9239
-- Should output two connections for loopback server
9293
- SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;
9294
- server_name | valid
9295
- -------------+-------
9296
- loopback | t
9297
- loopback | t
9240
+ SELECT server_name FROM postgres_fdw_get_connections() ORDER BY 1;
9241
+ server_name
9242
+ -------------
9243
+ loopback
9244
+ loopback
9298
9245
(2 rows)
9299
9246
9300
- -- Close loopback connections and return true.
9301
- SELECT postgres_fdw_disconnect('loopback');
9302
- postgres_fdw_disconnect
9303
- -------------------------
9304
- t
9247
+ COMMIT;
9248
+ -- Let's ensure to close all the existing cached connections.
9249
+ SELECT 1 FROM postgres_fdw_disconnect_all();
9250
+ ?column?
9251
+ ----------
9252
+ 1
9305
9253
(1 row)
9306
9254
9307
- -- List all the existing cached connections. No connection exists, so NULL
9308
- -- should be output.
9309
- SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;
9310
- server_name | valid
9311
- -------------+-------
9255
+ -- No cached connections, so no records should be output.
9256
+ SELECT server_name FROM postgres_fdw_get_connections() ORDER BY 1;
9257
+ server_name
9258
+ -------------
9312
9259
(0 rows)
9313
9260
9314
9261
-- Clean up
0 commit comments