0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

H2でVacuum

Posted at

背景

H2 Databaseは導入が楽ですが、放っておくとファイルが肥大化します。Vacuum的処理は当面実装されそうにありません。

しかし、サーバを落とすときには若干のVacuum的処理が走ります。

つまり時々落としてやればよいのです。
落としても大丈夫かだって?君の会社が大枚叩いて使ってるオーロラやら何やらは100%繋がるのかい?インターネットなんていつでも切れるんだぜ!

実装

Spring-bootを前提にして話を進めますが、DBのマイグレーションとかより先に立ち上げなきゃいけませんから、main(String[])で最初に立ち上げてしまうのが一番トラブルが少ないでしょう。stop/startはScheduledを使えます。

private static Server server;
public static void main(String[] args) throws Exception {
    server = Server.createTcpServer("-ifNotExists").start();
}
@Scheduled(cron = "0 0 0 * * *")
void dbCron() throws Exception {
    server.stop();
    server = Server.createTcpServer().start();
}

考察

実際、毎分1回落とす設定にしても体感できるトラブルはありません。データがでかくなれば事情が違うのかもしれませんが。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?