Skip to content

Instantly share code, notes, and snippets.

@jfrost
Created September 4, 2015 20:52
Show Gist options
  • Save jfrost/2478f8917b6d58a300a3 to your computer and use it in GitHub Desktop.
Save jfrost/2478f8917b6d58a300a3 to your computer and use it in GitHub Desktop.
PostgreSQL Configuration ERB Template
#########################################################
#
# puppet generated postgresql.conf
# Memory size: <%= memorysize %>
# max_connections: <%= max_connections %>
# Lun Fileystems: <%= lun_filesystem %>
#
#########################################################
listen_addresses = '*'
port = 5432
max_connections = <%= max_connections %>
unix_socket_directory = '/var/run/postgresql'
<% if ((memorysize.to_f * (memorysize.include?('GB') ? 1024 : 1 )) * 0.25).round <=8096 -%>
shared_buffers = <%= ((memorysize.to_f * (memorysize.include?('GB') ? 1024 : 1 )) * 0.25).round %>MB
<% else -%>
shared_buffers = 8096MB
<% end -%>
temp_buffers = <%= ((memorysize.to_f * (memorysize.include?('GB') ? 1024 : 1 )) / max_connections * 2 ).round %>MB
work_mem = <%= ((memorysize.to_f * (memorysize.include?('GB') ? 1024 : 1 )) / max_connections ).round %>MB
<% if ((memorysize.to_f * (memorysize.include?('GB') ? 1024 : 1 )) / 16 ).round <= 2048 -%>
maintenance_work_mem = <%= ((memorysize.to_f * (memorysize.include?('GB') ? 1024 : 1 )) / 16 ).round %>MB
<% else -%>
maintenance_work_mem = 2048MB
<% end -%>
wal_level = hot_standby
fsync = on
checkpoint_segments = 15
<% if lun_filesystem == "ext3" -%>
checkpoint_completion_target = 0.0
<% else -%>
checkpoint_completion_target = 0.9
<% end -%>
effective_cache_size = <%= ((memorysize.to_f * (memorysize.include?('GB') ? 1024 : 1 )) * 0.75 ).round %>MB
logging_collector = on
log_destination = csvlog
log_directory = 'pg_log'
log_filename = 'postgresql-%a.log'
log_file_mode = 0644
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 0
log_min_duration_statement = 1000
log_checkpoints = on
log_lock_waits = on
log_temp_files = 0
autovacuum = on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment