user6475988
user6475988

Reputation: 87

SQLAlchemy: Failover with oracledb and firewall restrictions

I'm using sqlalchemy to connect to a oracle express database via oracledb. I want to provide a failover mechanism by using a dsn entry in the following way (host2 should be used if host1 is not accessible).

dsn = """(DESCRIPTION=
             (FAILOVER=on)
             (ADDRESS_LIST=
               (ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=1521))
               (ADDRESS=(PROTOCOL=tcp)(HOST=host2)(PORT=1521)))
             (CONNECT_DATA=(SERVICE_NAME=service_name)))"""

username = "db_user"
password = "db_password"

from sqlalchemy import create_engine
engine = create_engine(f'oracle+oracledb://:@',
    connect_args={"user": user, "password": password, "dsn": dsn})

However, the failover mechanism fails if there is a firewall restriction. This means that it doesn't work it host1 is not reachable, because a firewall blocks the request, even if host2 is reachable. In fact I get a timeout issue:

sqlalchemy.exc.OperationalError: (oracledb.exceptions.OperationalError) DPY-6005: cannot connect to database

I didn't find an answer to my question. Some people seem to also have this issue: What does 'DPY-6005: cannot connect to database. Connection failed with "[Errno 61] Connection refused"' mean with python-oracledb

Can this issue be solved (without explicit removal of the firewall restriction)?

Upvotes: 0

Views: 106

Answers (0)

Related Questions