在AWS的容器中连接到Oracle数据库时遇到的问题

编程语言 2026-07-11

我正在处理一个连接Oracle数据库的代码片段,且它是在AWS Batch作业中的一个容器里运行。我收到这个错误:oracledb.exceptions.DatabaseError: ORA-12533: TNS:illegal ADDRESS parameters

Here is the code that generates the error; specifically the error happens in oracledb.connect:

oracledb.init_oracle_client()

dsn_alias = "prod1.analytics---data-warehouse---db"

connection = oracledb.connect(
    user=oracle_user,
    password=oracle_pwd,
    dsn=dsn_alias
)
return connection

我已经再次确认 cwallet.ssosqlnet.ora 和tnsnames.ora 位于容器中的正确路径。tnsnames.ora 中的 dsn_alias 如下,看起来没问题:

prod1.analytics--data-warehouse---db = (DESCRIPTION=(FAILOVER=on)(CONNECT_TIMEOUT=42)(TRANSPORT_CONNECT_TIMEOUT=20)(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCPS)(HOST=yadda.yadda.yadda.net)(PORT=1523)))(CONNECT_DATA=(SERVICE_NAME=analytics.prod1.data1)(FAILOVER_MODE=(TYPE=SELECT)(METHOD=BASIC)(RETRIES=20)(DELAY=5))))

sqlnet.ora 看起来是这样的:

SQLNET.AUTHENTICATION_SERVICES= (RADIUS, TCPS)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
SSL_CLIENT_AUTHENTICATION = FALSE
SSL_SERVER_DN_MATCH=OFF 

WALLET_LOCATION = 
    (SOURCE = (METHOD = FILE)
    (METHOD_DATA = (DIRECTORY = "/opt/oracle/instantclient_21_4/network/admin")))

SSL_SERVER_DN_MATCH = yes

据我所知,一切看起来都很正当。问题可能出在什么地方?

解决方案

那里没有什么看起来特别不对的地方。你得到的错误包含这段信息,可能有帮助,也可能没有帮助:

// *Cause: An illegal set of protocol adapter parameters was specified. In
// some cases, this error is returned when a connection cannot be made to the
// protocol transport.

// *Action: Verify that the destination can be reached using the specified
// protocol. Check the parameters within the ADDRESS section of
// TNSNAMES.ORA.  Legal ADDRESS parameter formats may be found in the
// Oracle operating system specific documentation for your platform.
// Protocols that resolve names at the transport layer (such as DECnet object
// names) are vulnerable to this error if not properly configured or names are
// misspelled.

我的建议是通过去掉对连接不是必需的部分来简化你的连接字符串(例如FAILOVER_MODE、CONNECT_TIMEOUT等),然后再逐步重新添加它们,以找出问题所在。

如果你不需要FAN,另一个选择是使用thin模式,它配置起来更简单,也不需要Oracle Client库。

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章