diff --git a/config/postgres_hba.conf b/config/postgres_hba.conf index 54928434a..790335f10 100644 --- a/config/postgres_hba.conf +++ b/config/postgres_hba.conf @@ -81,15 +81,15 @@ # maintenance (custom daily cronjobs, replication, and similar tasks). # # Database administrative login by Unix domain socket -local all postgres peer +# local all postgres peer # TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only # IPv4 local connections: -host all all 127.0.0.1/32 md5 +# host all all 127.0.0.1/32 md5 # IPv6 local connections: -host all all ::1/128 md5 +# host all all ::1/128 md5 # Allow replication connections from localhost, by a user with the # replication privilege. #local replication postgres peer diff --git a/config/postgresql.conf b/config/postgresql.conf index b477faecc..13f4ac37e 100644 --- a/config/postgresql.conf +++ b/config/postgresql.conf @@ -38,15 +38,15 @@ # The default values of these variables are driven from the -D command-line # option or PGDATA environment variable, represented here as ConfigDir. -data_directory = '/var/lib/postgresql/10/main' # use data in another directory +data_directory = '/var/lib/postgresql/9.4/main' # use data in another directory # (change requires restart) -hba_file = '/etc/postgresql/10/main/pg_hba.conf' # host-based authentication file +hba_file = '/etc/postgresql/9.4/main/pg_hba.conf' # host-based authentication file # (change requires restart) -ident_file = '/etc/postgresql/10/main/pg_ident.conf' # ident configuration file +ident_file = '/etc/postgresql/9.4/main/pg_ident.conf' # ident configuration file # (change requires restart) # If external_pid_file is not explicitly set, no extra PID file is written. -external_pid_file = '/var/run/postgresql/10-main.pid' # write an extra PID file +external_pid_file = '/var/run/postgresql/9.4-main.pid' # write an extra PID file # (change requires restart) diff --git a/fabfile.py b/fabfile.py index 4cdf3bdb4..1aa977505 100644 --- a/fabfile.py +++ b/fabfile.py @@ -1046,38 +1046,38 @@ def setup_postgres(standby=False): sudo('echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list') sudo('wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -') sudo('apt-get update') - sudo('apt-get -y install postgresql-10 postgresql-client-10 postgresql-contrib-10 libpq-dev') - put('config/postgresql.conf', '/etc/postgresql/10/main/postgresql.conf', use_sudo=True) - put('config/postgres_hba.conf', '/etc/postgresql/10/main/pg_hba.conf', use_sudo=True) - sudo('mkdir /var/lib/postgresql/10/archive') - sudo('chown -R postgres.postgres /etc/postgresql/10/main') - sudo('chown -R postgres.postgres /var/lib/postgresql/10/main') - sudo('chown -R postgres.postgres /var/lib/postgresql/10/archive') + sudo('apt-get -y install postgresql-9.4 postgresql-client-9.4 postgresql-contrib-9.4 libpq-dev') + put('config/postgresql.conf', '/etc/postgresql/9.4/main/postgresql.conf', use_sudo=True) + put('config/postgres_hba.conf', '/etc/postgresql/9.4/main/pg_hba.conf', use_sudo=True) + sudo('mkdir -p /var/lib/postgresql/9.4/archive') + sudo('chown -R postgres.postgres /etc/postgresql/9.4/main') + sudo('chown -R postgres.postgres /var/lib/postgresql/9.4/main') + sudo('chown -R postgres.postgres /var/lib/postgresql/9.4/archive') sudo('echo "%s" | sudo tee /proc/sys/kernel/shmmax' % shmmax) sudo('echo "\nkernel.shmmax = %s" | sudo tee -a /etc/sysctl.conf' % shmmax) sudo('echo "\nvm.nr_hugepages = %s\n" | sudo tee -a /etc/sysctl.conf' % hugepages) run('echo "ulimit -n 100000" > postgresql.defaults') sudo('mv postgresql.defaults /etc/default/postgresql') sudo('sysctl -p') - sudo('rm /lib/systemd/system/postgresql.service') # Ubuntu 16 has wrong default + sudo('rm -f /lib/systemd/system/postgresql.service') # Ubuntu 16 has wrong default sudo('systemctl daemon-reload') sudo('systemctl enable postgresql') if standby: - put('config/postgresql_recovery.conf', '/var/lib/postgresql/10/recovery.conf', use_sudo=True) - sudo('chown -R postgres.postgres /var/lib/postgresql/10/recovery.conf') + put('config/postgresql_recovery.conf', '/var/lib/postgresql/9.4/recovery.conf', use_sudo=True) + sudo('chown -R postgres.postgres /var/lib/postgresql/9.4/recovery.conf') sudo('/etc/init.d/postgresql stop') sudo('/etc/init.d/postgresql start') def config_postgres(standby=False): - put('config/postgresql.conf', '/etc/postgresql/10/main/postgresql.conf', use_sudo=True) - put('config/postgres_hba.conf', '/etc/postgresql/10/main/pg_hba.conf', use_sudo=True) - sudo('chown postgres.postgres /etc/postgresql/10/main/postgresql.conf') + put('config/postgresql.conf', '/etc/postgresql/9.4/main/postgresql.conf', use_sudo=True) + put('config/postgres_hba.conf', '/etc/postgresql/9.4/main/pg_hba.conf', use_sudo=True) + sudo('chown postgres.postgres /etc/postgresql/9.4/main/postgresql.conf') run('echo "ulimit -n 100000" > postgresql.defaults') sudo('mv postgresql.defaults /etc/default/postgresql') - sudo('/etc/init.d/postgresql reload 10') + sudo('/etc/init.d/postgresql reload 9.4') def upgrade_postgres(): sudo('su postgres -c "/usr/lib/postgresql/10/bin/pg_upgrade -b /usr/lib/postgresql/9.4/bin -B /usr/lib/postgresql/10/bin -d /var/lib/postgresql/9.4/main -D /var/lib/postgresql/10/main"') @@ -1088,18 +1088,16 @@ def copy_postgres_to_standby(master='db01'): # Make sure you can ssh from master to slave and back with the postgres user account. # Need to give postgres accounts keys in authroized_keys. - # local: fab host:old copy_ssh_keys:postgres,private=True - # new: ssh old - # new: sudo su postgres -c "rsync old" + # local: fab host:new copy_ssh_keys:postgres,private=True # new: sudo su postgres; ssh old # old: sudo su postgres; ssh new # old: sudo su postgres -c "psql -c \"SELECT pg_start_backup('label', true)\"" sudo('systemctl stop postgresql') - sudo('mkdir -p /var/lib/postgresql/10/archive') - sudo('chown postgres.postgres /var/lib/postgresql/10/archive') + sudo('mkdir -p /var/lib/postgresql/9.4/archive') + sudo('chown postgres.postgres /var/lib/postgresql/9.4/archive') with settings(warn_only=True): - sudo('su postgres -c "rsync -Pav -e \'ssh -i ~postgres/.ssh/newsblur.key\' --stats --progress postgres@%s:/var/lib/postgresql/10/main /var/lib/postgresql/10/ --exclude postmaster.pid"' % master) - put('config/postgresql_recovery.conf', '/var/lib/postgresql/10/main/recovery.conf', use_sudo=True) + sudo('su postgres -c "rsync -Pav -e \'ssh -i ~postgres/.ssh/newsblur.key\' --stats --progress postgres@%s:/var/lib/postgresql/9.4/main /var/lib/postgresql/9.4/ --exclude postmaster.pid"' % master) + put('config/postgresql_recovery.conf', '/var/lib/postgresql/9.4/main/recovery.conf', use_sudo=True) sudo('systemctl start postgresql') # old: sudo su postgres -c "psql -c \"SELECT pg_stop_backup()\"" @@ -1750,8 +1748,8 @@ def setup_postgres_backups(): # crontab for postgres backups crontab = """ 0 4 * * * /srv/newsblur/venv/newsblur/bin/python /srv/newsblur/utils/backups/backup_psql.py -0 * * * * sudo find /var/lib/postgresql/10/archive -mtime +1 -exec rm {} \; -0 * * * * sudo find /var/lib/postgresql/10/archive -type f -mmin +180 -delete""" +0 * * * * sudo find /var/lib/postgresql/9.4/archive -mtime +1 -exec rm {} \; +0 * * * * sudo find /var/lib/postgresql/9.4/archive -type f -mmin +180 -delete""" run('(crontab -l ; echo "%s") | sort - | uniq - | crontab -' % crontab) run('crontab -l')