You are on page 1of 6

Data Pump import/export for WATS project

Assumption: ‘shell’ database is created and ready for data import. This target database is referred to as
WATS database in the document. Current/source database is referred as current database.

1. Export the source database (set proper directory)

expdp system directory=DATA_PUMP_DIR full=y dumpfile=<dbname>_current.dmp


logfile= dbname _current.log

2. Copy dump file and log file to destination server (WATS server). From the WATS server, navigate
to the right directory (import directory) and run:

scp <user_id>@<wats_hostname>:<path>/<dbname>_current.dmp .
scp <user_id>@<wats_hostname>:<path>/<dbname>_current.log .

Example:

scp nlomigor@wdst4110.win.wellsfargo.com:/dbatemp/EXP/w053d/w053d_old.dmp .
scp nlomigor@wdst4110.win.wellsfargo.com:/dbatemp/EXP/w053d/w053d_old.log .

Note: Please copy <dbname>_current.log file, it is needed for primary dba to


validate the import.

3. WATS database: password reset for user dbsnmp and system. Grants for dbsnmp (needed for
OEM prior to actual import). After running below script, make sure you can connect see the
database in Grid OEM.

alter user system identified by xxxx account unlock;

alter user dbsnmp identified by xxxx account unlock;

Note: please update ‘junk’ file with updated system and dbsnmp credentials.

GRANT OEM_MONITOR TO DBSNMP;


GRANT CONNECT TO DBSNMP;
ALTER USER DBSNMP DEFAULT ROLE ALL;
-- 8 System Privileges for DBSNMP
GRANT CREATE TYPE TO DBSNMP;
GRANT CREATE TABLE TO DBSNMP;
GRANT RESTRICTED SESSION TO DBSNMP;
GRANT SELECT ANY DICTIONARY TO DBSNMP;
GRANT CREATE PUBLIC SYNONYM TO DBSNMP;
GRANT CREATE PROCEDURE TO DBSNMP;
GRANT CREATE SEQUENCE TO DBSNMP;
GRANT UNLIMITED TABLESPACE TO DBSNMP;
-- 8 Object Privileges for DBSNMP
GRANT EXECUTE ON SYS.DBMS_JOB TO DBSNMP;
GRANT EXECUTE ON SYS.DBMS_LOB TO DBSNMP;
GRANT EXECUTE ON SYS.DBMS_SERVER_ALERT TO DBSNMP;
GRANT EXECUTE ON SYS.DBMS_SYS_SQL TO DBSNMP;
GRANT EXECUTE ON SYS.UTL_FILE TO DBSNMP;
GRANT EXECUTE ON SYS.UTL_HTTP TO DBSNMP;
GRANT EXECUTE ON SYS.UTL_SMTP TO DBSNMP;
GRANT EXECUTE ON SYS.UTL_TCP TO DBSNMP;

4. Current database:
a. Generate tablespace script
b. Replace create path for datafiles with '+DATA01' or '+DATA02'. You can also combine
datafiles to reduce complexity.
c. Run the modified create tablespace script on WATS database
d. Run AUDIT_DATA and AUDIT_INDEX01 create tablespace and move AUD$. Adjust
‘+DATA’ location depending where you store other database files.

CREATE SMALLFILE TABLESPACE "AUDIT_DATA" DATAFILE '+DATA<XX>' SIZE 256M


REUSE AUTOEXTEND ON NEXT 128M MAXSIZE 32767M LOGGING EXTENT MANAGEMENT
LOCAL SEGMENT SPACE MANAGEMENT AUTO;

CREATE SMALLFILE TABLESPACE "AUDIT_INDEX01" DATAFILE ''+DATA<XX>' SIZE


128M REUSE AUTOEXTEND ON NEXT 128M MAXSIZE 32767M LOGGING EXTENT
MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;

begin
DBMS_AUDIT_MGMT.set_audit_trail_location(
    audit_trail_type           => DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,
    audit_trail_location_value => 'AUDIT_DATA');
END;

Begin
DBMS_AUDIT_MGMT.set_audit_trail_location(
    audit_trail_type           => DBMS_AUDIT_MGMT.AUDIT_TRAIL_FGA_STD,
    audit_trail_location_value => 'AUDIT_DATA');
END;

################### Generate Tablespaces Script #######################

spool gents.lst

set serveroutput on size 1000000

DECLARE

CURSOR get_ts IS SELECT * FROM dba_tablespaces


WHERE tablespace_name != 'SYSTEM';
CURSOR get_df (p_ts VARCHAR2) IS
SELECT * from dba_data_files
WHERE tablespace_name = p_ts;

l_str VARCHAR2(10);

BEGIN

FOR ts_rec IN get_ts LOOP


dbms_output.put_line ('CREATE TABLESPACE '||ts_rec.tablespace_name);
-- For each tablespace loop through the datafiles
FOR df_rec IN get_df (ts_rec.tablespace_name) LOOP
IF get_df%ROWCOUNT = 1 THEN
l_str := 'DATAFILE';
ELSE
l_str := ',';
END IF;

dbms_output.put_line (l_str||' '


||chr(39)||df_rec.file_name||chr(39)
||' SIZE '||df_rec.bytes||' REUSE ');

