14.5. 彈性設定
Durability is a database feature that guarantees the recording of committed transactions even if the server crashes or loses power. However, durability adds significant database overhead, so if your site does not require such a guarantee,PostgreSQLcan be configured to run much faster. The following are configuration changes you can make to improve performance in such cases. Except as noted below, durability is still guaranteed in case of a crash of the database software; only abrupt operating system stoppage creates a risk of data loss or corruption when these settings are used.
- Place the database cluster’s data directory in a memory-backed file system (i.e.RAMdisk). This eliminates all database disk I/O, but limits data storage to the amount of available memory (and perhaps swap).
- Turn offfsync; there is no need to flush data to disk.
- Turn offsynchronous_commit; there might be no need to forceWALwrites to disk on every commit. This setting does risk transaction loss (though not data corruption) in case of a crash of thedatabase.
- Turn offfull_page_writes; there is no need to guard against partial page writes.
- Increasemax_wal_sizeandcheckpoint_timeout; this reduces the frequency of checkpoints, but increases the storage requirements of
/pg_wal
. - Createunlogged tablesto avoidWALwrites, though it makes the tables non-crash-safe.