You are on page 1of 2

If you don't want to use or modify the scripts that I shared, you can try to set up the replication

manually. Some steps are unique to Ubuntu or


Debian configuration and filesystem. If you are in CentOS or another OS, you can adjust the commands in accordance with their installs and
OS configs.

--on MASTER:

sudo ufw disable


sudo service ufw stop
sudo apt-get update
sudo apt-get install -y postgresql-9.3
sudo mkdir /pgdata
sudo mkdir /pglog
sudo mkdir /pglog/archive
sudo mkdir /pgbackup
sudo chown -R postgres.postgres /pgdata
sudo chown -R postgres.postgres /pglog
sudo chown -R postgres.postgres /pgbackup
sudo -u postgres /usr/lib/postgresql/9.3/bin/pg_ctl stop -w -D /var/lib/postgresql/9.3/main
sudo su - root

-- Add settings to /etc/sysctl.conf for postgres to be able to access more shared memory
-- (e.g.):
kernel.sem = 250 32000 100 128
kernel.shmall = 2097152
kernel.shmmax = 943718400
kernel.shmmni = 4096

-- Configure /pgdata/postgresql.conf to desired settings, ensuring that wal_level = hot_standby


-- Configure /pgdata/pg_hba.conf

-- Continue running these commands:


sudo sysctl -p
sudo su - postgres
pg_ctl start -D /pgdata
psql
CREATE DATABASE gameplace;
select pg_start_backup('base backup for streaming rep');
create ROLE repuser SUPERUSER LOGIN CONNECTION LIMIT 1 ENCRYPTED
PASSWORD '9$8e7g6d5s4a3a21';
\q
mkdir ~/.ssh
cd ~/.ssh
ssh-keygen -t rsa

--on SLAVE:
sudo ufw disable
sudo service ufw stop
sudo apt-get update
sudo apt-get install -y postgresql-9.3
sudo mkdir /pgdata
sudo mkdir /pglog
sudo mkdir /pglog/archive
sudo mkdir /pgbackup
sudo chown -R postgres.postgres /pgdata
sudo chown -R postgres.postgres /pglog
sudo chown -R postgres.postgres /pgbackup
sudo -u postgres /usr/lib/postgresql/9.3/bin/pg_ctl stop -w -D /var/lib/postgresql/9.3/main
sudo su - root

-- Add settings to /etc/sysctl.conf for postgres to be able to access more shared memory
-- (e.g.):
kernel.sem = 250 32000 100 128
kernel.shmall = 2097152
kernel.shmmax = 943718400
kernel.shmmni = 4096

sudo su - postgres
mkdir ~/.ssh
cd ~/.ssh
ssh-keygen -t rsa

-- Add public keys to each postgres user on master and slave in authorized_keys file, like in
lecture video.

--On MASTER:
-- Replace $$SLAVE_IP$$ with your SLAVE IP or Hostname
rsync -av /pgdata -e "ssh -i ~/.ssh/id_rsa -p 22 -o UserKnownHostsFile=/dev/null -o
StrictHostKeyChecking=no" --delete --exclude server.crt --exclude server.key --exclude
recovery.done --exclude postmaster.pid --exclude archive --exclude backup_label $$SLAVE_IP$$:/

--On SLAVE:
sudo su - postgres
cd /pgdata
vi recovery.conf
-- Create file recovery.conf with these values and your MASTER IP or Hostname in $
$MASTER_IP$$:
standby_mode = 'on'
primary_conninfo = 'host=$$MASTER_IP$$ user=repuser keepalives_idle=8'
trigger_file = '/tmp/postgresql.trigger.5432'

-- Edit postgresql.conf hot_standby setting to hot_standby = on


pg_ctl start -D /pgdata

--On MASTER:
select pg_stop_backup(), current_timestamp

You might also like