diff --git a/chef/cookbooks/postgresql/recipes/server.rb b/chef/cookbooks/postgresql/recipes/server.rb index 947acc4a78..c3de5fb295 100644 --- a/chef/cookbooks/postgresql/recipes/server.rb +++ b/chef/cookbooks/postgresql/recipes/server.rb @@ -98,14 +98,57 @@ change_notify = node["postgresql"]["server"]["config_change_notify"] +raw_configuration = node["postgresql"]["config"] +postgresql_configuration = {} +raw_configuration.each do |key, value| + next if value.nil? + formatted_value = case value + when String + "'#{value}'" + when TrueClass + "on" + when FalseClass + "off" + else + value + end + postgresql_configuration[key] = formatted_value +end + +reloadable_parameters = [ + "log_line_prefix" +] + +config_needs_restart = postgresql_configuration.reject do |key, value| + reloadable_parameters.include? key +end + +config_needs_reload = postgresql_configuration.select do |key, value| + reloadable_parameters.include? key +end + template "#{node['postgresql']['dir']}/postgresql.conf" do source "postgresql.conf.erb" owner "postgres" group "postgres" mode 0600 + variables( + config: config_needs_restart.sort + ) notifies change_notify, "service[postgresql]", :immediately end +template "#{node['postgresql']['dir']}/postgresql_reloadable.conf" do + source "postgresql_reloadable.conf.erb" + owner "postgres" + group "postgres" + mode "0600" + variables( + config: config_needs_reload.sort + ) + notifies :run, "bash[reload-postgresql-configuration]", :immediately +end + template "#{node['postgresql']['dir']}/pg_hba.conf" do source "pg_hba.conf.erb" owner "postgres" @@ -164,3 +207,16 @@ only_if only_if_command if ha_enabled action :run end + +# Reload the configuration file +# We use the SQL interface for that. This way it will work +# in clustered mode as well, no matter which node runs it +# first +bash "reload-postgresql-configuration" do + user "postgres" + code <<-EOH + echo "SELECT pg_reload_conf();" | psql + EOH + action :nothing +end + diff --git a/chef/cookbooks/postgresql/templates/default/postgresql.conf.erb b/chef/cookbooks/postgresql/templates/default/postgresql.conf.erb index d2facc2a3d..f90fcc6f6e 100644 --- a/chef/cookbooks/postgresql/templates/default/postgresql.conf.erb +++ b/chef/cookbooks/postgresql/templates/default/postgresql.conf.erb @@ -3,18 +3,8 @@ # Please refer to the PostgreSQL documentation for details on # configuration settings. -<% node['postgresql']['config'].sort.each do |key, value| %> -<% next if value.nil? -%> -<%= key %> = <%= - case value - when String - "'#{value}'" - when TrueClass - 'on' - when FalseClass - 'off' - else - value - end -%> +include 'postgresql_reloadable.conf' + +<% @config.each do |key, value| %> +<%= key %> = <%= value %> <% end %> diff --git a/chef/cookbooks/postgresql/templates/default/postgresql_reloadable.conf.erb b/chef/cookbooks/postgresql/templates/default/postgresql_reloadable.conf.erb new file mode 100644 index 0000000000..4eafb7a28c --- /dev/null +++ b/chef/cookbooks/postgresql/templates/default/postgresql_reloadable.conf.erb @@ -0,0 +1,3 @@ +<% @config.each do |key, value| %> +<%= key %> = <%= value %> +<% end %>