Delete Orphaned Datafile Copies

Oracle Incrementally Updated Backups : Delete Orphaned (Expired) Datafile Copies

Oracle recommends adopting a merged incremental disk backup strategy to ensure efficient database protection and faster recovery times. This approach involves maintaining an up-to-date image copy of the database as the base backup while continuously applying incremental backups to it on the fly.

When using the Oracle recommended disk backup strategy, the retention policy should be set to REDUNDANCY 1, and the image copy should ideally be created within the Fast Recovery Area (FRA). FRA provides a centralized and managed location for backup and recovery files. Block Change Tracking (BCT) is highly recommended as it enhances incremental backup efficiency by recording changes to database blocks since the last backup, eliminating the need to scan the entire database during backup operations. Cumulative incremental backups should be taken and applied daily to roll forward the base backup.

We use a script similar to provided below.

connect catalog /@catdb
connect target /
RUN
{
SQL 'alter system checkpoint global';
ALLOCATE CHANNEL cblt1 device type DISK;
ALLOCATE CHANNEL cblt2 device type DISK;
BACKUP CHECK LOGICAL
INCREMENTAL LEVEL 1
FOR RECOVER OF COPY WITH TAG 'v'
DATABASE;
RECOVER COPY OF DATABASE
WITH TAG 'bltdb_update';
RELEASE CHANNEL cblt1;
RELEASE CHANNEL cblt2;
}
allocate channel for maintenance type DISK;
run
{
# delete incremental backups taken to apply on image copy
delete noprompt backup tag 'bltdb_update';
}
release channel;
exit

This strategy enables quick failover using the SWITCH DATABASE TO COPY command, allowing the database to point directly to the updated image copy without requiring a restore operation. Fewer archive logs are needed for recovery since the image copy is consistently rolled forward. For instance, only logs from the last 24 hours might be necessary if incremental updates are applied daily.

However, maintaining a full image copy of the database requires additional disk space, which may be a limitation for larger databases. Another limitation is that point-in-time recovery is restricted to dates after the last incremental backup was applied to the image copy. For example, if the image copy is updated daily, recovery to a point earlier than 24 hours may require alternative backup strategies.

This strategy works best when the retention policy is set to REDUNDANCY 1. If a different retention policy, such as RECOVERY WINDOW, is used, RMAN may not satisfy the policy with only one up-to-date image copy. To address this, DBAs need to create custom scripts to retain older versions of the image copy. For example, if a recovery window of seven days is required, the image copy must be retained for at least eight days using the UNTIL clause.

The database copy cannot be compressed or encrypted.

I want to share another important point I recently encountered, which I believe is often forgotten.

When you drop a tablespace or delete a datafile in Oracle, the datafiles associated with the base image copy are not automatically removed from the file system or ASM (Automatic Storage Management).

While the original datafile is dropped during the operation, its corresponding backup or image copy remains intact in the backup location. This behavior ensures that any backups, particularly those created for recovery purposes, are preserved unless explicitly removed. Since backup policies are typically written once and not revisited, these datafile copies are often forgotten in fast recovery area

To handle these leftover image copies, you must either manually delete the files from the file system or use RMAN commands to manage them. In our case, there were 20 datafiles leftover in the Fast Recovery Area. You can also detect the anomaly by comparing the count from v$datafile with the number_of_files value in v$recovery_area_usage.

SQL> select count(*) as datafile_count from v$datafile

DATAFILE_COUNT

————————————

298

SQL> select number_of_files from v$recovery_area_usage where file_type = ‘IMAGE COPY’;

NUMBER_OF_FILES

—————————————-

318

After identifying discrepancies in the number of datafiles between the database and the image copy, you can compare the outputs of v$datafile and v$datafile_copy, or use the RMAN command LIST DATAFILECOPY ALL.

You may delete the current database copy and take a new base backup. However, this method will require backing up all datafiles again, without utilizing incremental backups, which may result in a longer backup duration, especially for large databases. Alternatively, you can manually remove the leftover datafiles from the file system or ASM using the rm command. Afterward, perform a crosscheck in RMAN to detect the absence of these datafile copies. Then, you can run the DELETE EXPIRED command to remove the metadata of these backups from the catalog or control file.

You may feel comfortable deleting them once you’re certain that you’re in the fast_recovery_area and not in the db_create_file_dest location.

ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_APP.8889.1062728795
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_APP.28091.1070850253
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_APP.11430.1065147933
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_DOC.10223.1062123865
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_DOC.28060.1070850307
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_DOC.21758.1067221723
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_APP.12171.1070158731
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_APP.1518.1070763355
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_APP.3629.1070158867
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_APP.8275.1070763527
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_APP.27009.1067221785
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_APP.28036.1070850403
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_APP.10100.1062729049
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_APP.27032.1067221815
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_BI.15964.1060913539
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_ARCHIVE.17004.1121941201
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_ARCHIVE.7277.1121941227
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_APP.28002.1070850463
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_BI.25410.1062728149
ASMCMD> rm -f +RECO/BLTDB/DATAFILE/AI_BI.9995.1062728529
RMAN> crosscheck datafilecopy all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1011 instance=BLTDB1 device type=DISK
...
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_APP.8889.1062728795 RECID=787905 STAMP=1117246444
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_APP.28091.1070850253 RECID=787914 STAMP=1117246667
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_APP.11430.1065147933 RECID=787909 STAMP=1117246552
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_nsn.10824.1065060539 RECID=794004 STAMP=1118628343
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_nsn.28084.1070850253 RECID=794005 STAMP=1118628370
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_nsn.19463.1070158163 RECID=794006 STAMP=1118628392
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_nsn.22174.1070762791 RECID=794007 STAMP=1118628395
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_nsn.11939.1070762839 RECID=794002 STAMP=1118628281
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_DOC.10223.1062123865 RECID=794009 STAMP=1116122711
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_DOC.28060.1070850307 RECID=794008 STAMP=1116122705
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_DOC.21758.1067221723 RECID=794010 STAMP=1116122799
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_APP.12171.1070158731 RECID=787908 STAMP=1117246548
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_APP.1518.1070763355 RECID=787911 STAMP=1117246615
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_APP.3629.1070158867 RECID=787912 STAMP=1117246616
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_APP.8275.1070763527 RECID=787907 STAMP=1117246506
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_APP.27009.1067221785 RECID=787913 STAMP=1117246623
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_APP.28036.1070850403 RECID=787903 STAMP=1117246412
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_APP.10100.1062729049 RECID=787906 STAMP=1117246445
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_APP.27032.1067221815 RECID=787904 STAMP=1117246419
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_BI.15964.1060913539 RECID=787924 STAMP=1117419412
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_ARCHIVE.17004.1121941201 RECID=794062 STAMP=1121997882
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_ARCHIVE.7277.1121941227 RECID=794099 STAMP=1121997943
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_APP.28002.1070850463 RECID=787910 STAMP=1117246589
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_BI.25410.1062728149 RECID=787919 STAMP=1117419302
validation failed for DATAFILE copy
DATAFILE copy file name=+RECO/BLTDB/DATAFILE/AI_BI.9995.1062728529 RECID=787916 STAMP=1117419158
validation failed for DATAFILE copy
Crosschecked .... objects

Implementing a merged incremental disk backup strategy ensures efficient database protection and faster recovery by maintaining an up-to-date image copy as the foundation for incremental updates. Additionally, DBAs must remain proactive in managing orphaned datafiles after tablespace deletions to keep the base image copy synchronized with the database and prevent unnecessary storage consumption.

Hope it helps.


Discover More from Osman DİNÇ


Comments

Leave your comment