Hot Standby in PostgreSQL 9.0:
As per definition of Hot Standby, its a method of redundancy in which primay and secondary (Backup Server) runs simultaneously. The data is mirrored to secondary so that both should contain identical data in real time. With this user, would be able to execute the Query against Database while secondary is in archive recovery mode.
This is what introduce in PG9.0. In-built Hot Standby.
PostgreSQL Community always try to make the things simpler as much as possible, same they have proven in Hot Standby Implementation.
Following are the steps of configuring Hot Standby:
1. Make sure following parameters are set in Configuration file, postgresql.conf of Primary:
a) Execute following command in Primary:
6. Remove the postmaster.pid file from Hot Standby Data Directory.
7. Now start the Instance using following command:
Following are few snapshots (Primary Port is 5432 and Hot Standby Port 5433:
1. Here I have inserted one value in table "test" and created a new table test2 with some records:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOZBTzCGVKRip2z_0qouRIsCPwj0Yg7kXWly3b8Nle4qdo1uD2yEZ-zreenWVWxpkwqc1EFR93p-0owvtQ3wRZJdOBbW6SYZpGdvNn2w9BMGpV3nxMkOs7DWqV6Egl_PRn0_oHnRPqImRJ/s320/Screen+shot+2010-09-29+at+4.15.19+AM.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2O8xxnIx5z8iQMpPS8RvuIwH4pNoCT6Z9UJ1yBVVoEvSAJYxtUn5KMui_UZMdVva97ItNDe8nalOHTzl9StwbJCDjKumcfeQy86B1xc7KmSrOwcdi2xstIJiy_3fmqS-Rwa7FFRjfjlsz/s320/Screen+shot+2010-09-29+at+4.17.11+AM.png)
wal_level = ‘hot_standby’ archive_mode = on archive_command = ‘cp %p /Library/PostgreSQL/9.0/data/archivelog/%f’2. After setting the above parameters, Now take the hot backup of PG9.0 Instance. Steps of Hot Backup is simple:
a) Execute following command in Primary:
select pg_start_backup(‘Hot Standby Backup’);b) Take the file system backup of PG 9.0 Data directory, as given below:
cp -r $PRIMARY/* $HTStandby/c). Execute following command to stop the Hot Backup:
select pg_stop_backup();3. After taking the Hot Backup and restoring it desired location, set following parameter in postgresql.conf file of Hot Standby:
hot_standby = on4. Create a recovery.conf file in Hot Standby restore location and set the following parameters:
standby_mode = 'on' restore_command = 'cp /Library/PostgreSQL/9.0/data/archivelog/%f %p'5. Clean the pg_xlog and pg_xlog/archive_status directories of Hot Standby Data directory.
6. Remove the postmaster.pid file from Hot Standby Data Directory.
7. Now start the Instance using following command:
pg_ctl -D $HTStandby startNow, hot standby is up and running.
Following are few snapshots (Primary Port is 5432 and Hot Standby Port 5433:
1. Here I have inserted one value in table "test" and created a new table test2 with some records:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOZBTzCGVKRip2z_0qouRIsCPwj0Yg7kXWly3b8Nle4qdo1uD2yEZ-zreenWVWxpkwqc1EFR93p-0owvtQ3wRZJdOBbW6SYZpGdvNn2w9BMGpV3nxMkOs7DWqV6Egl_PRn0_oHnRPqImRJ/s320/Screen+shot+2010-09-29+at+4.15.19+AM.png)
2. Now on Standby Following is a snapshot:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2O8xxnIx5z8iQMpPS8RvuIwH4pNoCT6Z9UJ1yBVVoEvSAJYxtUn5KMui_UZMdVva97ItNDe8nalOHTzl9StwbJCDjKumcfeQy86B1xc7KmSrOwcdi2xstIJiy_3fmqS-Rwa7FFRjfjlsz/s320/Screen+shot+2010-09-29+at+4.17.11+AM.png)
Nice post.. One step is missing. - After taking the base backup, one needs to remove postmaster.pid from the standby cluster directory.
ReplyDelete-Sandeep
Thanks Sandeep. Included..
ReplyDeleteHey Vibhor,
ReplyDeleteSlony is giving me same features,then why should i go for streaming replication ?
Please comment.
-Rajiv
Following are the reasons which you can consider for using Streaming Replication:
ReplyDelete1. It replicates data and DDLs Both.
2. Replication lag time is very very less.
3. There is no overhead of Triggers in Streaming Replication.
4. Failover is easier than Slony.