python - 如何在python中使用SCAN连接到Oracle-RAC?

标签 python oracle cx-oracle oracle-rac

我使用 cx_Oracle 模块连接到独立的 Oracle 服务器,如下所示

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)

但是由于扫描IP没有机器和自己的用户名密码,我们如何连接?

最佳答案

Es documentation 中描述,您可以简单地使用tnsnames.ora中定义的名称。

假设您的 RAC tnsnames 条目名为 MAXIMIR,您可以使用它进行连接

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

或者,您可以在 dns 变量中传递整个连接字符串

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

关于python - 如何在python中使用SCAN连接到Oracle-RAC?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59368839/

相关文章:

python - 在 Python 中使用 cx_Oracle 和 xlrd 的带有列表列表的 executemany() 返回 TypeError

python - Python 中的正则表达式匹配

python - 相交数取决于相交数据帧的顺序

python - 反射(reflect) cx_Oracle/sqlalchemy 中的数据库表

SQL 甲骨文 : how to find records maching a particular id in the column

oracle - Jpa - Hibernate ManyToMany 在连接表中进行多次插入

python - 使用python从CSV插入到oracle表中

python - 将生成器包装为单个 `next` 调用,而不是两个步骤( __iter__ + __next__ )

python - 如何避免用户在 Django 中注册已使用的电子邮件?

node.js - 如何在 Node.js 项目中完美使用 Oracle DB