How to connect to Oracle-RAC using SCAN in python?

974 Views Asked by At

I use cx_Oracle module to connect to standalone Oracle server as follows

import cx_Oracle

CONN_INFO = {
    'host': 'xxx.xx.xxx.x',
    'port': 12345,
    'user': 'user_name',
    'psw': 'your_password',
    'service': 'abc.xyz.com',
}

CONN_STR = '{user}/{psw}@{host}:{port}/{service}'.format(**CONN_INFO)

connection = cx_Oracle.connect(CONN_STR)

but as scan IP doesn not have machine and its own username passoword, How do we connect?

1

There are 1 best solutions below

0
Marmite Bomber On

Es described in the documentation, you can simple use the name defined in tnsnames.ora.

Say your RAC tnsnames entry is called MAXIMIR than you can connect with

 con = cx_Oracle.connect("my_usr", "my_pwd", "MAXIMIR", encoding="UTF-8")

alternatively you may pass the whole connection string in a dns variable

dsn = """(DESCRIPTION=
             (FAILOVER=on)
             (ADDRESS_LIST=
               (ADDRESS=(PROTOCOL=tcp)(HOST=scan1)(PORT=1521))
               (ADDRESS=(PROTOCOL=tcp)(HOST=scan2)(PORT=1521)))
             (CONNECT_DATA=(SERVICE_NAME=MAXIMIR)))"""

connection = cx_Oracle.connect("my_usr", "my_pwd", dsn, encoding="UTF-8")