PostgreSQLInstallation RunBook
PostgreSQLInstallation RunBook
Revision History
Author
Ramesh S Raj
Ramesh S Raj
Ramesh S Raj
Source
Revision
Date
Release
Number
01/17/2014
01/20/2014
03/04/2014
1.0
1.1
1.2
Table of Contents
Introduction ...................................................................................................................................... 4
Download Software .......................................................................................................................... 4
VMware Server Installation .................................................................................................... 4
Install PostgreSQL ....................................................................................................................... 4
Download PostgreSQL Installer for Linux ..................................................................... 5
Verify the Installation ......................................................................................................... 10
Accessing Server from Remote Client ............................................................................. 12
Connecting to Postgres from Client using PgAdminIII ...................................... 14
Load PostgreSQL Sample Database ...................................................................................... 15
Creating a new DVD rental database .............................. 15
Load the DVD rental database .................................... 16
Streaming Replication ............................................. 21
How to do Failover/Switchover ....................................... 30
Introduction
In this tutorial, I will show you how to install PostgreSQL in your
local system/virtual Machine for learning and practicing PostgreSQL.
Download Software
Software required in building your own PostgreSQL Server.
1. Oracle Enterprise Linux Release 6
2. PostgreSQL 9.3
Install PostgreSQL
There are three steps to complete the PostgreSQL installation:
1. Download PostgreSQL installer for Linux
2. Install PostgreSQL
3. Verify the installation
The following illustrates each step and its options for installation.
If you install a different version, you may get additional steps.
Download the PostgreSQL 9.3 downloader for Linux x64 and ftp to the
Server.
Enter the port for PostgreSQL. Make sure that no other applications
are using this port.
Uncheck Stack Builder check box and Click Finish button to complete
the installation
To this:
listen_addresses = *
Click Ok
dvdrental.tar
You can use pg_restore tool to load data into the dvdrental database
or use pgAdmin to load the data.
Select the format as directory and in the filename, select the folder
where you have extracted the zip file.
Streaming Replication
Streaming Replication
This topic explains, how to setup Streaming replication with Postgres
9.3 on RHEL6 in master slave configuration, also called as streaming
replication. This topic assumes that you have at-least two Postgres 9.3
servers for establishing replication between two database servers.
We need to take snapshot of data from master and then move that to
slave server.
You can calculate the replication lag by comparing the current WAL
write location on the primary with the last WAL location
received/replayed by the standby. They can be retrieved using
pg_current_xlog_location on the primary and the
pg_last_xlog_receive_location /pg_last_xlog_replay_location on the
standby, respectively.
On the Primary:
psql -c "SELECT pg_current_xlog_location()" -h16.150.56.52
On the Slave:
-bash-4.1$ psql -c "select pg_last_xlog_replay_location()" h16.150.56.53
-bash-4.1$ psql -c "select pg_last_xlog_receive_location()" h16.150.56.53
Sender Process:
Receiver Process:
Failover
How to do Failover/Switchover
Let us try to simulate disasters in test environment.
Create a recovery command file in the standby server; the following
parameters are required for streaming replication and failover.
Now that STANDBY has turned into MASTER, point your application
servers to it. Even if the old MASTER is running at this point, the
new MASTER is not going to replicate any changes from it.
Fail-over will not be auto the moment the primary DB or Server goes
down. It requires for us to manually intervene to introduce the
trigger_file, to overcome this we can do the following:
Create a Monitoring File in Master to:
1. Check the status of Postgres on Master every Minute/second.
2. When Server goes down, copy the log files from pg_xlog to Remote
Archive directory.
3. Create trigger file in remote machine, this will trigger recovery
on Stand-by and will be the New Master.
-x-