Skip to Main Content
  • Questions
  • Best practice for "archiving" legacy tables and their data

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Phil.

Asked: October 04, 2019 - 6:29 pm UTC

Last updated: October 21, 2019 - 12:14 pm UTC

Version: 12.1.0.2.0

Viewed 1000+ times

You Asked

Hi,

I recently removed the last piece of front-end functionality that relied on a table, and am certain that that table and its data is no longer needed for the application to function. We'll have more similar tables in this situation in the near future, none of which should have more than a few thousand narrow rows.

The front end source code is in a git repo, so even after I "remove" it, I still always have the option of finding it in the off chance I'll ever need to look at it again.
However, I can't decide what to do about that obsolete table data. I'm 99.9% certain we'll never need to look at it again, but there's always a minuscule chance of needing it for some retroactive investigation in the future.

I guess we can just append its name with "_archive" or something, but I don't love the idea of seeing unused tables amongst actively used ones in production.

I have another idea of creating a "LEGACY_DATA" table with columns: table_name, archived_on, & data (lob). Then I could output all the data in the table I no longer need into something like json and store it in the data field of the LEGACY_DATA table.

Any issues with this latter approach? Or are there any best practices you guys recommend for such situations?

Thanks,
Phil

and Connor said...

For me, I would not bother "modifying" the table strucutre - just seems like effort I don't need to do. I'd just create a new schema for stuff that "might" be needed one day.

create user OLD_STUFF;
create table old_stuff.my_table as select * from my_app.my_table;

No-one will see the OLD_STUFF schema - there will be no privs on it, but your tables are there easily accessible to an admin should it ever be needed.

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

In-Database Archiving feature from 12.1.0.1

Rajeshwaran, Jeyabal, October 07, 2019 - 2:53 pm UTC

Team,

How about using the "In-Database archiving feature" introduced in 12.1.0.1 for this.

https://docs.oracle.com/database/121/NEWFT/chapter12101.htm#NEWFT237

Say, i got an EMP table with sample of four rows in it .

demo@ORA12C> create table emp as
  2  select rownum as empno,
  3     object_name as ename,
  4     object_id as sal
  5  from all_objects
  6  where rownum <=4;

Table created.

demo@ORA12C> select * from emp;

     EMPNO ENAME                       SAL
---------- -------------------- ----------
         1 ORA$BASE                    133
         2 DUAL                        142
         3 DUAL                        143
         4 MAP_OBJECT                  356

4 rows selected.

to enable in-database archival, we need an alter statement like this.
demo@ORA12C> alter table emp row archival;

Table altered.

demo@ORA12C> select emp.*,ora_archive_state from emp;

     EMPNO ENAME                       SAL ORA_ARCHIV
---------- -------------------- ---------- ----------
         1 ORA$BASE                    133 0
         2 DUAL                        142 0
         3 DUAL                        143 0
         4 MAP_OBJECT                  356 0

4 rows selected.

Say if we need to archive the rows with empno in (1,2) then do an update like this.

demo@ORA12C> update emp set
  2     ora_archive_state = dbms_ilm.archiveStateName(1)
  3  where empno in (1,2);

2 rows updated.

demo@ORA12C> commit;

Commit complete.

demo@ORA12C>
demo@ORA12C> select * from emp;

     EMPNO ENAME                       SAL
---------- -------------------- ----------
         3 DUAL                        143
         4 MAP_OBJECT                  356

2 rows selected.

to get all the rows back, we need to do an alter session like this.

demo@ORA12C> alter session set row archival visibility=all;

Session altered.

demo@ORA12C> select * from emp;

     EMPNO ENAME                       SAL
---------- -------------------- ----------
         1 ORA$BASE                    133
         2 DUAL                        142
         3 DUAL                        143
         4 MAP_OBJECT                  356

4 rows selected.

Chris Saxon
October 08, 2019 - 3:51 pm UTC

Row archival is about managing individual rows within a table.

It sounds to me like the OP wants to archive all the rows in the table. So In-Database Archiving doesn't really apply here.

Intuitive Solution

Phil Goldenberg, October 08, 2019 - 6:11 pm UTC

An OLD_STUFF schema seems like a very straight-forward & simple solution, especially since it's unlikely any of the tables we'll move there will be very large. Thank you!
Connor McDonald
October 21, 2019 - 12:14 pm UTC

Glad we could help

More to Explore

Administration

Need more information on Administration? Check out the Administrators guide for the Oracle Database