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

柔情痞子 提交于 2020-02-25 13:14:57

问题


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:


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")


来源:https://stackoverflow.com/questions/59368839/how-to-connect-to-oracle-rac-using-scan-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!