Pages

Tuesday, 28 May 2013

DBA REGULAR SCRIPTS

Queries : Memory, Free Space, Size, Temp Files, Control Files etc..

1)Database block size:

select to_number(value) "Block size in bytes"
from   sys.v_$parameter
where  name = 'db_block_size';


2)Max number of possible extents:

select to_number(value)/16-7 "MaxExtents"
from   sys.v_$parameter
where  name = 'db_block_size';



3)Min extent size:

select to_number(a.value) * to_number(b.value) / 1024 "Min extent size in K"
from   sys.v_$parameter a, sys.v_$parameter b
where  a.name = 'db_block_size'
and  b.name = 'db_file_multiblock_read_count';

4)List objects in the SYSTEM tablespace that doesn't belong to SYS or SYSTEM

select * from sys.dba_segments
where owner not in ('PUBLIC', 'SYS', 'SYSTEM')
and tablespace_name = 'SYSTEM';


5)Reports information about your current database context

select 'User: '|| user || ' on database ' || global_name,
       '  (term='||USERENV('TERMINAL')||
       ', audsid='||USERENV('SESSIONID')||')' as MYCONTEXT
from   global_name;

6)Reports free memory available in the SGA

select name,
       sgasize/1024/1024 "Allocated (M)",
       bytes/1024 "Free (K)",
       round(bytes/sgasize*100, 2) "% Free"
from   (select sum(bytes) sgasize from sys.v_$sgastat) s,

sys.v_$sgastat f
where  f.name = 'free memory';

7)Measure the Buffer Cache Hit Ratio
Get initial Buffer Hit Ratio reading

SELECT ROUND((1-(phy.value / (cur.value + con.value)))*100,2) "Cache Hit Ratio"
FROM v$sysstat cur, v$sysstat con, v$sysstat phy
WHERE cur.name = 'db block gets'
AND con.name = 'consistent gets' AND phy.name = 'physical reads';


8)Database users with deadly roles assigned to them.

select grantee, granted_role, admin_option
from   sys.dba_role_privs
where  granted_role in ('DBA', 'AQ_ADMINISTRATOR_ROLE',
                       'EXP_FULL_DATABASE', 'IMP_FULL_DATABASE',
                       'OEM_MONITOR')
  and  grantee not in ('SYS', 'SYSTEM', 'OUTLN',

'AQ_ADMINISTRATOR_ROLE',
                       'DBA', 'EXP_FULL_DATABASE',

'IMP_FULL_DATABASE',
                       'OEM_MONITOR',

'CTXSYS', 'DBSNMP', 'IFSSYS',
                       'IFSSYS$CM', 'MDSYS', 'ORDPLUGINS',

'ORDSYS',
                       'TIMESERIES_DBA');


9)Database users with deadly system privilages assigned to them.

select grantee, privilege, admin_option
from   sys.dba_sys_privs
where  (privilege like '% ANY %'
  or   privilege in ('BECOME USER', 'UNLIMITED TABLESPACE')
  or   admin_option = 'YES')
 and   grantee not in ('SYS', 'SYSTEM', 'OUTLN',

'AQ_ADMINISTRATOR_ROLE',
'DBA', 'EXP_FULL_DATABASE',

'IMP_FULL_DATABASE',
'OEM_MONITOR', 'CTXSYS',

'DBSNMP', 'IFSSYS',
'IFSSYS$CM', 'MDSYS',

'ORDPLUGINS', 'ORDSYS',
'TIMESERIES_DBA');


10)Allocated, Used & Free space within datafiles

SELECT   SUBSTR (df.NAME, 1, 40) file_name,

df.bytes / 1024 / 1024 allocated_mb,
((df.bytes / 1024 / 1024) - NVL (SUM (dfs.bytes) / 1024 / 1024, 0)) used_mb,
NVL (SUM (dfs.bytes) / 1024 / 1024, 0) free_space_mb
FROM v$datafile df, dba_free_space dfs
WHERE df.file# = dfs.file_id(+)
GROUP BY dfs.file_id, df.NAME, df.file#, df.bytes
ORDER BY file_name;

11)Show Used/free space by tablespace name

SELECT Total.name "Tablespace Name",
       nvl(Free_space, 0) Free_space,
       nvl(total_space-Free_space, 0) Used_space,
       total_space
FROM
  (select tablespace_name, sum(bytes/1024/1024) Free_Space
     from sys.dba_free_space
    group by tablespace_name
  ) Free,
  (select b.name,  sum(bytes/1024/1024) TOTAL_SPACE
     from sys.v_$datafile a, sys.v_$tablespace B
    where a.ts# = b.ts#
    group by b.name
  ) Total
WHERE Free.Tablespace_name(+) = Total.name
ORDER BY Total.name;


12)INvestigating undo-tablespace in EBS
SELECT version FROM v$timezone_file;

select count(status) from dba_undo_extents where status = 'ACTIVE';

select count(status) from dba_undo_extents where status = 'UNEXPIRED';

select (sum(bytes)/(1024*1024)) "SIZE in MB",tablespace_name from dba_free_space group by tablespace_name;

13)Find type of objects available in a tablespace
select ds.segment_name,do.object_type,do.status,ds.tablespace_name from dba_segments ds,dba_objects do where ds.tablespace_name='TOOLS'
Temp tablespace usage information
SELECT A.tablespace_name tablespace, D.mb_total,
SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_used,
D.mb_total - SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_free
FROM v$sort_segment A,
(
SELECT B.name, C.block_size, SUM (C.bytes) / 1024 / 1024 mb_total
FROM v$tablespace B, v$tempfile C
WHERE B.ts#= C.ts#
GROUP BY B.name, C.block_size
) D
WHERE A.tablespace_name = D.name
GROUP by A.tablespace_name, D.mb_total;

