CREATE PUBLIC DATABASE LINK v11
Name
CREATE [PUBLIC] DATABASE LINK
-- create a new database link.
Synopsis
Description
CREATE DATABASE LINK
creates a new database link. A database link is an object that allows a reference to a table or view in a remote database within a DELETE
, INSERT
, SELECT
or UPDATE
command. A database link is referenced by appending @dblink
to the table or view name referenced in the SQL command where dblink
is the name of the database link.
Database links can be public or private. A public database link is one that can be used by any user. A private database link can be used only by the database link’s owner. Specification of the PUBLIC
option creates a public database link. If omitted, a private database link is created.
When the CREATE DATABASE LINK
command is given, the database link name and the given connection attributes are stored in the Advanced Server system table named, pg_catalog.edb_dblink
. When using a given database link, the database containing the edb_dblink
entry defining this database link is called the local database. The server and database whose connection attributes are defined within the edb_dblink
entry is called the remote database. You can use edb_dblink_oci
to access remote Oracle tables and views using any SELECT
, INSERT
, UPDATE
, or DELETE
statement.
A SQL command containing a reference to a database link must be issued while connected to the local database. When the SQL command is executed, the appropriate authentication and connection is made to the remote database to access the table or view to which the @dblink
reference is appended.
Note
A database link cannot be used to access a remote database within a standby database server. Standby database servers are used for high availability, load balancing, and replication.
For information about high availability, load balancing, and replication for Postgres database servers, see the PostgreSQL core documentation available at:
https://www.postgresql.org/docs/11/static/high-availability.html
Note
- For Advanced Server 11, the
CREATE DATABASE LINK
command is tested against and certified for use with Oracle version 10g Release 2 (10.2), Oracle version 11g Release 2 (11.2), and Oracle version 12c Release 1 (12.1). - The
edb_dblink_oci.rescans
GUC can be set toSCROLL
orSERIALIZABLE
at the server level inpostgresql.conf
file. It can also be set at session level using theSET
command, but the setting will not be applied to existing dblink connections due to dblink connection caching. - When executing
SELECT
on LOB data of more than 4000 characters, it is advisable to useedb_dblink_oci.rescans=serializable
to free up the temporary PGA memory and avoid exceeding thePGA_AGGREGATE_LIMIT
.
The edb_dblink_oci
supports both types of rescans: SCROLL
and SERIALIZABLE
. By default it is set to SERIALIZABLE
. When set to SERIALIZABLE
, edb_dblink_oci
uses the SERIALIZABLE
transaction isolation level on the Oracle side, which corresponds to PostgreSQL’s REPEATABLE READ
.
- This is necessary as a single PostgreSQL statement can lead to multiple Oracle queries and thereby uses a serializable isolation level to provide consistent results.
- A serialization failure may occur due to a table modification concurrent with long-running DML transactions (for example
ADD
,UPDATE
, orDELETE
statements). If such a failure occurs, the OCI reportsORA-08177: can't serialize access for this transaction
, and the application must retry the transaction. - A
SCROLL
rescan will be quick, but with each iteration will reset the current row position to1
. ASERIALIZABLE
rescan has performance benefits over aSCROLL
rescan.
Parameters
PUBLIC
Create a public database link that can be used by any user. If omitted, then the database link is private and can only be used by the database link’s owner.
name
The name of the database link.
username
The username to be used for connecting to the remote database.
CURRENT_USER
Include CURRENT_USER
to specify that Advanced Server should use the user mapping associated with the role that is using the link when establishing a connection to the remote server.
password
The password for username
.
postgres_fdw
Specifies foreign data wrapper postgres_fdw
as the connection to a remote Advanced Server database. If postgres_fdw
has not been installed on the database, use the CREATE EXTENSION
command to install postgres_fdw
. For more information, see the CREATE EXTENSION
command in the PostgreSQL Core documentation at: https://www.postgresql.org/docs/11/static/sql-createextension.html
fdw_connection_string
Specify the connection information for the postgres_fdw
foreign data wrapper.
oci
Specifies a connection to a remote Oracle database. This is Advanced Server’s default behavior.
oracle_connection_string
Specify the connection information for an oci connection.
s
To create a non-public database link you must have the CREATE DATABASE LINK
privilege. To create a public database link you must have the CREATE PUBLIC DATABASE LINK
privilege.
Setting up an Oracle Instant Client for oci-dblink
In order to use oci-dblink, an Oracle instant client must be downloaded and installed on the host running the Advanced Server database in which the database link is to be created.
An instant client can be downloaded from the following site:
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
Oracle Instant Client for Linux
The following instructions apply to Linux hosts running Advanced Server.
Be sure the libaio
library (the Linux-native asynchronous I/O facility) has already been installed on the Linux host running Advanced Server.
The libaio
library can be installed with the following command:
If the Oracle instant client that you've downloaded does not include the file specifically named libclntsh.so
without a version number suffix, you must create a symbolic link named libclntsh.so
that points to the downloaded version of the library file. Navigate to the instant client directory and execute the following command:
Where version
is the version number of the libclntsh.so
library. For example:
When you are executing a SQL command that references a database link to a remote Oracle database, Advanced Server must know where the Oracle instant client library resides on the Advanced Server host.
The LD_LIBRARY_PATH
environment variable must include the path to the Oracle client installation directory containing the libclntsh.so
file. For example, assuming the installation directory containing libclntsh.so
is /tmp/instantclient
:
Alternatively, you can also set the value of the oracle_home
configuration parameter in the
postgresql.conf
file. So, the oracle_home
configuration parameter is an alternative to the
LD_LIBRARY_PATH
environment variable. For more details on the oracle_home
configuration
parameter, see configuration paramters.
The ORACLE_HOME
environment variable is must to be set and should include the path to the Oracle home directory. For example,