Skip to main content

Configuring Hot physical backup for PITR with continuous archiving.

Configuring Hot physical backup for PITR with continuous archiving:
The hot backup with continuous archiving help us to allow to recover the database point in time(PITR) from the time of database backup. Make sure to complete the basic requirement before starting the backup configuration, like where to store the base backup, WAL archives etc.

So, My environment contains the following,
pg01 --> PostgreSQL database server
pg03 --> Backup server
PGDATA --> Path to postgresql data directory
/u01/backups/base --> for storing the database base backup
/u01/backups/archive --> for storing WAL archives.
BACKUP_NAME--> Backup file name

Steps to configure the backup as follows,

1.) Create the backup and archive directories on backup server, if not already created. Here /u01/backups/base and /u01/backups/archive.
2.) Configure the passwordless ssh connectivity between database and backup server.
3.) Configure the database server, set the below parameters in postgresql.conf and restart the server, if not already present.
      archive_mode = on
      archive_command = 'rsync -a %p pg03:/u01/backups/archive/%f'
      [postgres@pg01 data]$ pg_ctl restart

4.) Define the name of the backup.
      export BACKUP_NAME=$(date '+%Y%m%d%H%M')

5.) start the backup as follows,
[postgres@pg01 pg_xlog]$ psql -c "select pg_start_backup('$BACKUP_NAME')"
 pg_start_backup 
-----------------
 0/1A000028
(1 row)

6.) Copy the database datafiles excluding pg_xlog directory.
[postgres@pg01 pg_xlog]$ rsync -cva --inplace --exclude='pg_xlog/*' ${PGDATA}/ pg03:/u01/backups/base/$BACKUP_NAME/
sending incremental file list
created directory /u01/backups/base/201712292232
./
PG_VERSION
<<< Msg truncated for clarity purpose >>>
sent 110553420 bytes  received 27255 bytes  17012411.54 bytes/sec
total size is 110441080  speedup is 1.00

7.) Stop the backup,
[postgres@pg01 pg_xlog]$ psql -c "select pg_stop_backup(), current_timestamp"
NOTICE:  pg_stop_backup complete, all required WAL segments have been archived
 pg_stop_backup |               now                
----------------+----------------------------------
 0/1A000248     | 2017-12-29 22:39:42.782183+05:30
(1 row)
[postgres@pg01 pg_xlog]$ 

8.) Login to pg03 server to validate the backup is created at defined location. /u01/backups/base
[postgres@pg03 201712292232]$ pwd
/u01/backups/base/201712292232
[postgres@pg03 201712292232]$ ls -ltr
total 144
-rw-------. 1 postgres postgres     4 Dec 22 00:28 PG_VERSION
drwx------. 2 postgres postgres  4096 Dec 22 00:28 pg_twophase
drwx------. 2 postgres postgres  4096 Dec 22 00:28 pg_tblspc
drwx------. 2 postgres postgres  4096 Dec 22 00:28 pg_snapshots
drwx------. 2 postgres postgres  4096 Dec 22 00:28 pg_serial
drwx------. 2 postgres postgres  4096 Dec 22 00:28 pg_replslot
drwx------. 4 postgres postgres  4096 Dec 22 00:28 pg_multixact
drwx------. 4 postgres postgres  4096 Dec 22 00:28 pg_logical
drwx------. 2 postgres postgres  4096 Dec 22 00:28 pg_dynshmem
drwx------. 2 postgres postgres  4096 Dec 22 00:28 pg_commit_ts
-rw-------. 1 postgres postgres    88 Dec 22 00:28 postgresql.auto.conf
drwx------. 2 postgres postgres  4096 Dec 22 00:28 pg_subtrans
-rw-------. 1 postgres postgres  1636 Dec 22 00:28 pg_ident.conf
drwx------. 2 postgres postgres  4096 Dec 22 00:28 pg_clog
-rw-------. 1 postgres postgres 22319 Dec 22 00:35 postgresql.conf.sample
-rw-------. 1 postgres postgres  4515 Dec 22 00:51 pg_hba.conf
drwx------. 7 postgres postgres  4096 Dec 29 20:08 base
-rw-------. 1 postgres postgres  4658 Dec 29 22:20 postgresql.conf
-rw-------. 1 postgres postgres    72 Dec 29 22:20 postmaster.pid
-rw-------. 1 postgres postgres    37 Dec 29 22:20 postmaster.opts
drwx------. 2 postgres postgres  4096 Dec 29 22:20 pg_stat
drwx------. 2 postgres postgres  4096 Dec 29 22:20 pg_notify
drwx------. 2 postgres postgres  4096 Dec 29 22:20 pg_log
drwx------. 2 postgres postgres  4096 Dec 29 22:21 global
drwx------. 2 postgres postgres  4096 Dec 29 22:34 pg_xlog
-rw-------. 1 postgres postgres   202 Dec 29 22:34 backup_label
drwx------. 2 postgres postgres  4096 Dec 29 22:35 pg_stat_tmp
[postgres@pg03 201712292232]$ 

