2 # Cookbook Name:: postgresql
5 # Copyright 2012, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 package "postgresql-common"
22 node[:postgresql][:versions].each do |version|
23 package "postgresql-#{version}"
24 package "postgresql-client-#{version}"
25 package "postgresql-contrib-#{version}"
26 package "postgresql-server-dev-#{version}"
28 defaults = node[:postgresql][:settings][:defaults] || {}
29 settings = node[:postgresql][:settings][version] || {}
31 template "/etc/postgresql/#{version}/main/postgresql.conf" do
32 source "postgresql.conf.erb"
36 variables :version => version, :defaults => defaults, :settings => settings
37 notifies :reload, "service[postgresql]"
40 template "/etc/postgresql/#{version}/main/pg_hba.conf" do
41 source "pg_hba.conf.erb"
45 variables :early_rules => settings[:early_authentication_rules] || defaults[:early_authentication_rules],
46 :late_rules => settings[:late_authentication_rules] || defaults[:late_authentication_rules]
47 notifies :reload, "service[postgresql]"
50 template "/etc/postgresql/#{version}/main/pg_ident.conf" do
51 source "pg_ident.conf.erb"
55 variables :maps => settings[:user_name_maps] || defaults[:user_name_maps]
56 notifies :reload, "service[postgresql]"
59 link "/var/lib/postgresql/#{version}/main/server.crt" do
60 to "/etc/ssl/certs/ssl-cert-snakeoil.pem"
63 link "/var/lib/postgresql/#{version}/main/server.key" do
64 to "/etc/ssl/private/ssl-cert-snakeoil.key"
67 restore_command = settings[:restore_command] || defaults[:restore_command]
68 standby_mode = settings[:standby_mode] || defaults[:standby_mode]
70 if restore_command || standby_mode == "on"
71 template "/var/lib/postgresql/#{version}/main/recovery.conf" do
72 source "recovery.conf.erb"
76 variables :defaults => defaults, :settings => settings
77 notifies :reload, "service[postgresql]"
80 template "/var/lib/postgresql/#{version}/main/recovery.conf" do
82 notifies :reload, "service[postgresql]"
87 service "postgresql" do
88 action [:enable, :start]
89 supports :status => true, :restart => true, :reload => true
92 ohai_plugin "postgresql" do
93 template "ohai.rb.erb"
97 package "libdbd-pg-perl"
99 clusters = node[:postgresql][:clusters] || []
101 clusters.each do |name, details|
102 suffix = name.tr("/", ":")
104 munin_plugin "postgres_bgwriter_#{suffix}" do
105 target "postgres_bgwriter"
107 conf_variables :port => details[:port]
110 munin_plugin "postgres_checkpoints_#{suffix}" do
111 target "postgres_checkpoints"
113 conf_variables :port => details[:port]
116 munin_plugin "postgres_connections_db_#{suffix}" do
117 target "postgres_connections_db"
119 conf_variables :port => details[:port]
122 munin_plugin "postgres_users_#{suffix}" do
123 target "postgres_users"
125 conf_variables :port => details[:port]
128 munin_plugin "postgres_xlog_#{suffix}" do
129 target "postgres_xlog"
131 conf_variables :port => details[:port]
134 next unless File.exist?("/var/lib/postgresql/#{details[:version]}/main/recovery.conf")
136 munin_plugin "postgres_replication_#{suffix}" do
137 target "postgres_replication"
139 conf_variables :port => details[:port]