// postgresql · wal, redo & durability

fsync

Flush WAL and data changes to disk before a commit reports success.

預設
on
Range
on, off
Restart needed
否
Default checked on
PostgreSQL 18

其作用

The master switch for durability. With it off, the server hands writes to the OS and acknowledges commits without waiting for the disk; a crash can then lose or tear data. synchronous_commit = off buys much of the same speed without the corruption risk.

預設值

on. on (PostgreSQL 18).

Check the current value

SHOW fsync;

SELECT setting, unit, boot_val, context, source, pending_restart
FROM pg_settings
WHERE name = 'fsync';

Change it

ALTER SYSTEM SET fsync = off;
SELECT pg_reload_conf();

No restart: reload with SELECT pg_reload_conf() or pg_ctl reload. It cannot be changed per session (context is sighup).

When to change it

Almost never in production. The legitimate cases are throwaway load tests and an initial bulk load into a cluster you will back up or rebuild before serving traffic.

What can go wrong

Off leaves acknowledged commits in the OS page cache, so a crash, power loss or disk error can corrupt the cluster beyond repair; docs advise considering full_page_writes = off alongside, which removes torn-page protection on top. Turning it back on does not undo damage taken while it was off.

Questions about fsync

What is the default value of fsync in PostgreSQL?

on. on (PostgreSQL 18).

Does changing fsync require a restart?

No. No restart: reload with SELECT pg_reload_conf() or pg_ctl reload. It cannot be changed per session (context is sighup).

When should I change fsync?

Almost never in production. The legitimate cases are throwaway load tests and an initial bulk load into a cluster you will back up or rebuild before serving traffic.

Back to all PostgreSQL settings, or check the PostgreSQL manual for every option.

// one client for every engine

Check fsync on your own server

SQLly runs the query above against PostgreSQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.

本頁文字與資料: CC BY 4.0,請註明出處 SQLly (sqlly.app)。 程式碼與 SQL 片段: MIT. 授權詳情