sqlalchemy: DatabaseError: (cx_Oracle.DatabaseError) ORA-01219: database not open: queries allowed on fixed tables/views only
Describe the bug
I am trying to query Oracle standby database which is in mount mode (not opened). And when querying the database I am getting
DatabaseError: (cx_Oracle.DatabaseError) ORA-01219: database not open: queries allowed on fixed tables/views only
[SQL: select value from nls_session_parameters where parameter = 'NLS_NUMERIC_CHARACTERS']
(Background on this error at: https://sqlalche.me/e/14/4xp6)
To Reproduce
DIALECT = 'oracle'
SQL_DRIVER = 'cx_oracle'
USERNAME = 'sys' #enter your username
PASSWORD = 'syspassword' #enter your password
CONN_STR='tns_alias'
ENGINE_PATH_WIN_AUTH = DIALECT + '+' + SQL_DRIVER + '://' + USERNAME + ':' + PASSWORD +'@' + CONN_STR + '?mode='+str(cx_Oracle.SYSDBA) + '&encoding=UTF-8&nencoding=UTF-8'
import pandas as pd
from sqlalchemy.engine import create_engine
conn = create_engine(ENGINE_PATH_WIN_AUTH)
pd.read_sql("select instance_name from v$instance", con=conn)
Error
<skipped>
File c:\python38\lib\site-packages\sqlalchemy\dialects\oracle\cx_oracle.py:1038, in OracleDialect_cx_oracle.initialize(self, connection)
1035 if self._is_oracle_8:
1036 self.supports_unicode_binds = False
-> 1038 self._detect_decimal_char(connection)
File c:\python38\lib\site-packages\sqlalchemy\dialects\oracle\cx_oracle.py:1107, in OracleDialect_cx_oracle._detect_decimal_char(self, connection)
1100 def _detect_decimal_char(self, connection):
1101 # we have the option to change this setting upon connect,
1102 # or just look at what it is upon connect and convert.
1103 # to minimize the chance of interference with changes to
1104 # NLS_TERRITORY or formatting behavior of the DB, we opt
1105 # to just look at it
-> 1107 self._decimal_char = connection.exec_driver_sql(
1108 "select value from nls_session_parameters "
1109 "where parameter = 'NLS_NUMERIC_CHARACTERS'"
1110 ).scalar()[0]
1111 if self._decimal_char != ".":
1112 _detect_decimal = self._detect_decimal
<skipped>
DatabaseError: (cx_Oracle.DatabaseError) ORA-01219: database not open: queries allowed on fixed tables/views only
[SQL: select value from nls_session_parameters where parameter = 'NLS_NUMERIC_CHARACTERS']
(Background on this error at: https://sqlalche.me/e/14/4xp6)
Versions
- OS: MS Windows 10
- Python: 3.8
- SQLAlchemy: 1.4.42
- Database: Oracle 12.2
- DBAPI (eg: psycopg, cx_oracle, mysqlclient): cx_oracle
Additional context
Use dynamic view gv$nls_parameters instead of nls_sessions_parameters when trying to set decimal separator. It will work with not opened (but mounted) database as well.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 43 (18 by maintainers)
Commits related to this issue
- Fixed bug causing a leading zero to be returned when certain numbers are converted to strings (one example noted here: https://github.com/sqlalchemy/sqlalchemy/issues/8744#issuecomment-1299160345). — committed to oracle/python-oracledb by anthony-tuininga 2 years ago
- use simple decimal query to detect decimal char Fixed issue where the ``nls_session_parameters`` view queried on first connect in order to get the default decimal point character may not be available... — committed to sqlalchemy/sqlalchemy by zzzeek 2 years ago
I noticed that and am looking into it – since it happened on my machine. It shouldn’t do that!
Yes I have a repaired version going through. Oracledb was actually working as we didn’t treat the decimal character as “absolute”, the test was just checking what it detects, so I’ve adjusted that to assert we get what’s expected for both drivers.