How To Set Up Master Slave Replication on PostgreSQL on an Ubuntu 12.04 VPS
How To Set Up Master Slave Replication on PostgreSQL on an Ubuntu 12.04 VPS
PostgreSQL is a powerful and popular relational database management system used by many applications and websites. In this tutorial, you will learn how to set up master slave replication on PostgreSQL on an Ubuntu 12.04 VPS.
Step 1: Install PostgreSQL
The first step is to install PostgreSQL on your Ubuntu 12.04 VPS. You can do this by running the following command:
sudo apt-get install postgresql
This will install PostgreSQL and its dependencies on your system.
Step 2: Configure the Master Server
The next step is to configure the master server. To do this, you need to edit the PostgreSQL configuration file located at /etc/postgresql/9.1/main/postgresql.conf. Open this file in your favorite text editor and add the following lines:
listen_addresses = '*'
wal_level = hot_standby
max_wal_senders = 5
checkpoint_segments = 8
archive_mode = on
archive_command = 'cd /var/lib/postgresql/9.1/archive && cp %p %f'
Save the file and restart PostgreSQL with the following command:
sudo /etc/init.d/postgresql restart
Step 3: Configure the Slave Server
The next step is to configure the slave server. You need to edit the PostgreSQL configuration file located at /etc/postgresql/9.1/main/postgresql.conf. Open this file in your favorite text editor and add the following lines:
hot_standby = on
recovery_target_timeline = 'latest'
Save the file and restart PostgreSQL with the following command:
sudo /etc/init.d/postgresql restart
Step 4: Create a Replication User
The next step is to create a replication user. To do this, you need to switch to the PostgreSQL command line by running the following command:
sudo su postgres
psql
Once you are in the PostgreSQL command line, create a replication user with the following command:
CREATE USER replication_user REPLICATION LOGIN CONNECTION LIMIT 1 ENCRYPTED PASSWORD 'your_password_here';
Replace 'your_password_here' with a strong password.
Step 5: Set Up Replication
The final step is to set up replication. To do this, you need to edit the PostgreSQL configuration file located at /etc/postgresql/9.1/main/pg_hba.conf. Open this file in your favorite text editor and add the following line:
Комментарии
Отправить комментарий