The Essential postgresql.conf

12,182 views
12,067 views

Published on

Discusses the the most important parameters inside the postgresql.conf. Given at the Beijing Perl Workshop, China, 2008

Published in: Technology
0 Comments
21 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
12,182
On SlideShare
0
From Embeds
0
Number of Embeds
146
Actions
Shares
0
Downloads
0
Comments
0
Likes
21
Embeds 0
No embeds

No notes for slide

The Essential postgresql.conf

  1. 1. The Essential postgresql.conf Robert Treat Beijing Perl Workshop, China, 2008
  2. 2. Introduction Robert Treat DBA, Postgres Major Contributor http://www.xzilla.net/writings.html OmniTI Internet Scalability Experts http://omniti.com/is/hiring
  3. 3. The Grand Scheme Understanding the postgresql.conf Essential postgresql.conf parameters
  4. 4. The Grand Scheme Understanding the postgresql.conf Essential postgresql.conf parameters
  5. 5. Understanding the postgresql.conf Types of settings When settings take effect postgresql.conf gotchas Viewing your current settings
  6. 6. Types of Settings ● Boolean : true, false, on, off ● Integer : whole numbers (2112) ● Float : decimal values (21.12) ● Memory/Disk Units : 128MB, 2112GB ● Avoid using integers to size memory params ● Time : d,m,s (30s) ● Strings : single quotes ('pg_log') ● Enum : single quotes ('WARNING' or 'ERROR') ● Limited set of acceptable strings ● Lists : comma separated ('”$user”,public,tsearch2')
  7. 7. When Settings Take Effect ● Internal : set at compile time ● Postmaster : requires database restart ● Backend : must be set before session start ● Sighup : change by reloading conf file ● pg_reload_conf(), pg_ctl reload, kill -HUP ● Superuser : set at runtime by superuser ● User : set at runtime, effects only single session See pg_settings.context to determine setting type
  8. 8. When Settings Take Effect ● Internal : set at compile time ● Postmaster : requires database restart ● Backend : must be set before session start ● Sighup : change by reloading conf file ● pg_reload_conf(), pg_ctl reload, kill -HUP ● Superuser : set at runtime by superuser ● User : set at runtime, effects only single session See pg_settings.context to determine setting type
  9. 9. postgresql.conf Gotchas! ● $PGDATA/postgresql.conf ● Watch out for symbolic links ● Some distros put it other places (/etc) ● Lines with # ● Line is a comment, has no effect ● On fresh install, uses default ● On <8.3, comment a line does not restore the default ● Settings listed multiple times ● Last one wins
  10. 10. View Your Current Settings ● Look in postgresql.conf ● Works if you follow best practice ● Not definitive! ● Show all, show <setting> ● Shows current value ● Watch out for session specific changes ● Select * from pg_settings ● Shows current value ● “source” column shows if session specific
  11. 11. Essential postgresql.conf parameters Getting connected Logging Sizing Memory WAL Management Checkpoint Management Vacuuming Leftovers
  12. 12. Getting Connected ● listen_addresses ● Requires restart! ● Default is localhost only ● Use * to enable tcp/ip ● max_connections ● Requires restart! ● 100 default (apache children default is higher) ● Affects other settings (work_mem) ● For 1000+ connections, use connection pool
  13. 13. Logging ● log_destination, log_directory, log_filename ● Find out where you are logging ● Might be good to log to different disk than data ● log_min_error_statement ● Make sure set to at least 'ERROR' ● log_line_prefix ● Generic recommendation: '%t:%r:%u@%d:[%p]: ' ● Timestamp, connecting host, username, database, pid
  14. 14. Sizing Memory ● shared_buffers ● Requires Restart! ● Most important setting for good performance ● Allocation of memory for Postgres caching ● ~ 20% of Total RAM (up to 2GB) ● 32GB of RAM, 1920MB probably ok ● Windows users probably want less ● May require adjusting kernel params (shmmax) ● http://www.postgresql.org/docs/current/interactive/kernel-resources.html
  15. 15. Sizing Memory ● effective_cache_size ● Most important setting for good performance ● Based on memory available for filesystem cache ● SET = TRAM – (DRAM – PGRAM) ● TRAM = Total RAM ● DRAM = RAM needed by OS and other applications ● PGRAM = RAM needed for Postgres (shared_buffers, etc...) ● Guide for available memory, not an allocation
  16. 16. Sizing Memory ● work_mem ● Used by queries for sorting ● Higher values for more complex queries ● Limit is Per sort ● 5 sorts in 1 query = 5*work_mem ● maintenance_work_mem ● Used by vacuum, indexing, and similar operations ● Semi-Allocation of memory when needed ● Values up to 128MB have been found useful
  17. 17. WAL Management ● wal_buffers ● Requires restart! ● needed for write-heavy databases ● 1024kB is good starting point ● wal_sync_method ● WAL is sync'd after every transaction ● fsync is ok default, but tuning can be helpful sometimes ● http://www.westnet.com/~gsmith/content/postgresql/TuningPGWAL.htm ● synchronous_commit ● Can increase tps by large margin ● Allows data loss without corruption ● BAD: fsync=off ● GOOD: synchronous_commit=off ● Set per database, user, or transaction
  18. 18. Checkpoint Management ● checkpoint_segments ● Controls amount of data required per checkpoint ● Recommend default of 10 ● Set higher for heavy write activity ● 30-300 is not uncommon ● Increases space needed in pg_xlog ● Increases recovery time after crash ● checkpoint_completion_target ● With checkpoint_segments >= 10, set this to .9 ● http://www.westnet.com/~gsmith/content/postgresql/chkp-bgw-83.htm
  19. 19. Vacuum Management ● autovacuum ● Just do it! (Default on 8.3+) ● default_statistics_target ● Defines amount of data collected on tables for planner ● Important for good query planning ● 100 is a better default (might need further tuning)
  20. 20. Vacuum Management ● max_fsm_relations, max_fsm_pages ● Both Require Restart! ● Track dead tuples in database cluster ● fsm_relations – number of tables in all databases ● fsm_pages – number of pages with dead tuples in all databases ● “vacuum verbose” in postgres database INFO: free space map contains 5293 pages in 214 relations DETAIL: A total of 8528 page slots are in use (including overhead). 8528 page slots are required to track all free space. Current limits are: 204800 page slots, 1000 relations, using 1265 kB ● check_postgres script has a check for both ● http://bucardo.org/check_postgres/ ● Requires pg_freespacemap from contrib ● These go away in Postgres 8.4 (yay!)
  21. 21. Leftovers ● random_page_cost ● For server grade hardware, most set to 3 ● max_prepared_transactions ● Can be set to zero if not using prepared transactions ● constraint_exclusion ● Needed for table partitioning ● Good for setting at database or query level
  22. 22. The End ● Additional Resources ● http://www.postgresql.org/docs/8.3/interactive/runtime-config.html ● http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server ● Slides ● http://www.xzilla.net/writings.html ● Xìe xìe

×