PolarDB for PostgreSQL(Compatible with Oracle) provides the database link (DBLink) feature for you to access data across databases.
For example, you can create a database link of Database B in Database A. Then, Database A can use the database link to access the data stored in Database B in the same way as Database A accesses its own data. In this case, two-way data access cannot be implemented. If Database B needs to access the data stored in Database A, you must create a database link of Database A in Database B.
Scenarios
PolarDB for PostgreSQL(Compatible with Oracle) supports two types of database links: database links from some PolarDB for PostgreSQL(Compatible with Oracle) clusters to other PolarDB for PostgreSQL(Compatible with Oracle) clusters and database links from PolarDB for PostgreSQL(Compatible with Oracle) to user-created PostgreSQL databases hosted on Elastic Compute Service (ECS) instances.
- Scenario 1: Database links from PolarDB for PostgreSQL(Compatible with Oracle) to user-created PostgreSQL databases hosted on ECS instances
You previously used a user-created PostgreSQL database that is hosted on an ECS instance. When you migrated the services to PolarDB for PostgreSQL(Compatible with Oracle), only part of the business systems were migrated to PolarDB for PostgreSQL(Compatible with Oracle) due to some reasons. In this scenario, the remaining services are still deployed in the user-created PostgreSQL database that is hosted on the ECS instance. Data access is required between the business systems that were migrated and the remaining services. Therefore, two-way data access must be implemented between the PolarDB for PostgreSQL(Compatible with Oracle) database and the user-created PostgreSQL database hosted on the ECS instance to ensure that your business runs as expected. To implement two-way data access, create a database link from the user-created PostgreSQL database hosted on the ECS instance to PolarDB for PostgreSQL(Compatible with Oracle). You must also create a database link from PolarDB for PostgreSQL(Compatible with Oracle) to the user-created PostgreSQL database hosted on the ECS instance.
- Scenario 2: Database links from some PolarDB for PostgreSQL(Compatible with Oracle) clusters to other PolarDB for PostgreSQL(Compatible with Oracle) clusters
Due to business requirements, you use two PolarDB for PostgreSQL(Compatible with Oracle) clusters. Assume that the two clusters are PolarDB for PostgreSQL(Compatible with Oracle) cluster A and PolarDB for PostgreSQL(Compatible with Oracle) cluster B and the two clusters store data sets of different services. Two-way data access is required between the data sets of different services. To implement two-way data access between the two databases, create a database link from PolarDB for PostgreSQL(Compatible with Oracle) cluster A to PolarDB for PostgreSQL(Compatible with Oracle) cluster B and a database link from PolarDB for PostgreSQL(Compatible with Oracle) cluster B to PolarDB for PostgreSQL(Compatible with Oracle) cluster A.