PostgreSQL Tuning
约 1 分钟阅读
Tools & Resources
- Explain Analysis Visualization (PEV)
- Explain Depesz
- PGTune
- PostgreSQL High Performance CookbookGitHubPacktPublishing/PostgreSQL-High-Performance-Cookbook
- Debugging Performance the Hard Way
IO Benchmarking (fio)
# Sequential mixed read/write (50/50)
fio --ioengine=libaio --direct=1 --name=test_seq --filename=test_file --bs=8k --iodepth=32 --size=1G --readwrite=rw --rwmixread=50
# Random mixed read/write (50/50)
fio --ioengine=libaio --direct=1 --name=test_rand --filename=test_file --bs=8k --iodepth=32 --size=1G --readwrite=randrw --rwmixread=50Optimization Techniques
UNLOGGED Tables
- Effect: No WAL logging, data lost on crash/unclean shutdown. Not replicated.
- Use Case: Bulk loading, temporary data, reproducible data.
- Command:
CREATE UNLOGGED TABLE ...orALTER TABLE ... SET UNLOGGED(locks table).
WAL Configuration
synchronous_commit:on(default): Safe, wait for flush.off: Async commit. Loss of recent transactions (default 3xwal_writer_delay) possible on crash. Integrity maintained. Good for analytics/bulk loading.local,remote_write,remote_apply.
Memory (work_mem)
- Default 4MB is per-operation (sort/hash).
- Monitor
log_temp_filesto see spills to disk. - Increase for complex analytical queries, but watch out for
max_connections * work_mem * operations.
HyperLogLog (HLL)
- Efficient distinct counting for rollups.
- citusdata/postgresql-hllGitHubcitusdata/postgresql-hll
关联信息
反向链接、本文链接的其他页面和外部资料。
参考资料
GitHub2 条
- citusdata/postgresql-hllgithub.com/citusdata/postgresql-hll
- PacktPublishing/PostgreSQL-High-Performance-Cookbookgithub.com/PacktPublishing/PostgreSQL-High-Performance-Cookbook
其他外链4 条
- explain.depesz.comexplain.depesz.com/
- pgtune.leopard.in.uapgtune.leopard.in.ua/
- tatiyants.com/pevtatiyants.com/pev
- www.justwatch.com/blog/post/debugging-postgresql-performance-the-hard-waywww.justwatch.com/blog/post/debugging-postgresql-performance-the-hard-way