Oracle Export-Import with QUERY parameter on LINUX box

There's this one time when I like to purge a certain table but it is very large. It creates a lot of archive logs when I am performing delete statements using a where clause as a delimiter for the rows I'd like to delete. It is very time consuming and it eats space on the disk. And one more thing is that, there are more rows that I need to delete that the rows I need to keep.

So I just tried to purge this very large table using Oracle' EXP and IMP utility. My plan is to export the rows that I want to keep and truncate the table I am purging. Afterwards, I will IMP the dumpfile into that same table.

Here's what I did:

Environment:
OS: RHELinux 5.4 32bit
DB: Oracle 10.2.0.4

SQL Query:
SQL> select * from sh.sales
     where time_id = to_date('28-DEC-01:00:00:00',
     'DD-MON-RR:HH24:MI:SS');

The output of this query are the rows that I want to keep.

My gameplan is:
1. Perform EXP using QUERY parameter.
2. Truncate the table I am purging
3. Perform IMP
4. Gather table statistics

Here is my export parameter file:

[oracle@shaoran selective_export]$ cat exp_mysale.par
userid="sys/oracle as sysdba"
buffer=10000000
file=mysales148.dmp
query="where time_id=to_date('28-DEC-01:00:00:00','DD-MON-RR:HH24:MI:SS')"
log=mysales148.log
TABLES=sh.mysales
recordlength=65535
statistics=none

My actual export goes:

[oracle@shaoran selective_export]$ export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
[oracle@shaoran selective_export]$ exp parfile=exp_mysale.par

Export: Release 10.2.0.1.0 - Production on Fri Feb 4 12:13:28 2011

Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Export done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character set

About to export specified tables via Conventional Path ...
Current user changed to SH
. . exporting table MYSALES 4784 rows exported
Export terminated successfully without warnings.


My export parfile is:

[oracle@shaoran selective_export]$ cat import_mysales.par
userid="sys/oracle as sysdba"
buffer=10000000
file=mysales148.dmp
log=imp_mysales148.log
IGNORE=y
FEEDBACK=10000
STATISTICS=none
RESUMABLE=y
RESUMABLE_TIMEOUT=600
FROMUSER=sh
TOUSER=sh
TABLES=mysales


And my import goes:


[oracle@shaoran selective_export]$ export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
[oracle@shaoran selective_export]$ imp parfile=import_mysales.par

Import: Release 10.2.0.1.0 - Production on Fri Feb 4 12:28:18 2011

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

Export file created by EXPORT:V10.02.01 via conventional path
import done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character set
. importing SH's objects into SH
. . importing table                      "MYSALES"
                                                         4784 rows imported
Import terminated successfully without warnings.


Post tasks includes gathering table statistics:


SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS (ownname => 'SH', 
tabname=>'MYSALES',estimate_percent=> dbms_stats.auto_sample_size, cascade => true);


Gilbert S Dela Cruz
Oracle Database Administrator
Oracle Database 11g Certified Associate
Registered Electronics Engineer
Member IECEP Philippines Inc.

Comments

Popular posts from this blog

RMAN Restoration to New Server with Different Directory and New Database Name

[Script] Tablespace Usage Alert

[Script] ASM Diskgroup Space Usage Alert