14)To count no. of segments in each t.s.
select tablespace_name,count(*) from dba_segments group by tablespace_name;

15)Database growth per month for last year

select to_char(creation_time, 'RRRR Month') "Month",
       sum(bytes)/1024/1024 "Growth in Meg"
  from sys.v_$datafile
 where creation_time > SYSDATE-365
 group by to_char(creation_time, 'RRRR Month');


16)Query to find the ATG rollup Patch level in your application (11i).

connect as apps:

SELECT (bug_number),
decode((bug_number),
'3438354','ATG_PF.H',
'4017300','ATG_PF.H RUP 1',
'4125550','ATG_PF.H RUP 2',
'4334965','ATG_PF.H RUP 3',
'4676589','ATG_PF.H RUP 4',
'5473858','ATG_PF.H RUP 5',
'5903765','ATG_PF.H RUP 6',
'6241631','ATG_PF.H RUP 7')
FROM ad_bugs
WHERE bug_number IN
('3384350',
'3438354',
'4017300',
'4125550',
'4334965',
'4676589',
'5473858',
'5903765',
'6241631')
order by bug_number desc; 



17)To find RUP Level in R12 : -


select bug_number, creation_date
from ad_bugs
where bug_number in ('6022657','6266113','6728000')
ORDER BY 2;


18)To Check Maintenance Family Pack Level

select patch_level from fnd_product_installations
where application_id = 275;


19)Query to find the Apps Version : -

select release_name from fnd_product_groups;


20)Which FND_USER is locking that table
The column named "module" will tell you the name of the Form Function
or the Concurrent Program Short name which has aquired a lock onto that table.

SELECT c.owner ,c.object_name,c.object_type,
       fu.user_name locking_fnd_user_name
      ,fl.start_time locking_fnd_user_login_time,
      vs.module,vs.machine ,vs.osuser
      ,vlocked.oracle_username,vs.sid,vp.pid
      ,vp.spid AS os_process,vs.serial# ,vs.status ,vs.saddr
      ,vs.audsid ,vs.process

FROM fnd_logins fl ,fnd_user fu ,v$locked_object vlocked
    ,v$process vp ,v$session vs,dba_objects c

WHERE vs.sid = vlocked.session_id
AND vlocked.object_id = c.object_id
AND vs.paddr = vp.addr
AND vp.spid = fl.process_spid(+)
AND vp.pid = fl.pid(+)
AND fl.user_id = fu.user_id(+)
AND c.object_name LIKE '%' || upper('&tab_name_leaveblank4all') || '%'
AND nvl(vs.status ,'XX') != 'KILLED';


21)Security related database initialization parameters and password file users.

select name || '=' || value "PARAMTER"
from   sys.v_$parameter
where  name in ('remote_login_passwordfile', 'remote_os_authent',
                'os_authent_prefix', 'dblink_encrypt_login',
                'audit_trail', 'transaction_auditing');

22)List security related profile information

select profile, resource_name, limit
from   dba_profiles
where  resource_name like '%PASSWORD%'
   or  resource_name like '%LOGIN%';


23)To find space used by a database user
Query to find space used by a database user. Following query can be used to know the space used by the logged in user in MBs:

SELECT sum(bytes)/1024/1024 user_size FROM user_segments;

24)Query to find the space occupied by all the users in a database.
This requires access to dba_segments table:

SELECT owner, sum(bytes)/1024/1024 total_size FROM dba_segments
GROUP BY owner ORDER BY total_size DESC;

25)Total space occupied by all users:

SELECT sum(bytes)/1024/1024 total_size FROM dba_segments;

26)To find Database Size
The database mainly comprises of datafiles, temp files and redo log files.
The biggest portion of a database’s size comes from the datafiles.

27)To find out how many megabytes are allocated to all datafiles:
SELECT sum(bytes)/1024/1024 data_size FROM dba_data_files;

28)To get the size of all TEMP files:
SELECT nvl(sum(bytes),0)/1024/1024 temp_size FROM dba_temp_files;

29)To get the size of the on-line redo-logs:
SELECT sum(bytes)/1024/1024 redo_size FROM sys.v_$log;

Finally, summing up the three above, total database size can be found:
SELECT (dsize.data_size + tsize.temp_size + rsize.redo_size)/1024/1024 "total_size"
FROM (SELECT sum(bytes) data_size
FROM dba_data_files ) dsize,
(SELECT nvl(sum(bytes),0) temp_size
FROM dba_temp_files ) tsize,
(SELECT sum(bytes) redo_size
FROM sys.v_$log ) rsize;


30)To find free space in temporary tablesapce:
SELECT tablespace_name,SUM(bytes_used),SUM(bytes_free) FROM V$temp_space_header GROUP BY tablespace_name;

31)To find tablespace free space in a database
SELECT a.tablespace_name, a.file_name, a.bytes allocated_bytes,
b.free_bytes
FROM dba_data_files a,
(SELECT file_id, SUM(bytes) free_bytes
FROM dba_free_space b GROUP BY file_id) b
WHERE a.file_id=b.file_id
and a.tablespace_name='SYSTEM'
ORDER BY a.tablespace_name;

32)To find Table size in a database :

select sum(BYTES/1024/1024) as TOTAL_GIG from user_segments where
SEGMENT_NAME = 'TABLE_NAME';

Note: Need to execute as owner of the table. (OR)
select sum(BYTES/1024/1024) as TOTAL_GIG from dba_segments where SEGMENT_NAME='FND_TS_MIG_CMDS';


