Opening existing DB in read-only mode may throw exception "The database is read only [90097-123]"

1,053 views
Skip to first unread message

Rafferty

unread,
Nov 18, 2009, 1:33:05 AM11/18/09
to H2 Database
Hi Thomas -

First I'd like to say how much I admire the engineering and
professionalism of H2. It's inspiring.

I'm testing 1.2 with an app that I've been running with H2 for some
time and seeing a new error that I hadn't seen before.

When it opens an existing DB file with ACCESS_MODE_DATA=R it sometimes
get an exception as below. It looks like PageStore.recover() is
getting called, which in turn is calling PageStore.writePage() , which
bombs out because the conection was opened as read-only.

I'm not sure what recovery is required for this DB. Possibly, the DB
is sometimes not being shutdown correctly, because this problem
doesn't happen all the time. Once it does, however it persists until
I make the connection read-write. Making the connection read-write
makes the problem go away.

I tested setting ACCESS_MODE_LOG=RW while leaving ACCESS_MODE_DATA=R
but this didn't help.

org.h2.jdbc.JdbcSQLException: The database is read only [90097-123]
at org.h2.message.Message.getSQLException(Message.java:111)
at org.h2.message.Message.getSQLException(Message.java:122)
at org.h2.message.Message.getSQLException(Message.java:75)
at org.h2.message.Message.getSQLException(Message.java:157)
at org.h2.engine.Database.checkWritingAllowed(Database.java:1852)
at org.h2.store.FileStore.checkWritingAllowed(FileStore.java:166)
at org.h2.store.FileStore.write(FileStore.java:332)
at org.h2.store.PageStore.writePage(PageStore.java:977)
at org.h2.store.PageLog.recover(PageLog.java:267)
at org.h2.store.PageStore.recover(PageStore.java:1003)
at org.h2.store.PageStore.openExisting(PageStore.java:296)
at org.h2.store.PageStore.open(PageStore.java:254)
at org.h2.engine.Database.getPageStore(Database.java:2299)
at org.h2.engine.Database.open(Database.java:625)
at org.h2.engine.Database.openDatabase(Database.java:228)
at org.h2.engine.Database.<init>(Database.java:222)
at org.h2.engine.Engine.openSession(Engine.java:58)
at org.h2.engine.Engine.openSession(Engine.java:142)
at org.h2.engine.Engine.getSession(Engine.java:122)
at org.h2.engine.SessionFactoryEmbedded.createSession
(SessionFactoryEmbedded.java:17)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer
(SessionRemote.java:245)
at org.h2.engine.SessionRemote.createSession(SessionRemote.java:223)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:110)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:94)
at org.h2.Driver.connect(Driver.java:58)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)

I'm using H2 1.2.123 on Windows XP with JDK 1.6.0_12

Thomas Mueller

unread,
Nov 20, 2009, 5:39:38 AM11/20/09
to h2-da...@googlegroups.com
Hi,

I think I found the problem. It will be fixed in the next release.

Regards,
Thomas
> --
>
> You received this message because you are subscribed to the Google Groups "H2 Database" group.
> To post to this group, send email to h2-da...@googlegroups.com.
> To unsubscribe from this group, send email to h2-database...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/h2-database?hl=.
>
>
>

=maximus=

unread,
Dec 8, 2009, 8:50:04 AM12/8/09
to H2 Database
Thomas,

Is this problem fixed and should one set read-only attributes for
database files and/or it is sufficient to use ACCESS_MODE_DATA=R
parameter? It is not clear whether to use both or not?

Maxim.

Thomas Mueller

unread,
Dec 11, 2009, 1:25:15 PM12/11/09
to h2-da...@googlegroups.com
Hi,

> Is this problem fixed

Yes.

> should one set read-only attributes for
> database files and/or it is sufficient to use ACCESS_MODE_DATA=R
> parameter?

One of both is sufficient.

Regards,
Thomas

Steve Luo

unread,
Feb 9, 2013, 7:21:19 AM2/9/13
to h2-da...@googlegroups.com
Hi Thomas,

