4

I am using Oracle 11g express edition. I have created tables, stored procedures and it works fine. I have my user "System" with password "xyz" (main user during installation).

Then i have created two databases "abc" and "pqr" with same user.

I wanted to create database link from abc to pqr.

create database link testlink
connect to pqr identified by xyz
 using '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))   (CONNECT_DATA=(sid=xe)))';

I am getting error "Insufficient privileges". Please help me out.

1
  • 1
    Did you mean created two users? Instead of databases? If so check that whether the user create database link has the CREATE DATABASE LINK system privilege and the connecting user has CREATE SESSION system privilege. Commented Jan 5, 2017 at 5:40

1 Answer 1

7

It should be CONNECT TO username not the database name as shown in the following image which describes the syntax of CREATE DATABASE LINK. We define database instance/service under USING connect_string clause.

enter image description here

Prerequisites

To create a private database link, you must have the CREATE DATABASE LINK system privilege. To create a public database link, you must have the CREATE PUBLIC DATABASE LINK system privilege. Also, you must have the CREATE SESSION system privilege on the remote Oracle database.

Reference:CREATE DATABASE LINK

Demo

[oracle@orcl Desktop]$ sqlplus system/oracle

SQL> create user abc identified by abc;

User created.

SQL> create user xyz identified by xyz;

User created.

SQL> grant create session to abc;

Grant succeeded.

SQL> conn abc/abc
Connected.

SQL> create database link testlink connect to pqr identified by pqr using '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orcl.dba.com)(PORT=1522))   (CONNECT_DATA=(service=orcl)))';
create database link testlink connect to pqr identified by pqr using '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orcl.dba.com)(PORT=1522))   (CONNECT_DATA=(service=orcl)))'
                     *
ERROR at line 1:
ORA-01031: insufficient privileges


SQL> conn system/oracle
Connected.
SQL> grant create database link to abc;

Grant succeeded.

SQL> create database link testlink connect to pqr identified by pqr using '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orcl.dba.com)(PORT=1522))   (CONNECT_DATA=(service=orcl)))';^[[3~^C

SQL> conn abc/abc
Connected.
SQL> create database link testlink connect to pqr identified by pqr using '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orcl.dba.com)(PORT=1522))   (CONNECT_DATA=(service=orcl)))';

Database link created.
Sign up to request clarification or add additional context in comments.

5 Comments

yes when i try to execute grant create database link i get same error message. How Do I give system privilege?
Connect as sys user with sysdba privilege then try to grant the required privileges. For example: sqlplus sys as sysdba then SQL> grant ...
Here main issue is i cannot login as sys user also. I tried sys and sys and other combinations too.
@poonam: Then connect as SYSTEM user and grant CREATE DATABASE LINK to abc user. Next, connect as abc user and create the database link. Refer to the demo.
Public database links are a security vulnerability. Use them with caution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.