if df_rec.autoextensible = 'YES' then

dbms_output.put_line (' AUTOEXTEND ON'


||' NEXT '||df_rec.increment_by );

if df_rec.maxbytes = 68719443968 then


dbms_output.put_line (' MAXSIZE UNLIMITED');
else
dbms_output.put_line (' MAXSIZE '||df_rec.maxbytes);
end if;
end if;

END LOOP;

/* Extent Management Clause */

dbms_output.put_line ('EXTENT MANAGEMENT ' ||ts_rec.extent_management );


if ts_rec.extent_management = 'LOCAL' then
if ts_rec.allocation_type = 'SYSTEM' then
dbms_output.put_line (' AUTOALLOCATE ');
else

dbms_output.put_line (' UNIFORM SIZE '||ts_rec.initial_extent);


end if;
end if;

if ts_rec.extent_management = 'DICTIONARY' then

dbms_output.put_line ('DEFAULT STORAGE (INITIAL '||ts_rec.initial_extent


||' NEXT '||ts_rec.next_extent
||' MINEXTENTS '||ts_rec.min_extents
||' MAXEXTENTS '||ts_rec.max_extents
||' PCTINCREASE '||ts_rec.pct_increase||' ) ');

end if;

dbms_output.put_line (' ONLINE;');


dbms_output.new_line;

END LOOP;
END;
/

spool off
##############################################################################

5. Take the backup of WATS database (optional but strongly recommended, if import goes bad this
will allow quick recovery).

Example (please update path and file names prior to running it)

shutdown immediate
startup mount

vi bkp.sh –- copy below


chmod 755 bck.sh
./bck.sh

$ORACLE_HOME/bin/rman >>rmanbkp.log << EOF


connect target /
run
{
CONFIGURE BACKUP OPTIMIZATION OFF;
CONFIGURE COMPRESSION ALGORITHM 'LOW';
allocate channel c1 DEVICE type disk;
change archivelog all crosscheck;
BACKUP as compressed backupset FORMAT '/dbaworkspace/w053d/rman/w053d_bkup_%U'
DATABASE;
BACKUP CURRENT CONTROLFILE FORMAT '/dbaworkspace/w053d/rman/w053d_bkup_ctl_%U';
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE COMPRESSION ALGORITHM CLEAR;
}
exit
EOF

If you need to recover (import goes bad):

############## RECOVER (example) ################

create pfile='/tmp/init<dbname>.ora' from memory;

shutdown immediate
startup mount
alter system enable restricted session;
drop database;

startup nomount

rman target /

restore controlfile to '/tmp/ctl.ctl' from


'/dbaworkspace/w053d/rman/w053d_bkup_ctl_0oo1711t_1_1';

update init.ora with sinlge ctl file

move pfile create earlier,

cd $ORACLE_HOME/dbs
startup mount pfile=initw053d.ora

$ORACLE_HOME/bin/rman >>rman_restore.log << EOF


connect target /
run
{
allocate channel c1 DEVICE type disk;
allocate channel c2 DEVICE type disk;
restore DATABASE;
recover database;
alter database open resetlogs;
}
exit
EOF

-- fix control file location after import is successful.

############## END ################

6. Import data to WATS server:

a. Make sure you have grants in place, check DATA_PUMP_DIR or create


DATA_DIR if you need more/different space, example:

grant import full database to system;

cd /dbaworkspace/w053d

CREATE OR REPLACE DIRECTORY data_dir AS '/dbaworkspace/w053d/';


GRANT READ, WRITE ON DIRECTORY data_dir TO system;

b. Create parameter file


import.par file contains :

full=y
directory=DATA_DIR
dumpfile=<dbname>_current.dmp
logfile=<dbname>_wats_import.log
job_name=053d_wats_import
parallel=4
EXCLUDE=TABLESPACE
EXCLUDE=DIRECTORY
EXCLUDE=SCHEMA:"='TSMSYS'"
EXCLUDE=SCHEMA:"='SYS'"
EXCLUDE=SCHEMA:"='SYSTEM'"
EXCLUDE=SCHEMA:"='WMSYS'"
EXCLUDE=SCHEMA:"='DBSNMP'"
EXCLUDE=SCHEMA:"='OUTLN'"
EXCLUDE=SCHEMA:"='SYSMAN'"
EXCLUDE=SCHEMA:"='ANONYMOUS'"
EXCLUDE=SCHEMA:"='CTXSYS'"
EXCLUDE=SCHEMA:"='DIP'"
EXCLUDE=SCHEMA:"='ORAMAN'"
EXCLUDE=SCHEMA:"='XDB'"
EXCLUDE=SCHEMA:"='ORACLE_OCM'"
EXCLUDE=SCHEMA:"='APPQOSSYS'"

Note: These are standard oracle users, we do want to exclude these to avoid
overwriting objects and creating errors in the import log file. Depending on database
components installed, DBA can exclude more users (query dba_users on shell/WATS
database).

c. Import data:
impdp parfile=import.par

d. Review the log file, send an email to Project Manager and primary DBA for validation.

You might also like