I encountered such exception quite often and don't know what's the root cause yet, I'm using h2-1.3.159. The exception looks like below.

org.h2.jdbc.JdbcSQLException: The database is read only [90097-159]
     at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
     at org.h2.message.DbException.get(DbException.java:169)
     at org.h2.message.DbException.get(DbException.java:146)
     at org.h2.message.DbException.get(DbException.java:135)
     at org.h2.engine.Database.checkWritingAllowed(Database.java:1626)
     at org.h2.store.PageStore.logUndo(PageStore.java:996)
     at org.h2.index.PageDataLeaf.create(PageDataLeaf.java:92)
     at org.h2.index.PageDataIndex.getPage(PageDataIndex.java:227)
     at org.h2.index.PageDataIndex. (PageDataIndex.java:81)
     at org.h2.table.RegularTable. (RegularTable.java:92)
     at org.h2.store.PageStore.openMetaIndex(PageStore.java:1511)
     at org.h2.store.PageStore.recover(PageStore.java:1328)
     at org.h2.store.PageStore.openExisting(PageStore.java:349)
     at org.h2.store.PageStore.open(PageStore.java:273)
     at org.h2.engine.Database.getPageStore(Database.java:2049)
     at org.h2.engine.Database.open(Database.java:553)
     at org.h2.engine.Database.openDatabase(Database.java:220)
     at org.h2.engine.Database. (Database.java:215)
     at org.h2.engine.Engine.openSession(Engine.java:56)
     at org.h2.engine.Engine.openSession(Engine.java:159)
     at org.h2.engine.Engine.createSessionAndValidate(Engine.java:138)
     at org.h2.engine.Engine.createSession(Engine.java:121)
     at org.h2.engine.Engine.createSession(Engine.java:28)
     at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:285)
     at org.h2.jdbc.JdbcConnection. (JdbcConnection.java:110)
     at org.h2.jdbc.JdbcConnection. (JdbcConnection.java:94)
     at org.h2.Driver.connect(Driver.java:72)

     at java.sql.DriverManager.getConnection(DriverManager.java:582)
     at java.sql.DriverManager.getConnection(DriverManager.java:185)
     at

My case is just like what this post mentioned. I'm trying open a database with ACCESS_MODE_DATA=R using embedded mode, and then some time this error raised and persisted unless I restart my application.

So, my question is can I safely change to a read write mode when this error occurred? Like:

Connection conn = null;
try {
    conn = DriverManager.getConnection("jdbc:h2:/home/data/test;ACCESS_MODE_DATA=r", "sa", "");
} catch (org.h2.jdbc.JdbcSQLException e) {
   if (e.getMessage().contains("The database is read only"))
       conn = DriverManager.getConnection("jdbc:h2:/home/data/test;ACCESS_MODE_DATA=r", "sa", "");
   else
       throw new RuntimeException(e);
}


Best Regards,
Steve


Steve Luo

unread,
Feb 9, 2013, 7:26:07 AM2/9/13
to h2-da...@googlegroups.com
Sorry, my mistake, the code snippet should be:


Connection conn = null;
try {
    conn = DriverManager.getConnection("jdbc:h2:/home/data/test;ACCESS_MODE_DATA=r", "sa", "");
} catch (org.h2.jdbc.JdbcSQLException e) {
    if (e.getMessage().contains("The database is read only"))
        conn = DriverManager.getConnection("jdbc:h2:/home/data/test", "sa", "")
    else
        throw new RuntimeException(e);

Christoph Läubrich

unread,
Feb 9, 2013, 7:34:41 AM2/9/13
to h2-da...@googlegroups.com
I would asume that the connections/sessions are not closed properly, so the DB tries to revert some uncommited changes.
--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.

To post to this group, send email to h2-da...@googlegroups.com.

Noel Grandin

unread,
Feb 9, 2013, 7:54:24 AM2/9/13
to h2-da...@googlegroups.com
This is what happened

(1) someone opened the DB in rw mode
(2) that program did not shutdown cleanly
(3) you try to open in ro mode
(4) the DB tries to undo the uncommitted changes

Reply all
Reply to author
Forward
0 new messages