0

When I use oracledb Python module in Thick mode, I get a Segmentation fault error on a huge database request with Oracle v11.2 client.

Code:

# main.py
import oracledb

oracledb.init_oracle(lib_dir='path/to/lib', config_dir='path/to/config')
connection = oracledb.connect(user='user', password='pwd', dsn=cs, sid=sid, encoding='utf-8')
cursor = connection.cursor()
cur.arraysize = 100

results = cur.execute('SELECT * FROM MY_TABLE')

Error:

python main.py
Segmentation fault

What is the problem with this request?

4
  • What does MY_TABLE contain? Where do you get the segfault? Commented Mar 27, 2023 at 17:15
  • In my case, MYTABLE is Materialized View with a lot of columns and rows. I get the segfault after the line "results = cur.execute('SELECT * FROM MY_TABLE')". I also have the error when I use SQL Alchemy + Pandas + dbOracle after "pandas.read_sql()" (pandas v1.1.5) even if I use chunks of size 1. Setting "ORA_OCI_NO_OPTIMIZED_FETCH=1" fixed the issue with larger chunksize. Commented Mar 27, 2023 at 21:51
  • Ok! You can also try thin mode (by commenting out the call to init_oracle_client() as it doesn't have that particular bug. It doesn't have all of the same features but it does have all of the commonly used ones! Commented Mar 28, 2023 at 14:44
  • Oracledb client tell me that Thin mode is not compatible with Oracle DB v11.2.0, that's why I can only use Thick mode in my case. Commented Mar 28, 2023 at 20:06

2 Answers 2

0

It may be a bug in your Oracle Client version at the C level.

To correct it, try to set the ORA_OCI_NO_OPTIMIZED_FETCH environnement variable to 1 in order to disable fetch Oracle compression - which can make your code failed- before running your Python code:

export ORA_OCI_NO_OPTIMIZED_FETCH=1
python main.py

You can also try to update your Oracle client because this bug is probably fix in a more recent version or patch.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes the particular problem that ORA_OCI_NO_OPTIMIZED_FETCH resolves was fixed in 21c Oracle client libraries, and I think backported to a later 19c release (but I don't have that info with me).
0

This issue was recently fixed in https://github.com/oracle/odpi/commit/3a578197cae567028bfe9d39e7e05bfc5869c650 and will be released as part of python-oracledb 3.1.0

1 Comment

The fix you reference may be a different issue. It stops a crash when client libraries can't be loaded and gives a proper error instead. The user would still need to fix their environment and set lib_dir to a valid library path, or use LD_LIBRARY_PATH etc. Note: that on Linux, you should NOT pass lib_dir to init_oracle_client() - it doesn't do what you want, and can lead to other clashes. Only pass it on Windows and macOS. RTM.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.