Stop the database server assuming that it has been crashed.
Step 8. Rename 'data' db cluster to 'data.bad.data'
[root@localhost 8.3]#pwd
/opt/PostgreSQL/8.3/
[root@localhost 8.3]#mv data data.bad.data
Step 9. Create database cluster with name 'data' & don't initialize
[root@localhost 8.3]#pwd
/opt/PostgreSQL/8.3/
[root@localhost 8.3]#mkdir data
[root@localhost 8.3]#chown postgres:postgres -R data
[root@localhost 8.3]#chmod 0700 -R data
Step 10. Extract files from base backup
10.1 Extract files from tar file
[root@localhost pgsqlbackup]pwd
/opt/pgsqlbackup
[root@localhost pgsqlbackup]tar -xvzf pgdatabk2012Dec12.tar
10.2 After extract,move to data folder
[root@localhost pgsqlbackup]cd opt/PostgreSQL/8.3/data/
[root@localhost data]# pwd
/opt/pgsqlbackup/opt/PostgreSQL/8.3/data
10.3 Move all files from 'data' folder to 'data' folder created in
Step 9 (**user 'mv' command only)
[root@localhost data] mv * /opt/PostgreSQL/8.3/data
Step 11. Copy files from 'pg_xlog' folder of crashed 'data' folder renamed as
'data.bad.data' to 'data' cluster files copied in step 10.3
11.1.Before copying,issue commands to clear content of
'pg_xlog' of 'data' cluster files copied in step 10.3.
[root@localhost 8.3 data]#pwd
/opt/PostgreSQL/8.3/data
[root@localhost 8.3 data]#cd pg_xlog
[root@localhost 8.3 pg_xlog]#pwd
/opt/PostgreSQL/8.3/data/pg_xlog
[root@localhost 8.3 pg_xlog]#rm -f 0* (remove all wal files)
[root@localhost 8.3 pg_xlog]#cd archive_status
[root@localhost archive_status]#pwd
/opt/PostgreSQL/8.3/data/pg_xlog/archive_status
[root@localhost archive_status]rm -f 0* (remove all wal files)
** Now, no contents in pg_xlog folder except 'archive_status' folder.
11.1 Go to pg_xlog folder of 'data.bad.data'
[root@localhost 8.3 data.bad.data]#pwd
/opt/PostgreSQL/8.3/data.bad.data
[root@localhost 8.3 data.bad.data]cd pg_xlog
[root@localhost 8.3 pg_xlog]pwd
/opt/PostgreSQL/8.3/data.bad.data/pg_xlog
11.2 Move unarchived files from 'pg_xlog' folder of 'data.bad.data'
to 'pg_xlog' folder of 'data' cluster copied in step 10.3.
a) To find which are unarchived files, goto
'cd /opt/pgsqlbackup/wals/' archived folder of WAL files.
b) Find out which file is the last file in above folder.
Assume that '000000010000000000000011' is the last file in
the 'wals/' folder.From that we can understood that
from file number '000000010000000000000012' to last file
in 'pg_xlog' folder of crashed 'data.bad.data' cluster has
to be copied to 'pg_xlog' folder of 'data' cluster copied
in step 10.3
** only user copy command for copying fiels,
so that data won't be corrupted
12.Create recovery.conf file
[root@localhost 8.3 data]#pwd
/opt/PostgreSQL/8.3/data
[root@localhost 8.3 data]#vi recovery.conf
#add this content to above file
restore_command = 'cp /opt/pgsqlbackup/wals/%f %p'
13.Start Recover
[root@localhost ~] /etc/init.d/postgresql-8.3 start
or
[root@localhost ~] /opt/PostgreSQL/8.3/bin/pg_ctl start -D /opt/PostgreSQL/8.3/data -l /tmp/pg.log
a)if recovery is successful,then
- 'recovery.conf' file name is changed to 'recovery.done'
- history file is created.
- WAL segment file number sequence is changed(e.g from x to x+1)
b)check the log whether data base is recovered or not.
c)connect to database & check db restoration is done properly or not.