![]() |
![]()
| ![]() |
![]()
NAMEdblink_connect - opens a persistent connection to a remote database SYNOPSISdblink_connect(text connstr) returns text dblink_connect(text connname, text connstr) returns text DESCRIPTIONdblink_connect() establishes a connection to a remote PostgreSQL database. The server and database to be contacted are identified through a standard libpq connection string. Optionally, a name can be assigned to the connection. Multiple named connections can be open at once, but only one unnamed connection is permitted at a time. The connection will persist until closed or until the database session is ended. The connection string may also be the name of an existing foreign server. It is recommended to use the foreign-data wrapper dblink_fdw when defining the foreign server. See the example below, as well as CREATE SERVER (CREATE_SERVER(7)) and CREATE USER MAPPING (CREATE_USER_MAPPING(7)). ARGUMENTSconnname The name to use for this connection; if omitted, an
unnamed connection is opened, replacing any existing unnamed connection.
connstr libpq-style connection info string, for example
hostaddr=127.0.0.1 port=5432 dbname=mydb user=postgres password=mypasswd
options=-csearch_path=. For details see Section 32.1.1. Alternatively,
the name of a foreign server.
RETURN VALUEReturns status, which is always OK (since any error causes the function to throw an error instead of returning). NOTESIf untrusted users have access to a database that has not adopted a secure schema usage pattern, begin each session by removing publicly-writable schemas from search_path. One could, for example, add options=-csearch_path= to connstr. This consideration is not specific to dblink; it applies to every interface for executing arbitrary SQL commands. The foreign-data wrapper dblink_fdw has an additional Boolean option use_scram_passthrough that controls whether dblink will use the SCRAM pass-through authentication to connect to the remote database. With SCRAM pass-through authentication, dblink uses SCRAM-hashed secrets instead of plain-text user passwords to connect to the remote server. This avoids storing plain-text user passwords in PostgreSQL system catalogs. See the documentation of the equivalent use_scram_passthrough option of postgres_fdw for further details and restrictions. Only superusers may use dblink_connect to create connections that use neither password authentication, SCRAM pass-through, nor GSSAPI-authentication. If non-superusers need this capability, use dblink_connect_u instead. It is unwise to choose connection names that contain equal signs, as this opens a risk of confusion with connection info strings in other dblink functions. EXAMPLESSELECT dblink_connect('dbname=postgres options=-csearch_path=');
|