Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

H2 and query logging?

Is there a way to get a "query log" out of H2, like you can with e.g. MySQL? The closest match so far is the TRACE_LEVEL_FILE option, but it it not good for debugging the individual queries, especially when they have variable parameters like most do.

like image 585
Eemeli Kantola Avatar asked May 25 '11 13:05

Eemeli Kantola


People also ask

How do I query H2 DB?

Accessing the H2 Console H2 database has an embedded GUI console for browsing the contents of a database and running SQL queries. By default, the H2 console is not enabled in Spring. Then, after starting the application, we can navigate to http://localhost:8080/h2-console, which will present us with a login page.

Is H2 better than SQLite?

SQLite is much more robust to corruption. Speed wise H2 was much faster in my case. With SQLite transactions are particularly costly, so you should prefer doing bulk operations within transactions or via batches.

Is H2 database same as MySQL?

MySQL is a server - based database - it runs as a separate process from your application, and is commonly used in production deployments. H2 is a lightweight database, which can run entirely in-memory, or with disk storage, either in your application's process (embedded) or in a separate process.

Is H2 compatible with PostgreSQL?

SQL SupportCompatibility modes for IBM DB2, Apache Derby, HSQLDB, MS SQL Server, MySQL, Oracle, and PostgreSQL.


1 Answers

The TRACE_LEVEL_FILE is the best option. There are 4 levels:

  • 0 (disabled)
  • 1 (only errors)
  • 2 (errors and info messages, including SQL statements)
  • 3 (debug level; including SQL statements and parameter values)
  • 4 (log using SLF4J)

So I guess 2 would be the right level in your case.

There is also a simple way to analyze the trace file, documented in Database Profiling.

like image 88
Thomas Mueller Avatar answered Oct 20 '22 15:10

Thomas Mueller