33)=== Temp Usage ===

select sum(blocks)/1024*8 "Size in MB" FROM v$sort_usage;

SELECT ss.sid, sum(st.blocks)/1024*8
FROM v$sort_usage st, v$session ss
where ss.saddr=st.session_addr
group by ss.sid
having sum(st.blocks)/1024*8 > 100 order by 2;


SELECT  /*+ RULE */ s.username, s.osuser, s.sid,
NVL(s.machine,'N/A'),
NVL(s.module,'N/A'), NVL(s.action,'N/A'),
NVL(s.program,'N/A'),
s.status ||' for '||LPAD(((last_call_et/60)-mod((last_call_et/60),60))/60,2,'0') ||':'||LPAD(ROUND(mod((last_call_et/60),60)),2,'0') ||' Hr',
u.tablespace, u.contents, u.extents,
round((u.blocks*8)/1024),s.sql_address, s.sql_hash_value
FROM    v$session s, v$sort_usage u
WHERE   s.saddr    = u.session_addr
AND     u.contents = 'TEMPORARY'
AND     s.audsid != USERENV('sessionid')
AND    (u.blocks*8)/1024 >= 1000

ORDER   BY 1,2,3,4,5 Desc;


34)=== High Redo ===

SELECT s.inst_id,s.sid, s.serial#, s.username,
s.program, i.block_changes
FROM gv$session s, gv$sess_io i
WHERE s.sid = i.sid
AND i.block_changes > 10000000
ORDER BY 6 desc, 1, 2, 3, 4;


35)=== Rollback Used ===
                                 
SELECT rn.name, ROUND(rs.rssize/1024/1024),
s.username, s.osuser, s.sid, NVL(s.machine,'N/A'),
NVL(s.module,'N/A'), NVL(s.action,'N/A'),
NVL(s.program,'N/A'),
s.sql_address, s.sql_hash_value, p.spid,
s.status ||' for '||LPAD(((last_call_et/60)-mod((last_call_et/60),60))/60,2,'0') ||':'||LPAD(ROUND(mod((last_call_et/60),60)),2,'0') ||' Hr' ,
round(ceil((t.used_ublk*8)/1024),1)
FROM   v$rollname rn, v$rollstat rs,
v$session s, v$transaction t, v$process p
WHERE  rn.usn = rs.usn
AND    round((t.used_ublk*8)/1024) >= 1000
AND    rs.usn = t.xidusn
AND    s.sid = p.pid (+)
AND    s.taddr = t.addr
ORDER  BY 2 desc, s.sid ,s.status;


36)=== Roll back segement Information ====

select tablespace_name, status segment_status,
count(extent_id) "Extent Count", sum(blocks) "Total Blocks",
sum(blocks)*8/(1024*1024) "Total Space in GB"
from dba_undo_extents
where tablespace_name like '%UNDO%'
group by tablespace_name, status;


37)=== Shared Pool Usage ===

SELECT INST_ID,ROUND(bytes/1024/1024, 2)||' MB'
FROM gv$sgastat 
WHERE name='free memory' AND pool='shared pool';


38)=== Archive Generation for last 5 hours ===

SELECT TO_CHAR(first_time, 'DD-MM-YY') AS Day,
TO_CHAR(first_time, 'HH24') AS Hour,COUNT(*) 
FROM v$log_history
WHERE TO_CHAR(first_time, 'DD-MM-YY') = TO_CHAR(sysdate, 'DD-MM-YY')
AND  TO_CHAR(first_time, 'HH24') >= TO_CHAR(sysdate, 'HH24') - 5
GROUP BY  TO_CHAR(first_time, 'DD-MM-YY'),
TO_CHAR(first_time, 'HH24') ORDER BY 2;


39)=== High Memory ===

select s.inst_id, s.sid, name,
round(value/1024/1024) Mem_in_mb, p.*
from gv$sesstat s, v$statname n, gv$session p
where n.statistic# = s.statistic#
and s.inst_id = p.inst_id
and s.sid = p.sid
and name like '%pga memory%'
and value > 1*1024*1024*512;


40)=== Performance ===

select sql_hash_value, count(*)
from v$session
where event like 'enq%'
group by sql_hash_value;


select sql_hash_value,username,osuser, count(*)
from v$session
where event like 'enq%'
and SQL_HASH_VALUE='&event'
group by sql_hash_value,username,osuser;


select sql_text
from v$sqlarea
where hash_value = '&hash_value';


select s1.sid,FETCHES,ROWS_PROCESSED
from v$sql s,v$session s1
where s.HASH_VALUE=s1.SQL_HASH_VALUE
and s1.sid=4885;


select s.sid,s.serial#,s.status,s.username,s.module,
s.osuser,x.event
from v$session s,v$session_wait x
where s.paddr in ( select addr
from v$process
where spid in (2340,23869,13827,18261,14880,2381))
and x.sid=s.sid;


select s.sid,s.serial#,s.status,s.username,
s.module,s.osuser,x.event
from v$session s,v$session_wait x
where x.sid=s.sid and x.event like '&event_name';

How to find the ORACLE_HOME path in Oracle Database?

In 9i:
SELECT substr(file_spec,1,instr(file_spec,'lib')-2) ORACLE_HOME FROM
dba_libraries
WHERE library_name='DBMS_SUMADV_LIB';
In 10g:
SQL > var OHM varchar2(100);
SQL > EXEC dbms_system.get_env('ORACLE_HOME', :OHM) ;
SQL > PRINT OHM
Linux/Unix:
echo $ORACLE_HOME

