Showing posts with label imp. Show all posts
Showing posts with label imp. Show all posts

Friday, May 7, 2010

Effects of compress option on exp and imp

This is the official description of the compress option from Oracle docs

The default, COMPRESS=y, causes Export to flag table data for consolidation into
one initial extent upon import
If you specify COMPRESS=n, Export uses the current storage parameters, including
the values of initial extent size and next extent size.

What is basically says is that if you set compress=y when imported the table size will be same as the exported size. If you set compress=n then things are different as you can see from below.

create table test1 (a char(2000));

begin
for i in 1 .. 20000
loop
insert into test1 values('a'||i);
end loop;
end;
/

SQL> select segment_name,bytes from user_segments where segment_name='TEST1';

SEGMENT_NA BYTES
---------- ----------
TEST1 55574528

SQL> delete from test1;

20000 rows deleted.

SQL> select segment_name,bytes from user_segments where segment_name='TEST1';

SEGMENT_NA BYTES
---------- ----------
TEST1 55574528


Now take two exports one with compress=y and one with compress=n


exp asanga/*** file=test.dmp tables=test1 compress=y
exp asanga/*** file=test_n.dmp tables=test1 compress=n

SQL>drop table test1 purge;

Table dropped.

imp asanga/*** file=test.dmp full=y
Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and AL16UTF16 NCHAR character set
. importing ASANGA's objects into ASANGA
. importing ASANGA's objects into ASANGA
. . importing table "TEST1" 0 rows imported
Import terminated successfully without warnings.

SQL>select segment_name,bytes from user_segments where segment_name='TEST1';

SEGMENT_NA BYTES
---------- ----------
TEST1 55574528

SQL>drop table test1 purge;

Table dropped.

imp asanga/asa file=test_n.dmp full=y

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

SQL>select segment_name,bytes from user_segments where segment_name='TEST1';

SEGMENT_NA BYTES
---------- ----------
TEST1 65536


As it could seen from above even if an empty table is imported with the default options, the size of the table doesn't shrink. If compress=n is used the imported table is redcued in size (or number of segments it uses).

Monday, February 25, 2008

expdp / impdp

create directory mydir as '/home/oracle/dpdump';
grant read,write on directory mydir to asanga;


expdp asanga/asa dumpfile=mydir:test.dmp schemas=asanga flashback_scn=14073963 logfile=mydir:expdp.log


expdp asanga/asa directory=mydir dumpfile=test.dmp schemas=asanga flashback_scn=14073963 logfile=expdp.log


impdp asanga/asa dumpfile=mydir:test.dmp logfile=mydir:impdp.log full=y
impdp asanga/asa directory=mydir dumpfile=test.dmp logfile=impdp.log full=y

to remap to different schema and generate new OID for type objects.
impdp directory=mydir dumpfile=remap.dmp logfile=rmap.log full=y remap_schema=sbx:sbxway transform=oid:n:type


FLASHBACK_TIME


This Export parameter specifies a timestamp of the form "YYYY-MM-DD HH24:MI:SS". Export finds the SCN that most closely matches the specified timestamp.

flashback_time='"2008-02-25 15:30:00"'

to get the date from the system on linux
flashback_time=\"$(date +%F' '%T)\"

Default value: none


Can specify the FLASHBACK_TIME parameter on the command line.


flashback_time=\"TO_TIMESTAMP\(\'19-06-2004 13:24:26\', \'DD-MM-YYYY HH24:MI:SS\'\)\"

You can also specifiy the FLASHBACK_TIME parameter in a parameter file.
When using the TO_TIMESTAMP function in a parameter file in Oracle10g,
use double quotes.
E.g.:
FLASHBACK_TIME="TO_TIMESTAMP('19-06-2004 13:24:26', 'DD-MM-YYYY HH24:MI:SS')"

Exclude Objects

expdp hr/hr EXCLUDE=INDEX:\"LIKE \'EMP%\'\" DUMPFILE=dpump_dir1:exp.dmp

Importing only a subset of rows
Using the query option it is possible to specify a select statment to a table or all the tables in schema. If the table is not specified then by default it will be applied to all the tables in schema.
create table x (a number);

Table created.

SQL> begin
  2  for i in 1 .. 100
  3  loop
  4  insert into x values(i);
  5  end loop;
  6  end;
  7  /

PL/SQL procedure successfully completed.

SQL> commit;

SQL>  create table y as select * from x;

Table created.

SQL> delete from y where mod(a,3)=0;

33 rows deleted.

SQL> commit;
Two tables X and Y has 100 and 67 rows now. Export the two tables
Starting "ASANGA"."SYS_EXPORT_SCHEMA_01":  asanga/******** directory=dumpdir dumpfile=test.dmp logfile=test.log schemas=asanga
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 128 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
. . exported "ASANGA"."X"                                5.585 KB     100 rows
. . exported "ASANGA"."Y"                                5.359 KB      67 rows
Master table "ASANGA"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Drop the tables from schema before import
SQL> drop table x;

Table dropped.

SQL> drop table y;

Table dropped.
Import only the rows where value of column A is between 10 and 20 on table X and only rows where value is even.
impdp asanga/asa directory=dumpdir dumpfile=test.dmp logfile=imp.log query=X:'"where a between 10 and 20"',
Y:'"where mod(a,2)=0"'
...
...
Master table "ASANGA"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "ASANGA"."SYS_IMPORT_FULL_01":  asanga/******** directory=dumpdir dumpfile=test.dmp logfile=imp.log query=X:"where a between 10 and 20",
Y:"where mod(a,2)=0"
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"ASANGA" already exists
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "ASANGA"."X"                                5.585 KB      11 out of 100 rows
. . imported "ASANGA"."Y"                                5.359 KB      34 out of 67 rows
Job "ASANGA"."SYS_IMPORT_FULL_01" completed with 1 error(s) at 13:33:47