oracle / python-cx_Oracle

Python interface to Oracle Database now superseded by python-oracledb
https://oracle.github.io/python-cx_Oracle
Other
890 stars 361 forks source link

Possible memory leak when using fetchone or fetchall #637

Closed qwertyue closed 2 years ago

qwertyue commented 2 years ago

Description: Even such simple code, it will leave the data returned by the fetchone(fetchone) function unable to be recycled, i even use gc.collection function. Or do I need to execute specific methods to prevent memory leaks?

cjbj commented 2 years ago

Can you include a complete, runnable script with the exact SQL statement? Also include the CREATE TABLE statement. Show us how you are measuring the memory use and what results you are seeing. Finally, what are the versions of cx_Oracle and of the Oracle client libraries used? You can get these by run the script shown in the issue template.

qwertyue commented 2 years ago

Can you include a complete, runnable script with the exact SQL statement? Also include the CREATE TABLE statement. Show us how you are measuring the memory use and what results you are seeing. Finally, what are the versions of cx_Oracle and of the Oracle client libraries used? You can get these by run the script shown in the issue template.

I will upload this information in a few hours But I may not be able to give you such information as exact SQL statement, CREATE TABLE statement. I passed memory_profile plug-in to prints the memory usage line by line I noticed that the fetchone function will use 0.3mb of memory each time it gets data, and will not release The fetchall function retrieves 50MB of data each time, and deleting the res reference will release 30MB

Finally, I will try the latest python oracle db

anthony-tuininga commented 2 years ago

I assume that since you closed the issue the problem is resolved? What solved your problem?

qwertyue commented 2 years ago

I assume that since you closed the issue the problem is resolved? What solved your problem?

I ran the simulation code ( fetchone, and increase 0.1mb each time ) 2000 times, and the memory increased by 220MB.

Then gc.collect() was called manually, which reduced my memory by 160MB, only added 50MB.

So I don't think the memory leaked, And now I have a new question (sqlalchemy, cx_oracle and multithreading are used), which is OCI-21500: internal error code, arguments: [17099], [], [], [], [], [], [], []

anthony-tuininga commented 2 years ago

If you are using multthreading, you need to ensure that the threaded parameter is set to True. This is done automatically in the new python-oracledb driver.

qwertyue commented 2 years ago

If you are using multthreading, you need to ensure that the threaded parameter is set to True. This is done automatically in the new python-oracledb driver.

If I use sqlalchemy to connect oracle, the threaded parameter in the python-oracledb driver will also be automatically set to True?

anthony-tuininga commented 2 years ago

Yes, take a look at the documentation to help during the transition. SQLAlchemy 2.0 (when it is released) will have native support for python-oracledb.

qwertyue commented 2 years ago

Yes, take a look at the documentation to help during the transition. SQLAlchemy 2.0 (when it is released) will have native support for python-oracledb.

Setting 'threaded' does not solve the problem of OCI-21500: internal error code, arguments: [17099], [], [], [], [], [], [], [].

anthony-tuininga commented 2 years ago

Open a new issue, then, and give as much detail as you can -- including a runnable test case if at all possible!

cjbj commented 2 years ago

Also see the blog posts: