IMPORT FOREIGN SCHEMA v17
Name
IMPORT FOREIGN SCHEMA
— Import a foreign schema from a foreign server or database link.
Synopsis and parameters
See IMPORT FOREIGN SCHEMA for command syntax, parameters and functionality.
NOT NULL constraints are imported by default. Use the import_not_null
option if you don’t want to import NOT NULL constraints.
Description
After you create an access to a remote database with either a Foreign Data Wrapper or a database link, you can import a foreign schema with IMPORT FOREIGN SCHEMA
. You can import foreign schemas with database links created with edb_dblink_oci
connections as explained in the database link creation examples.
You can then access the imported schema objects locally, instead of remotely.
Example
This example uses the IMPORT FOREIGN SCHEMA
command to import a database schema named IMP
from an Oracle server to an EDB Postgres Advanced Server. The target schema with the imported table definitions is called tmp_schema
and uses an edb_dblink_oci
connection called oci_link
.
Prerequisites
Ensure you have the
connstr
information at hand.Create a server and user mapping as in the following example. Alternatively, you can create a public database link.
Import schemas
Create a server (here called
oci_link
) that connects you to the Oracle database. Specify the foreign data wrapper, and the connection string required to reach the Oracle service.Where
ORACLE_SERVICE
is the environment variable for the name of the Oracle service from which you want to do the import.Map the EDB Postgres
edb
user to the Oracle database user for which you want to import the schemas. Use theoci_link
connection created previously, and specify the Oracle’s user and password:Where
'a'
is the Oracle user name that has access to the foreign schema and'c'
, its password.Create a schema where you’ll place the imported objects:
Import the
IMP
schema from the source database to EDB Postgres Advancedtmp_schema
using theoci_link
connection.This command creates foreign tables that represent the tables existing on the Oracle server.
By default, all tables and views existing in a particular schema on the foreign server are imported. Optionally, the list of tables can be limited to a specified subset, or specific tables can be excluded.
Verify the imported foreign table contains all the schema objects you expect it to have:
- On this page
- Name
- Synopsis and parameters
- Description
- Example