how do I create a dblink connection in postgres that I can keep using

Darren Oakey

so - I can create a dblink connection - eg

select * from dblink( 'dbname=whatever host=the_host user=the_user password=my_password', 'select x, y, z from blah')

works fine. I can even make what appears to be a persistent connection

select * from dblink_connect( 'dev', 'dbname=whatever host=the_host user=the_user password=my_password');

select * from dblink( 'dev', 'select x, y, z from blah' );

works fine. For a while. And then after a while - if I try to use dev again - it starts telling me "no open connection". But if I try to run the connect command again, it tells me a connection with that name already exists.

So how do I establish a named connection that I, and others, can just use directly forever afterwards without having to do any sort of connect/disconnect?

jjanes

You can give dblink() the name of a foreign server, rather than the name of a connection.

create server dev foreign data wrapper dblink_fdw options (host 'thehost', dbname 'whatever');
create user mapping for public server dev options (user 'the_user', password 'my_password');

Then run your dblink query just as you currently are, using 'dev' as the name.

Note that this will increase the number of connections done, it is just that the system manages them so that you don't need to. So it is good for convenience, but not for performance.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I use a dblink?

How can I keep netcat connection open?

How can you do an update to a table in another database using postgres dblink?

How can write a query like this using dblink in postgres?

How do I create a query template in Postgres?

Using PHP to access a MySQL database, can I keep a connection open?

how can I do conditional insert in postgres when there can be concurrent inserts that can create conflict?

C# / MongoDB : How do I keep a connection alive?

How do I keep SSH connection alive on Windows 10?

How can I redo this code to do create the table, but using loops?

Django - postgres: how can I verify whether the database connection is SSL?

How can I do connection connection pooling in Nodejs MongoDb

I create input field using jquery, how can keep this ' new input value ' exist after refresh page

How can i create GeoJSON for addressing it in an Layer URL by using geo data from postgres database?

How can I create a table with a UUID column in a Postgres db using SQLAlchemy?

How can I create a fast and secure network connection using 4 Internet LAN connections

Can I create a linked server connection to Databricks using SSMS?

How do I create a http connection using environment variables that are stored as UserDefaults in swiftui?

How do i create several persistent socket connection TCP/IP to the same host using PHP

How do I use createQuery() Method to create JDBC Connection, using sql2o?

Do I realy need Idle Connection in Postgres?

How do I create a public action, but keep the invoke private?

Postgres on Docker. How can I create a database and a user?

How can I create enum with default value in postgres

How can I create a connection to any external database in Mosaic?

How can I create a TCP connection in Python between 2 PCs

How can I create a TLS connection without certificates in golang?

How can I create a remote connection between Mac & Windows computers?

How can I make IB create an action connection?