Last active
August 29, 2015 13:57
-
-
Save clarkdave/9786643 to your computer and use it in GitHub Desktop.
(CHEF) change PostgreSQL (9.2) data directory
This file contains 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
# changing the postgresql data directory is an annoyingly non-trivial and fragile operation | |
# this should mostly do it but there are lots of things that can go wrong and if/when they do | |
# you will have lots of fun trying to eradicate broken postgres installs between chef runs | |
# | |
config_dir = "etc/postgresql/#{node[:postgresql][:version]}/main" | |
bash 'change_data_directory' do | |
code <<-CODE | |
mkdir /tmp/pg_conf_backup | |
cp #{config_dir}/*.conf /tmp/pg_conf_backup/ | |
pg_dropcluster --stop 9.2 main | |
pg_createcluster --locale=en_US.utf8 9.2 -d /data/postgresql main | |
cp /tmp/pg_conf_backup/*.conf #{config_dir}/ | |
chmod 0600 #{config_dir}/postgresql.conf #{config_dir}/pg_hba.conf | |
sed -i -e"s:data_directory.*$:data_directory = '/data/postgresql':" #{config_dir}/postgresql.conf | |
CODE | |
not_if { | |
::FileTest.exist?(File.join('/data/postgresql', 'PG_VERSION')) | |
} | |
notifies :create, 'ruby_block[set_data_directory]', :immediately | |
end | |
ruby_block 'set_data_directory' do | |
block do | |
# we forcibly set the data directory for this node here, because we couldn't set it | |
# earlier or it'd break the first start of postgresql (for goodness sake!) | |
node.set[:postgresql][:config][:data_directory] = '/data/postgresql' | |
end | |
action :nothing | |
notifies :start, 'service[postgresql]', :immediately | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment