"ORA-01000: maximum open cursors exceeded" Error
XWiki's cached prepared statements exceed Oracle's default OPEN_CURSORS limit of 300 until it is raised.
Explanation
Once a wiki on Oracle carries real traffic, the logs show:
ORA-01000: maximum open cursors exceededCause
An Oracle session may hold only as many cursors open at a time as its OPEN_CURSORS parameter allows, and Oracle's default is 300. XWiki caches prepared statements in its connection pool, so its sessions are long-lived and hold many cursors at once: the shipped Oracle configuration turns hibernate.dbcp.poolPreparedStatements on and allows 20 cached statements per connection. The Oracle image XWiki's own functional tests run against raises OPEN_CURSORS to 3000 for that reason.
Solution
- Connect to the database as a user holding the DBA role, for example with SQL*Plus.
- Raise the limit. SCOPE=BOTH applies it to the running instance as well as to the next start-up, so Oracle does not have to be restarted.
ALTER SYSTEM SET open_cursors = 3000 SCOPE=BOTH; - Watch the logs of the wiki under the same traffic. The error is gone, with no XWiki restart needed.
FAQ
Does raising the limit hide a leak in XWiki?
No. Oracle's default is simply low for a workload that pools prepared statements, which is why the Oracle image XWiki tests against ships the higher value.
Can I reduce the number of cursors instead?
Yes, by lowering hibernate.dbcp.maxOpenPreparedStatements in the WEB-INF/hibernate.cfg.xml file, at the cost of re-preparing statements more often. Raising OPEN_CURSORS is the cheaper trade.