0
1

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 1 year has passed since last update.

PostgreSQL fsyncとsynchronous_commit

Last updated at Posted at 2023-10-17
  • fsync
  • synchronous_commit
    • セッションごと、トランザクションごとに設定可能
    • offにすると、fsyncは行うがその完了を待たずにクライアントに成功を返す。DBクラッシュ時にデータが壊れることはないが、コミットしたはずの変更が失われるリスクがある。本番でoffにすることも十分見合うトレードオフ。
    • 有効な値は何種類かある: remote_apply、on(デフォルト)、remote_write、local、off

set synchronous_commit = 'off' にして単純なINSERT文を試してみたところ、0.8msくらい短縮できた。

postgres=# insert into users (name, start_date, end_date) values ('hoge', '2023-10-01', '2023-10-02');
INSERT 0 1
時間: 1.351 ミリ秒

postgres=# set synchronous_commit = 'off';
SET
時間: 0.700 ミリ秒

postgres=# insert into users (name, start_date, end_date) values ('hoge', '2023-10-01', '2023-10-02');
時間: 0.526 ミリ秒

公式ドキュメントの記述はやや分かりづらいが、内部的な動作はCOMMITについて少し考えてみた(3)の通りらしい。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?