Wednesday, April 10, 2024

OCI Autonomous Database -- How to Create a DB Link

Problem

You want to create a database link on an Autonomous Database in OCI (Oracle Cloud Infrastructure)

Solution

Use commands below to create a db link:

If db link being created in a schema other than ADMIN, grant required privileges:

SQL> grant execute on DBMS_CLOUD_ADMIN to <schema>;
SQL> grant CREATE DATABASE LINK to <schema>;

Create credential;

BEGIN
  DBMS_CLOUD.CREATE_CREDENTIAL(
    credential_name => '<credential_name>',
    username        => '<username>',
    password        => '<password>'
  );
END;

Create database link:

BEGIN
     DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK(
          db_link_name       => '<db_link_name>',
          hostname           => 'target_db_host_name',
          port               => '<port>',
          service_name       => '<service_name>',
          ssl_server_cert_dn => NULL,
          credential_name    => '<credential_name>',
          directory_name     => NULL,
          private_target     => true);
END;

No comments: