HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

How often does Postgres or Mysql make the fsync call?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
fsyncthepostgresoftenmakecallmysqldoeshow

Problem

How often does Postgres or Mysql make the fsync call?

  • Does Postgres or Mysql fsync for every write to the Write Ahead log?



  • Does Postgres or Mysql fsync for every transaction? so if I do a SQL Insert will postgres or mysql fsync immediately?

Solution

I can only answer for PostgreSQL:
About sync on the WAL:

The transaction log (WAL) is synced to disk on every commit (unless you set synchronous_commit = off.

In addition, the WAL writer regularly syncs the WAL; this is governed by wal_writer_delay (this will only take effect if WAL hasn't been synced for a while). Also, if more than wal_writer_flush_after bytes have been written without a sync, data will be synced to disk.
About sync on the data files:

Data files are normally synced during checkpoints.

Since PostgreSQL uses buffered I/O, there is the danger that too many dirty blocks in the file system cache cause write spikes. Since version 9.6, PostgreSQL has various *_flush_after parameters that avoid that by regulary syncing data when a lot is written:

  • bgwriter_flush_after (default 512K) makes the background writer flush data to disk after it has written that amount of data



  • backend_flush_after (default 0 = disabled) makes the client session flush data to disk after it has written that amount of data



  • checkpoint_flush_after (default 256KB) makes the checkpointer flush out data after writing this much, rather than flushing all at the end

Context

StackExchange Database Administrators Q#254069, answer score: 4

Revisions (0)

No revisions yet.