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 service "postgresql" do
23 action [ :enable, :start ]
24 supports :status => true, :restart => true, :reload => true
27 node[:postgresql][:versions].each do |version|
28 package "postgresql-#{version}"
29 package "postgresql-client-#{version}"
30 package "postgresql-contrib-#{version}"
31 package "postgresql-server-dev-#{version}"
33 defaults = node[:postgresql][:settings][:defaults] || {}
34 settings = node[:postgresql][:settings][version] || {}
36 template "/etc/postgresql/#{version}/main/postgresql.conf" do
37 source "postgresql.conf.erb"
41 variables :version => version, :defaults => defaults, :settings => settings
42 notifies :reload, "service[postgresql]"
45 template "/etc/postgresql/#{version}/main/pg_hba.conf" do
46 source "pg_hba.conf.erb"
50 variables :early_rules => settings[:early_authentication_rules] || defaults[:early_authentication_rules],
51 :late_rules => settings[:late_authentication_rules] || defaults[:late_authentication_rules]
52 notifies :reload, "service[postgresql]"
55 template "/etc/postgresql/#{version}/main/pg_ident.conf" do
56 source "pg_ident.conf.erb"
60 variables :maps => settings[:user_name_maps] || defaults[:user_name_maps]
61 notifies :reload, "service[postgresql]"
64 link "/var/lib/postgresql/#{version}/main/server.crt" do
65 to "/etc/ssl/certs/ssl-cert-snakeoil.pem"
68 link "/var/lib/postgresql/#{version}/main/server.key" do
69 to "/etc/ssl/private/ssl-cert-snakeoil.key"
72 restore_command = settings[:restore_command] || defaults[:restore_command]
73 standby_mode = settings[:standby_mode] || defaults[:standby_mode]
75 if restore_command || standby_mode == "on"
76 template "/var/lib/postgresql/#{version}/main/recovery.conf" do
77 source "recovery.conf.erb"
81 variables :defaults => defaults, :settings => settings
82 notifies :reload, "service[postgresql]"
85 template "/var/lib/postgresql/#{version}/main/recovery.conf" do
87 notifies :reload, "service[postgresql]"
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 if File.exist?("/var/lib/postgresql/#{details[:version]}/main/recovery.conf")
135 munin_plugin "postgres_replication_#{suffix}" do
136 target "postgres_replication"
138 conf_variables :port => details[:port]