Pages

Saturday 22 October 2011

Create database link in Oracle

If database is on the same machine(linux/window):
conntion string : 'sid'
Query to use:
>>CREATE DATABASE LINK   linkName CONNECTED TO username IDENTIFIED BY password USING 'sid'
where
 sid: service id or host string of the databaes

How to create Database link in Oracle on Window machines
Connection String:    '//Ip:port(1521)/remote_db_sid'
Query to use:
>>CREATE DATABASE LINK   linkName CONNECTED TO remote_db_username IDENTIFIED BY remote_db_pwd USING '//Ip:port(1521)/remote_db_sid'
Where
  linkName: name of the link
  remote_db_username/remote_db_pwd:  username and password of user who has access to remote database
  remote_db_sid: service id or host string of the remote database.
example:
 > create database newlink connected to system identified by system using '//172.28.1.58:1521/oracle'


PROBLEM:  //IP:PORT(1521) : won't work on linux , so you need some other connection string : a long one.


NOTE
 oracle is case insensitive so don't worry much about case. But do pay attention to quotes. use single quotes to enclose connection string


How to create Database link in Oracle on Linux machines
Connection String:     
'(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.28.1.58)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = oracle)
    )
  )'

Query to use:
>>CREATE DATABASE LINK   linkName CONNECTED TO remote_db_username IDENTIFIED BY remote_db_pwd USING  '(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.28.1.58)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = oracle)
    )
  )'

OR
you can provide alias to this connection string by providing this connection string in your tnsnames.ora file as such:


-- create tnsnames entry for newSid--
conn_link =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.28.1.58)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orabase)
    )
  )

now your query will be :
create database newlink connect to username identified by password USING '
newSid';



Problem:  Sometime  you may find, link is created by not working saying some error. 
Trying writing the same query but this type with connection string in small letters.



example:
 > create database newlink connected to system identified by system using 'description =( address=(protocol =tcp)(host=172.28.1.58)(port=1521)))(connect_data=(service_name=oracle)))'

references:
 http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/ds_concepts002.htm
http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/ds_admin002.htm

No comments:

Post a Comment