Created
January 5, 2016 14:36
-
-
Save pramsey/80ddf002b9ea38c79e90 to your computer and use it in GitHub Desktop.
Create a recursive connections in PostgreSQL FDW, exhausting your client connections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO $d$ | |
BEGIN | |
EXECUTE $$CREATE SERVER loopback FOREIGN DATA WRAPPER postgres_fdw | |
OPTIONS (dbname '$$||current_database()||$$', | |
port '$$||current_setting('port')||$$' | |
)$$; | |
END; | |
$d$; | |
CREATE USER MAPPING FOR CURRENT_USER SERVER loopback; | |
CREATE TABLE foo ( id integer ); | |
CREATE FOREIGN TABLE foo_fdw ( id integer ) server loopback; | |
SELECT * FROM foo_fdw; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The default target table in the
CREATE FOREIGN TABLE
statement is just the name of the foreign table itself (the code assumes the table will be remote) so this sets up a self reference. Each attempt to examinefoo_fdw
leads the backend to open a new connection to figure out what the structure offoo_fdw
is. Even though each call only makes one new connection, all connections are eventually exhausted.