Created
August 6, 2010 23:56
-
-
Save adamhjk/512232 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Cookbook Name:: postgresql | |
# Library:: helpers | |
# | |
# Copyright 2010, Estately, Inc. | |
# | |
# All rights reserved - Do Not Redistribute | |
# | |
module Foo | |
class << self | |
# postgresql.conf allows you to set values using numbers (in bytes) or | |
# strings ending in kB, MB, or GB. This method takes any of those values | |
# and converts it to bytes. | |
def translate_size( size ) | |
return size if size.is_a? Numeric | |
value, units = size.match( /^(\d+)(\w+)$/ )[1,2] | |
case units | |
when "kB" | |
return value * 1024 | |
when "MB" | |
return value * 1_048_576 | |
when "GB" | |
return value * 1_073_741_824 | |
end | |
end | |
# based on the information contained in table 17-2 in the postgres | |
# manual. | |
# | |
# http://www.postgresql.org/docs/8.4/static/kernel-resources.html | |
def calculate_shmmax | |
requirements = [] | |
# we'll be using this again... | |
mlpt = translate_size( node.max_locks_per_transaction ) | |
# base memory | |
requirements << translate_size( "770kB" ) | |
# memory per connection | |
requirements << (1800 + 270 * mlpt) * node.max_connections | |
# memory per autovacuum worker | |
requirements << (1800 + 270 * mlpt) * node.autovacuum_max_workers | |
# memory per prepared transaction | |
requirement << (770 + 270 * mlpt) * node.max_prepared_transactions | |
# shared disk buffers | |
requirements << (node.block_size + 208) * translate_size(node.shared_buffers) | |
# WAL buffers | |
requirements << (node.wal_block_size + 8) * translate_size(node.wal_buffers) | |
return requirements.inject(0) {|sum, value| sum += value } | |
end | |
end | |
end | |
# Foo.calculate_shmmax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment