Using Oracle with Django


In a production environment you could hit this one: DatabaseError: Invalid handle!

It seems to happen when Oracle is called with OCI interface (cx_Oracle) by multiple threads.

Yes using apache with MPM worker or mod_wsgi, will create threads in the same process, by default cx_Oracle is configured to be used without threads cause it will add a mutex and a performance hit.

The solution is to pass the threaded parameters to the connection string, so in Django settings just add:

DATABASE_OPTIONS = {
        'threaded':True
    }

Here is a bug in the Django documentation to changed it to threaded by default … 13351