=== Other Script to update the daily report ===

select status,count(1) from gv$session group by status;

select count(1) from dba_tables where logging='NO';

select distinct status,count(1) from dba_indexes group by status;

select count(1) from dba_objects where status='INVALID';




select sum(bytes)/1024/1024 from dba_data_files;

select sum(bytes)/1024/1024 from v$log;

select sum(bytes)/1024/1024/1024 from dba_data_files
+
select sum(bytes)/1024/1024/1024 from dba_temp_files
+
select sum(bytes)/1024/1024/1024 from v$log


select t.tablespace_name, round(a.bytes,2) tbsize, 
nvl(round(c.bytes,2),'0') tbfree, 
nvl(round(b.bytes,2),'0') tbused, 
to_char(round(100 * (nvl(b.bytes,0)/nvl(a.bytes,1)),2)) || '%' tbusedpct, 
to_char(round(100 * (nvl(c.bytes,0)/nvl(a.bytes,1)),2)) || '%' tbfreepct 
from dba_tablespaces t, 
(select tablespace_name, round(sum(bytes)/1024/1024,2) bytes 
from dba_data_files 
group by tablespace_name 
union 
select tablespace_name, round(sum(bytes)/1024/1024,2) bytes 
from dba_temp_files 
group by tablespace_name ) a, 
(select e.tablespace_name, round(sum(e.bytes)/1024/1024,2) bytes 
from dba_segments e 
group by e.tablespace_name 
union 
select tablespace_name, sum(max_size) bytes 
from v$sort_segment 
group by tablespace_name) b, 
(select f.tablespace_name, round(sum(f.bytes)/1024/1024,2) bytes 
from dba_free_space f 
group by f.tablespace_name 
union 
select tmp.tablespace_name,  (sum(bytes/1024/1024) - sum(max_size)) bytes 
from dba_temp_files tmp, v$sort_segment sort 
where tmp.tablespace_name = sort.tablespace_name 
group by tmp.tablespace_name) c 
where 
t.tablespace_name = a.tablespace_name (+) 
and t.tablespace_name = b.tablespace_name (+) 
and t.tablespace_name = c.tablespace_name (+) 
order by t.tablespace_name 
/

Sunday, 26 May 2013

11g Data Pump – Data Obfuscation

11g Data Pump – Data Obfuscation
lData Obfuscation
lDuring export or import operation
lModify data via PL/SQL routine
lRemap_data parameter
lLists schema.table_name.column_name:
package_name for remap operation
lSeparate remap_data parameter for each
table/column pair.
11g Data Pump – Data Obfuscation
lExample PL/SQL Code.
Create or replace package my_package
as
function my_function (p_in_data varchar2)
return varchar2;
end;
/
Create or replace package body my_package
as
function my_function (p_in_data varchar2)
return varchar2
As
v_return varchar2(30);
begin
v_return:=translate(p_in_data, 'abcdefghijklmnopqrstuvwxyz',
'bcdefghijklmnopqrstuvwxyza');
return v_return;
end;
end;
/

Remap during import (with 2 columns)
impdp Robert/robert DIRECTORY=data_pump_dir
DUMPFILE=remap.dmp tables=RAJ.NAMES
remap_data=RAJ.copy_names.user_name:
RAJ.my_package.my_function
remap_data=RAJ.copy_names.user_commment:
RAJ.my_package.my_function

DATA PUMP 11G

