PolarDB for Oracle provides the database link (DBLink) feature to query data across databases. This topic describes how to use a database link to query data across databases.
Prerequisites
- A source cluster and a destination cluster are created. For more information, see
Create a cluster.
Note The DBLink feature of PolarDB for Oracle supports the following connection methods:
- The source database is in a PolarDB for Oracle cluster and the destination database is in a PolarDB for Oracle cluster.
- The source database is in a PolarDB for Oracle cluster. The destination database is a self-managed PostgreSQL database hosted on an ECS instance.
- Databases are created in the source and destination clusters. For more information, see Create a database.
- Tables are created in the destination database.
Note
You can query data of the destination cluster only from the source cluster. You cannot query data of the source cluster from the destination cluster.
Parameter configuration
PolarDB for Oracle provides the polar_enable_pushable_unsafe_collate_remote and polar_enable_pushable_all_any_remote parameters to improve query performance.
- polar_enable_pushable_unsafe_collate_remote: specifies whether to push down the functions that do not meet collation requirements.
This parameter is a session-level parameter. The default value of this parameter is
on.
If you set this parameter to off, the functions that do not meet collation requirements are not pushed down.
- To set this parameter to on, run the following command:
SET polar_enable_pushable_unsafe_collate_remote = on;
- To set this parameter to off, run the following command:
SET polar_enable_pushable_unsafe_collate_remote = off;
- To set this parameter to on, run the following command:
- polar_enable_pushable_all_any_remote: specifies whether to push down ANY() and ALL() expressions. This parameter is a
session-level parameter. The default value of this parameter is on.
If you set this parameter to off, the ALL/ANY expressions that do not meet requirements are not pushed down.
- To set this parameter to on, run the following command:
SET polar_enable_pushable_all_any_remote = on;
- To set this parameter to off, run the following command:
SET polar_enable_pushable_all_any_remote = off;
- To set this parameter to on, run the following command:
Procedure
Examples
To create a table named test
in the destination database for testing and insert test data into the table, execute
the following statements:
CREATE TABLE test(id int);
INSERT INTO test VALUES(1);
Connect to the source database and execute the following query statement:
SELECT * FROM test@dblinkname;
The following query result is returned:
id
----
1
(1 row)