9.) Check the archives are continuously shipping to pg03 server.
[postgres@pg03 archive]$ ls -tlr
-rw-------. 1 postgres postgres 16777216 Dec 29 17:17 00000001000000000000000A
-rw-------. 1 postgres postgres 16777216 Dec 29 17:17 00000001000000000000000B
-rw-------. 1 postgres postgres 16777216 Dec 29 22:30 000000020000000000000018
-rw-------. 1 postgres postgres 16777216 Dec 29 22:30 000000020000000000000017
-rw-------. 1 postgres postgres 16777216 Dec 29 22:30 000000020000000000000016
-rw-------. 1 postgres postgres 16777216 Dec 29 22:32 000000020000000000000019
-rw-------. 1 postgres postgres      299 Dec 29 22:39 00000002000000000000001A.00000028.backup
-rw-------. 1 postgres postgres 16777216 Dec 29 22:39 00000002000000000000001A
[postgres@pg03 archive]$

Note:- We must have both base backup and archive backup to perform the point in time recovery(PITR). Hence please plan your backup retention properly.
and finally, don;t forget to test the strategies in test or dev environment before going for production.


Comments

Popular posts from this blog

ORA-29913: error in executing ODCIEXTTABLEOPEN callout

While running oracle datapatch in 12c, ORA-29913 error raised due to corrupted external table. The error you might see while running the datapatch after patching. $ ./datapatch -verbose Connecting to database...OK Determining current state... Currently installed SQL Patches: 18522516 DBD::Oracle::st execute failed: ORA-04063: package body "SYS.DBMS_QOPATCH" has errors ORA-06508: PL/SQL: could not find program unit being called: "SYS.DBMS_QOPATCH" ORA-06512: at line 4 (DBD ERROR: OCIStmtExecute) [for Statement "DECLARE x XMLType; BEGIN x := dbms_qopatch.get_pending_activity; ? := x.getStringVal(); END;" with ParamValues: :p1=undef] at /u01/app/oracle/product/12.1.0.2/db_1/sqlpatch/sqlpatch.pm line 1293. or Connecting to database...OK catcon: ALL catcon-related output will be written to /u01/app/oracle/cfgtoollogs/sqlpatch/sqlpatch_53150146_2017_05_09_21_37_14/sqlpatch_catcon__catcon_53150146.lst catcon: See /u01/app/oracle/cfgtoollogs/sqlpatc

datapatch failed with error ORA-20009: Job Load_opatch_inventory_1execution failed

Today we have hit with issue while applying the OCT-2017 PSU. The Cluster and RDBMS software patched successfuly but while running the datapatch automation failed with below error. ERROR: Can't locate XML/Simple.pm in @INC (@INC contains: /u01/app/oracle/product/12.1.0.2/db_1/sqlpatch /u01/app/oracle/product/12.1.0.2/db_1/rdbms/admin /u01/app/oracle/product/12.1.0.2/db_1/sqlpatch/lib /u01/app/oracle/product/12.1.0.2/db_1/perl/lib/site_perl/5.14.1/x86_64-linux-thread-multi /u01/app/oracle/product/12.1.0.2/db_1/perl/lib/site_perl/5.14.1 /u01/app/oracle/product/12.1.0.2/db_1/perl/lib/5.14.1/x86_64-linux-thread-multi /u01/app/oracle/product/12.1.0.2/db_1/perl/lib/5.14.1 .) at /u01/app/oracle/product/12.1.0.2/db_1/sqlpatch/sqlpatch.pm line 173. BEGIN failed--compilation aborted at /u01/app/oracle/product/12.1.0.2/db_1/sqlpatch/sqlpatch.pm line 173. Compilation failed in require at /u01/app/oracle/product/12.1.0.2/db_1/sqlpatch/sqlpatch.pl line 64. BEGIN failed--compilatio

datapatch failed with ORA-27477: "SYS"."LOAD_OPATCH_INVENTORY_X" already exists

We have received the below error while working on the 6-node cluster patching. The patch has been applied on software GRID and RDBMS on all the node but the datapatch execution is failed with ORA-27477. rac06:dbp01:/u01/app/oracle/product/12.1.0.2/database/OPatch$ ./datapatch -verbose SQL Patching tool version 12.1.0.2.0 on Wed Oct 25 12:55:45 2017 Copyright (c) 2016, Oracle. All rights reserved. Log file for this invocation: /u01/app/oracle/cfgtoollogs/sqlpatch/sqlpatch_12298_2017_10_25_12_55_45/sqlpatch_invocation.log Connecting to database…OK Bootstrapping registry and package to current versions…done Queryable inventory could not determine the current opatch status. Execute ‘select dbms_sqlpatch.verify_queryable_inventory from dual’ and/or check the invocation log /u01/app/oracle/cfgtoollogs/sqlpatch/sqlpatch_12298_2017_10_25_12_55_45/sqlpatch_invocation.log for the complete error. Prereq check failed, exiting without installing any patches. Solution:  The