h2.db file keeps growing

你。 提交于 2019-12-29 09:59:09

问题


We're using H2 database (persistent) embedded within our application.

Even after we delete the tables, the h2.db file keeps growing.

We tried disabling transaction isolation (LOCK_MODE=0), disabled the query log (TRACE_LEVE_FILE=0), disabled the undo log, but nothing helps.

Is compacting the only option? Compacting will need restart of the DB which we cannot do.


回答1:


Using TRACE_LEVE_FILE=0 will only affect the file {databaseName}.trace.db, I suggest not to use disable tracing. The file {databaseName}.trace.db contains human readable error messages and warnings, and normally should be empty. If it is not empty, you might have a bug in your application.

The most common cause for growing database files is uncommitted transactions. Did you commit all transactions? With the newest version of H2 (1.3.168), the message "Transaction log could not be truncated" is written to the {databaseName}.trace.db file. But this requires you don't use TRACE_LEVE_FILE=0.

Please note empty space in the file is re-used, but the file doesn't shrink while the database is open.




回答2:


This issue got resolved. The issue was we were using connection stored in the servlet context. This connection was never closed. We changed the code to manage connections ourselves and close connections after tables are dropped (and reopen).



来源:https://stackoverflow.com/questions/11784497/h2-db-file-keeps-growing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!