Datapump
• COMPRESSION
• ALL, DATA_ONLY, METADATA_ONLY, NONE
$ expdp / directory=tmp dumpfile=uncompressed.dmp compression=NONE schemas=ops\$tkyte
Export: Release 11.1.0.6.0 - Production on Friday, 21 September, 2007 12:23:26
. . exported "OPS$TKYTE"."BIG_TABLE" 24.57 MB 250000 rows
. . exported "OPS$TKYTE"."T" 6.791 MB 67945 rows
$ expdp / directory=tmp dumpfile=compressed.dmp compression=ALL schemas=ops\$tkyte
Export: Release 11.1.0.6.0 - Production on Friday, 21 September, 2007 12:23:58
. . exported "OPS$TKYTE"."BIG_TABLE" 3.110 MB 250000 rows
. . exported "OPS$TKYTE"."T" 762.1 KB 67945 rows
$ ls -l /tmp/*compressed.dmp
-rw-r----- 1 ora11gr1 ora11gr1 4124672 Sep 21 12:24 /tmp/compressed.dmp
-rw-r----- 1 ora11gr1 ora11gr1 33136640 Sep 21 12:23 /tmp/uncompressed.dmp

exp full back up script


oraprod4 oraprfdm /db/cpmfdmp/oracle/scripts/exp

cpmfdmp> cat cpmfdmp_dly_full_dp_exp
#!/bin/ksh
#NLS_LANG="AMERICAN_AMERICA.WE8ISO8859P1"
#export NLS_LANG
#. oraenv >/dev/null << eof
. /home/oraprfdm/cpmfdmp
#eof
echo ' '
echo "**** - CPMPFDMP EXPORT of $ORACLE_SID ****"
echo This will copy the cpmfdmp system to /db/cpmfdmp/export disk drive.
date
echo $ORACLE_SID
LOGOUT=/db/cpmfdmp/export/cpmfdmp_exp_dp_full.log; export LOGOUT
date
rm -f /db/cpmfdmp/export/cpmfdmp_dly_full_dp.dmp;
rm -f /db/cpmfdmp/export/cpmfdmp_exp_dp_full.log;
usersid=`cat /db/cpmfdmp/oracle/admin/cpmfdmp/create/system/pdssystem.sql`
expdp $usersid PARFILE=/db/cpmfdmp/oracle/scripts/exp/ctl/cpmfdmp_dly_full_dp.ctl
RETVAL=$?
if [ $RETVAL -ne 0 ]
     then
        echo ""
        echo "${PNAME}: Export error; Return code = <${RETVAL}>"
        echo ""
        exit 8
fi

check_success=`grep 'successfully completed' $LOGOUT|wc -l`
oracle_num=`expr $check_success`

DBA REGULAR SCRIPTS

scp -rp  stratadmin_pffin1_25April11.dmp oraffin1@fsdev.us.estee.com:/db/ffin1/backu
scp -rp ABP_WIP_PFIN3_22MAY2012.dmp oraqfin3@oradev3.us.estee.com:/db/qfin3/export

a) script for disable constraints:
set heading off
set linesize  100
spool drop_constraints.sql
select 'ALTER TABLE ' || OWNER || '.' || TABLE_NAME || ' DROP CONSTRAINT ' || constraint_name|| ';' from dba_constraints where owner in ('STRATADMIN') and constraint_type='R';
select 'ALTER TABLE ' || OWNER || '.' || TABLE_NAME || ' DROP CONSTRAINT ' || constraint_name|| ';' from dba_constraints where owner in ('ABP','ABP_WIP') and constraint_type='R';

b) script for drop objects:
spool drop_objects.sql
select 'DROP ' || OBJECT_TYPE || ' ' || OWNER || '.' || OBJECT_NAME || ';' from dba_objects where owner in ('STRATADMIN') and object_type!='INDEX' order by 1;
select 'DROP ' || OBJECT_TYPE || ' ' || OWNER || '.' || OBJECT_NAME || ';' from dba_objects where owner in ('ABP','ABP_WIP') and object_type!='INDEX' order by 1;

scp -rp smi_prodsupphase2group3db.dmp oraalmd1@infa5qb.am.elcompanies.net:/db/hpalmd1/export



1.        Restore the schema:
a.       default_smi_phase2_group3_db
                 DEFAULT_SMI_PHASE2_GROUP3_DB
                 DEFAULT_SMI_PHASE2_GROUP3_DB
2.       Source SID: INFA4PB
3.       Target SID: INFA5QB
scp -rp smi_prodsupphase2group3db.dmp  raalmd1@infa5qb.am.elcompanies.net:/db/hpalmd1/export

nohup impdp parfile=imp.par &
cat > imp.par
userid=system/d01infa5qb
dumpfile=smi_prodsupphase2group3db.dmp
logfile=default_smi_phase2_group3_db_imp.log
SCHEMAS=DEFAULT_SMI_PHASE2_GROUP3_DB
REMAP_SCHEMA=DEFAULT_SMI_PHASE2_GROUP3_DB:DEFAULT_SMI_PHASE2_GROUP3_DB
directory=DATA_PUMP_DIR
SQL> select object_type,count(*) from dba_objects where owner='DEFAULT_SMI_PHASE2_GROUP3_DB' group by object_type;
nohup exp system/p01rp1 file=ABP_WIP_PFIN3_22MAY2012.dmp log=ABP_WIP_PFIN3_22MAY2012_imp.log owner=ABP,ABP_WIP buffer=52428800 consistent=y  &
imp system/p396081 FILE=/db/ffin1/backup/startadmin_pfin1_25April.dmp FROMUSER=stratadmin TOUSER=stratadmin TABLES=TBLLFS rows=y ignore=y
nohup imp system/q03if1  file=ABP_WIP_PFIN3_22MAY2012.dmp log=ABP_WIP_PFIN3_22MAY2012_imp.log full=y buffer=10485760 commit=y ignore=y &
imp system/p01rp1  file=pfin3_abp_exp_17052012.dmp INDEXFILE=pfin3abp.sql rows=n FULL=y

Please copy all contents of the DRM schema in the CPMTEST database to the DRM-OLD schema in the CPMTEST database, replacing the current contents of the DRM-OLD schema
After that is completed, please copy all contents of the DRM schema in the CPMPROD database to the DRM schema in the CPMTEST database, replacing the current contents of the DRM schema
Task1
--------
1) Export of DRM Schema from CPMTEST
2) Import into DRMOLD schema in CPMTEST
Task2
----
1) Export of DRM Schema from CPMPROD
2) Import into DRM schema in  CPMTEST
>expdp system/Access09$  dumpfile=DRM_CPMTEST_DP.dmp logfile=DRM_CPMTEST_expdp.log directory=DATA_PUMP_DIR SCHEMAS=DRM
>impdp system/Access09$ DUMPFILE=DRM_CPMTEST_DP.dmp   LOGFILE=DRM_CPMTEST_DP_impdp.log DIRECTORY=DATA_PUMP_DIR REMAP_SCHEMA=DRM:DRMOLD REMAP_TABLESPACE=MDM_DATA:MDM_DATA TABLE_EXISTS_ACTION=REPLACE
>expdp system/access09 dumpfile=DRM_CPMPROD_DP.dmp logfile=DRM_CPMPROD_expdp.log directory=DATA_PUMP_DIR SCHEMAS=DRM
cpmprod> scp -rp DRM_CPMPROD_DP.dmp oracpmts@oradev1.am.elcompanies.net:/db/cpmtest/export/csc
impdp system/Access09$ DUMPFILE=DRM_CPMPROD_DP.dmp   LOGFILE=DRM_CPMPROD_DP.dmp_impdp.log DIRECTORY=DATA_PUMP_DIR
script for disable constraints:
===============================
set heading off
set linesize  100
spool drop_constraints.sql
select 'ALTER TABLE ' || OWNER || '.' || TABLE_NAME || ' DROP CONSTRAINT ' || constraint_name|| ';' from dba_constraints where owner in ('DRM') and constraint_type='R';
script for drop objects:
==========================
spool drop_objects.sql
select 'DROP ' || OBJECT_TYPE || ' ' || OWNER || '.' || OBJECT_NAME || ';' from dba_objects where owner in ('DRM') and object_type!='INDEX' order by 1;
SQL> select sum(bytes)/1024/1204/1024 GB from dba_segments where owner='FDR';
        GB
----------
40.5103821
SQL> select sum(bytes)/1024/1204/1024 GB from dba_segments where owner='FDRB';
        GB
----------
30.8884967
SQL> select object_type,count(*) from dba_objects where owner='DRM' group by object_type;
OBJECT_TYPE           COUNT(*)
------------------- ----------
INDEX                      238
PROCEDURE                   11
VIEW                         2
TABLE                      107
SEQUENCE                    24
LOB                          8
6 rows selected.


SQL> select OWNER, TABLE_NAME, TABLESPACE_NAME, LAST_ANALYZED from dba_tables where table_name='ODS_FLD_ORDER_DTL';
OWNER TABLE_NAME TABLESPACE_NAME LAST_ANAL
------------------------------ ------------------------------ ------------------------------ ---------
ODS ODS_FLD_ORDER_DTL ODS 10-FEB-11

Would you kindly migrate the following table data from Prod (oraprod4, cpmprod) to QA (oradev1, cpmqa)? Please note that, if required, the data from the QA tables should be truncated prior to running in the new data from Prod.

 Tables needing migration:

·         fdr.iz_bw_mcust_sales
·         fdr.iz_bw_mcustomer_member
·         fdr.iz_bw_ledger_data
·         fdr.iz_bw_copa_data
TABLES=(fdr.iz_bw_mcust_sales, fdr.iz_bw_mcustomer_member, fdr.iz_bw_ledger_data, fdr.iz_bw_copa_data)

cpmprod> scp -rp FDR_Tbls_cpmprod.dmp.Z racpmqa@oradev1.am.elcompanies.net:/db/cpmqa/export/

SQL> select count(*) from dba_tables where owner='FDR';
  COUNT(*)
----------
       225
SQL> truncate table FDR.iz_bw_sellthru_ziso002_data;
Table truncated.
SQL> truncate table FDR.iz_bw_sellthru_ziso010_data;
Table truncated...............

cpmqa> more FDR_Tbls_237_exp.ctl USERID=system/Access09$ FILE=/db/cpmqa/export/fdr_exp_pipe
GRANTS=Y INDEXES=Y BUFFER=65586748COMPRESS=N DIRECT=Y ROWS=Y CONSTRAINTS=Y
TABLES=(FDR.BW_237_ACCT_FA_SET_MAP,FDR.BW_237_ACCT_FA_SET_MAP_MINUS,...........................)
LOG=/db/cpmqa/export/FDR_Tbls_231_cpmqa.log CONSISTENT=Y
SQL> select count(*) from dba_tables where owner='FDR';
  COUNT(*)
----------
       230
SQL> select count(*) from dba_views where owner='FDR';
  COUNT(*)
----------
       240


Re-Compile Invalid Objects
----------------------------

-->To list all invalid objects of all users

select owner,count(*) from dba_objects where status like 'INVA%' group by owner;


--> To list all invalid objects of a particular user, to re-compile

select 'ALTER '||OBJECT_TYPE||' ' ||OWNER||'.'||OBJECT_NAME||' COMPILE;'  from dba_objects where status like 'INVA%' and owner like 'STRATADMIN';
SQL> select owner, object_type,count(*) from dba_objects where owner in ('ABP','ABP_WIP') group by owner,object_type;
select object_type,count(*) from dba_objects where owner='ABP' group by object_type;
select object_type,object_name,status from dba_objects where owner='ABP' and object_type='VIEW';
select 'Grant select on '||object_name||' to abp_user' from dba_objects where owner='ABP' and object_type='VIEW';

--> To Re-Compile, following are the syntaxes
ALTER PACKAGE my_package COMPILE;
ALTER PACKAGE my_package COMPILE BODY;
ALTER PROCEDURE my_procedure COMPILE;
ALTER FUNCTION my_function COMPILE;
ALTER TRIGGER my_trigger COMPILE;
ALTER VIEW my_view COMPILE;
ALTER SYNONYM my_synonym COMPILE;
ALTER PUBLIC SYNONYM my_synonym COMPILE;

--> If compilation error is showing the message DBMS_LOCK, then grant the 'execute' permission and compile the objects once again, the revoke the grants.
GRANT EXECUTE ON DBMS_LOCK TO PUBLIC;
REVOKE EXECUTE ON DBMS_LOCK FROM PUBLIC;
User management:--------------------------------------------------------------------

>CREATE USER SOE IDENTIFIED BY welcome123 DEFAULT TABLESPACE ELHRP TEMPORARY TABLESPACE TEMP PROFILE SERVICE_PROFILE ACCOUNT UNLOCK;
>GRANT CONNECT TO SOE;GRANT OUHRP_HUMAN_RESOURCES TO SOE;...............
>alter user soe quota unlimited on users;
>drop user SOE cascade;
SQL> select USERNAME, TABLESPACE_NAME from DBA_TS_QUOTAS where USERNAME = 'INTEGRATOR';
11:32:54 SQL> alter user integrator quota unlimited on INTGRTON_NDX;
>alter tablespace INTGRTON add datafile '/db/prod06/data6/intgrton02.dbf' size 3000M;
11:33:48 SQL> select USERNAME, TABLESPACE_NAME from DBA_TS_QUOTAS where USERNAME='INTEGRATOR';
USERNAME                       TABLESPACE_NAME
------------------------------ ------------------------------
INTEGRATOR                     INTGRTON_NDX
INTEGRATOR                     INTGRTON
SQL> select table_name from dba_tables where owner='FDR' and table_name like 'IZ_PLN%';
SQL> select USERNAME , DEFAULT_TABLESPACE from dba_users where username like 'TRECS';

SQL> CREATE USER VGAITE IDENTIFIED BY VALUES '0C98D1CE49112F67'  DEFAULT TABLESPACE USERS
    TEMPORARY TABLESPACE TEMP   PROFILE PTM_PROFILE    ACCOUNT UNLOCK;
SQL>select username,account_status from dba_users where username in ('AJORDAN', 'SKELLMKB', 'SKELLNER', 'MSAFRON', 'LPERSAUD');
SQL>select grantee , GRANTED_ROLE from dba_role_privs where grantee='RHERMANS';
16:28:44 SQL> select username,account_status, default_tablespace from dba_users where username = upper('infaREPO85_qa');



CREATE TEMPORARY TABLESPACE TEMP----------------------------------------
first ... extract the tablespace using embarcadero.then drop the tablespace then delete the files then create the temp tablespace  no alter database drop or add
>CREATE TEMPORARY TABLESPACE TEMP   TEMPFILE '/db/ptmtrain/data24/temp04.dbf' SIZE 5000M AUTOEXTEND OFF,   '/db/ptmtrain/data24/temp05.dbf' SIZE 5000M AUTOEXTEND OFF, EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1024K;

DATABASE LINK--------------------------------------------------------------------------
SQL>select * from dba_db_links where host like 'PTM%';
SQL>CREATE DATABASE LINK JDAPAY_TEST CONNECT TO ELODBMS IDENTIFIED BY elc414ret USING 'jdatest';
# JDADEV TEST Box
JDATEST =
(DESCRIPTION =
   (ADDRESS  =
      (PROTOCOL  = TCP )
      (Host = jdadev)
      (Port = 1523)
     )
     (CONNECT_DATA =
        (SID = jdatest))
        (GLOBAL_DBNAME = hpal.com)
       )
SQL> select * from dual@jdapay_test;


set lines 150
col file_name for a50

select file_name,bytes/1024/1024 MB from dba_data_files where tablespace_name='INTGRTON';

Tablespace Check
==============
set sqlcase mixed

COLUMN tablespace_name HEADING Tablespace|Name FORMAT a30
COLUMN totalspace HEADING Total|Space FORMAT 99999999
COLUMN free HEADING Free FORMAT 99999999.99
COLUMN Percent_free HEADING Percent|Free FORMAT 99999999.99
set lines 500
set pages 500
select a.tablespace_name ,c.bytes/1024/1024 TOTALSPACE , round((b.bytes/1024/1024),2) FREE,
100-round((b.bytes/c.bytes)*100,2)  Percent_Used, round((b.bytes/c.bytes)*100,2)  Percent_free from
dba_tablespaces a,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_free_space GROUP BY tablespace_name ) b,
( select count(1) datafiles, SUM(bytes) bytes,
tablespace_name from dba_data_files GROUP BY tablespace_name ) c
where
b.tablespace_name (+) = a.tablespace_name
AND
c.tablespace_name (+) = a.tablespace_name
-- a.tablespace_name='INTGRTON'
-- b.tablespace_name='INTGRTON'
-- c.tablespace_name='INTGRTON'
--and round((b.bytes/c.bytes)*100,2)<6
ORDER BY ((c.bytes-b.bytes)/c.bytes) DESC

SQL> select TABLESPACE_NAME,sum(BYTES_USED/1024/1024) "in MB",sum(BYTES_FREE/1024/1024) "Free in MB",(sum(BYTES_FREE/1024/1024)*100)/(sum(BYTES_FREE/1024/1024)+sum(BYTES_USED/1024/1024)) "pct_free%" from v$temp_space_header group by tablespace_name;
SQL> ALTER TABLESPACE temp ADD TEMPFILE 'J:\TEMPFILES\BG01_TEMP02.DBF' SIZE 1024M;
SQL> ALTER DATABASE TEMPFILE '/db/cpmprod/data4/temp02.dbf' RESIZE 5000M;
SQL> ALTER DATABASE TEMPFILE '/db/cpmprod/data4/temp02.dbf' AUTOEXTEND OFF;
SQL> select sum(bytes)/1024/1024/1024 GB from dba_segments where tablespace_name='WEBMDATA_MDA';
SQL> select owner,segment_type,sum(bytes)/1024/1024 MB from dba_segments where tablespace_name='WEBMDATA_MDA' group by owner,segment_type order by owner,segment_type;


SQL> select FILE_NAME, BYTES/1024/1024 MB from dba_temp_files where TABLESPACE_NAME='TEMP';

FILE_NAME                              MB
------------------------------ ----------
/db/cpmprod/data3/temp01.dbf        32767
/db/cpmprod/data4/temp02.dbf         5000

to see tablespace freespace,pctfree,pctused,total space------------------------------------

COLUMN tablespace_name HEADING Tablespace|Name FORMAT a30
COLUMN totalspace HEADING Total|Space FORMAT 99999999
COLUMN free HEADING Free FORMAT 99999999.99
COLUMN Percent_free HEADING Percent|Free FORMAT 99999999.99
COLUMN Percent_used HEADING Percent|Used FORMAT 99999999.99
set lines 500
set pages 500
select a.tablespace_name ,c.bytes/1024/1024 TOTALSPACE , round((b.bytes/1024/1024),2) FREE,
100-round((b.bytes/c.bytes)*100,2) Percent_used ,round((b.bytes/c.bytes)*100,2) Percent_free from
dba_tablespaces a,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_free_space GROUP BY tablespace_name ) b,
( select count(1) datafiles, SUM(bytes) bytes,
tablespace_name from dba_data_files GROUP BY tablespace_name ) c
where
b.tablespace_name (+) = a.tablespace_name
AND
c.tablespace_name (+) = a.tablespace_name ORDER BY ((c.bytes-b.bytes)/c.bytes) DESC
/
Tablespace                         Total                   Percent      Percent
Name                               Space         Free         Used         Free
------------------------------ --------- ------------ ------------ ------------
TEMP
SYSTEM                               480         2.25        99.53          .47
SYSAUX                               240         3.50        98.54         1.46
EXAMPLE                              100        31.75        68.25        31.75
USERS                                  5         2.00        60.00        40.00
UNDOTBS1                              30        12.56        58.12        41.88



Inrease the UNDO talespace size:-------------------------------------------------
SQL> select tablespace_name,file_name,bytes/1024/1024 MB from dba_data_files where tablespace_name like '%UN%';

ALTER DATABASE DATAFILE '/behp03/MDEV/data1/undotbs1MDEV.dbf' RESIZE 1024M
/
ALTER DATABASE DATAFILE '/behp03/MDEV/data1/undotbs1MDEV.dbf' AUTOEXTEND OFF
/


SQL> select owner,segment_name,segment_type,bytes/1024/1024 MB from dba_segments where segment_name like '%MSG%LOG%' and segment_type='TABLE';

OWNER                          SEGMENT_NAME                             SEGMENT_TYPE               MB
------------------------------ ---------------------------------------- ------------------ ----------
AGQUANTUM                      MSGLOG                                   TABLE                   10368
AGQUANTUM                      TBL_ELC_ARCH_MSGLOG                      TABLE                   10368



Changes done in PFILE to process parameter as 652
====================================================
Sessions = (1.5 * process) +22
dwmos> more initdwmos.ora |grep process
*.job_queue_processes=1
*.processes=652# min 500, increase for higher load
gb-mdt-ux02 oracle /db/dwmos/oracle/product/11.1.0/dbs
Old values in database====================
SQL> select name, value from v$parameter where name in ('sessions','processes');
NAME                                   VALUE
-------------------------- --------------------------------------------------------------------------------
sessions               500
processes            555




DBA broken jobs:
SQL> JOB, LOG_USER, SCHEMA_USER, to_char(LAST_DATE,'dd-mon-yy hh:mi:ss'), TOTAL_TIME, BROKEN, FAILURES from dba_jobs where broken='Y' order by job;
col job for a40
col se for a80
set lines 150
SQL>select 'exec DBMS_JOB.BROKEN('||job||',false);' Job,'exec '||what se from dba_jobs where job in(select JOB from dba_jobs where broken='Y') order by job;
SQL> col job for a40
 SQL> select 'exec DBMS_JOB.BROKEN('||job||',false);' Job,'exec '||what se from dba_jobs where job in(select JOB from dba_jobs where broken='Y') order by job;
JOB                                      SE
---------------------------------------- --------------------------------------------------------------------------------
exec DBMS_JOB.BROKEN(1,false);           exec BEGIN EL_SEND_ORA_EMAIL; END;
exec DBMS_JOB.BROKEN(44,false);          exec BEGIN EL_SEND_ORA_EMAIL; END;
SQL> exec DBMS_JOB.BROKEN(44,false);
PL/SQL procedure successfully completed.


SQL> !date
sql>set time on;



set lines 150
col username for a15
col program for a25
SQL>select sid,serial#,server,username,status, program,to_char(logon_time,'DD-MON-YY HH:MI:SS'), last_call_et from v$session where sid=23;
SQL> select sid,serial# from v$session where sid>80 and SID<100;


Find & Kill the sessiosns by using the SID, Searial#
======================================================
select 'kill -9 '||spid from v$session,v$process where v$session.paddr=v$process.addr  and  v$session.username is not null and v$session.sid=&SID and v$session.serial#=&Serail order by logon_time desc;

SQL> select sql_address from v$session where sid =687;

SQL_ADDRESS
----------------
000000044756A5C0

SQL> select sql_text  from v$sql  where ADDRESS='000000044756A5C0';

SQL_TEXT
------------------------------------------------------------------------------------------------------------------------------------------
SELECT COUNT(*) FROM STG_SOURCING S WHERE S.ITEM = :B2 AND S.DEST = :B1

SQL>select DBMS_XPLAN.DISPLAY() from dual

SQL>@$ORACLE_HOME/rdbms/admin/utlxpls.sql

SQL>select 'kill -9 '||spid from v$session,v$process where v$session.paddr=v$process.addr  and v$session.username is not null and v$session.sid=&SID and v$session.serial#=&Serail order by logon_time desc;

12:23:51 SQL> select sql_address from v$session where sid = &sid;
Enter value for sid: 28
old   1: select sql_address from v$session where sid = &sid
new   1: select sql_address from v$session where sid = 28

Please ensure that the FDRDOOR user account is not locked after the import.
 
Feel free to reach out to me should you have any questions.
 
Also, please let us know when the migration is complete.
 
Thank you!