You are on page 1of 6

show parameter DB_BLOCK_SIZE select 'grant '||privilege||' to '||grantee||';' from DBA_SYS_PRIVS where grantee='FMAQBOOL'; select username,account_status from dba_users

where account_status='&ACCOUNT_STATUS' select username,account_status from dba_users where username = &USERNAME; select GRANTEE, granted_role from dba_role_privs where grantee ='&USERNAME'; select grantee,privilege from dba_sys_privs where grantee in (USER,'DBA') order by privilege; Indexes Information select owner,table_name,index_name from dba_indexes where owner='SOR' and table_name like'%MSC%' order by 2 select owner,table_name,index_name,status from dba_indexes where owner='SOR' and status='UNUSABLE' order by 2 select owner,table_name,index_name from dba_indexes where owner='SOR' and table_name like'%&TABLE_NAME%' order by 2 User and their assign tablespace with roles SELECT u.username, u.default_tablespace, u.temporary_tablespace, u.profile, r.granted_role, r.admin_option, r.default_role FROM dba_users u, dba_role_privs r WHERE u.username = r.grantee and u.username like UPPER('%&USERNAME%') GROUP BY u.username, u.default_tablespace,u.temporary_tablespace, u.profile, r.granted_role, r.admin_option, r.default_role; select * from dba_datapump_jobs; How to find out Roles assigned to a Role: select * from role_role_privs where role='&ROLENAME'; TO see table name owner, its tablespace and partition info col SEGMENT_NAME format a15 select owner,segment_name,tablespace_name,PARTITION_NAME from dba_segments where owner='SOR' and segment_name='MSC_CDR' col SEGMENT_NAME format a30 col owner format a10 select owner,segment_name,segment_type,tablespace_name,PARTITION_NAME from dba_segments where tablespace_name =&TABLESSPACE_NAME Getting the size of tablespace

select tablespace_name, sum(bytes) from dba_data_files group by tablespace_name; select tablespace_name, sum(bytes)/1024/1024 SIZE_IN_MB,maxbytes/1024/1024 MAX_SIZE_IN_MB from dba_data_files where tablespace_name like '%MSC%' group by tablespace_name, maxbytes Renaming Tablespace alter tablespace paktelods_temptables rename to paktelods_data Dropping Tablespace DROP TABLESPACE "PAKTEL_ODS" INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS ADDING DATAFILES ALTER TABLESPACE "SOR_PRE_VOICE_SU_IN_OCT06W1" ADD DATAFILE '+ORADATA(DATAFILE)' SIZE 1024M AUTOEXTEND ON NEXT 100M MAXSIZE 4096M ALTER TABLESPACE "FLEETAGGTABLE07" ADD DATAFILE '/m47/oradata/avsedwp/FleetAggTable07c.dbf' SIZE 1024M AUTOEXTEND ON NEXT 100M MAXSIZE 2048M;

CREATE TABLESPACE data_lrg DATAFILE 'c:\temp\inddemo1.dbf' SIZE 250M AUTOEXTEND ON EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;
CREATE SYNONYM TEST.PRE_SMS_SU FOR PRE_SMS_SU; GRANT DELETE ON PRE_SMS_SU TO SOR_DELETE_ROLE; How fragmented a Tablespace is: SELECT Tablespace_Name, SQRT( MAX( Blocks ) / SUM( Blocks ) ) * (100 / SQRT( SQRT(COUNT(Blocks ) ) ) ) AS FSFI FROM DBA_Free_Space where tablespace_name like '%MSC%' GROUP BY Tablespace_Name Taking table name and size (exact table size) col segment_name format a25 select owner,segment_name,bytes/1024000 MB from dba_segments where segment_name like '%BACKUP%' or segment_name like '%BKP%' or segment_name like '%TEST%' or segment_name like '%TEMP%' and OWNER not in ('SYS','SYSTEM','SYSMAN','PUBLIC') col segment_name format a30 Select owner,segment_name,bytes/1024000 MB from dba_segments where OWNER =upper(&OWNER); col segment_name format a30 Select owner,segment_name,bytes/1024000 MB from dba_segments where segment_name like upper('%&SEGMENT_NAME%') and OWNER =upper(&OWNER); col segment_name format a30 Select owner,segment_name,tablespace_name,bytes/1024000 MB from dba_segments where tablespace_name =upper('&TBS_NAME') order by 4 desc

For combine byte count select owner,segment_name,segment_type,sum(bytes/1024000) MB from dba_segments where OWNER in ('SOR','PAKTEL_ODS','BATCH_AA','ETL') and segment_type like '%TABLE%' group by segment_name,segment_type,owner order by 3 desc / select segment_name,segment_type,sum(bytes/1024000) MB from dba_segments where segment_name ='&SEGMENT_NAME' and OWNER ='&OWNER' group by segment_name,segment_type /

Taking table_name and size (estimate table size) SELECT owner, table_name, NVL(num_rows*avg_row_len,0)/1024000 MB FROM dba_tables where table_name like '%BACKUP%' or table_name like '%BKP%' or table_name like '%TEST%' or table_name like '%TEMP%' and OWNER not in ('SYS','SYSTEM','SYSMAN','PUBLIC')

select username,default_tablespace from dba_users where username='PAKTEL_ODS' alter user paktel_ods default tablespace PAKTELODS_DATA select table_name,PARTITION_NAME,TABLESPACE_NAME,logging from DBA_TAB_PARTITIONS where logging <> 'NO' and table_owner in ('SOR','BATCH_AA','PAKTEL_ODS') To check the dependent objects for a table: select NAME,TYPE from dba_dependencies where REFERENCED_NAME=upper('Market_Share_msisdn_temp'); To find owner of specific objects select OWNER,OBJECT_NAME from dba_objects where OBJECT_NAME='dependant object name';

GRANTS Alter user masif quota 5m on IMPTEST; revoke unlimited tablespace from SCOTT

Analyzing Statement Estimate Statistics begin dbms_stats.gather_table_stats(OWNNAME=>'BATCH_AA',tabname=>'ODS_PRE_REV_USG_C UBE_MSISDN',cascade=>TRUE,degree=>8,method_opt=>'FOR ALL INDEXED COLUMNS SIZE SKEWONLY',estimate_percent=>10/5,granularity=>'ALL'); Either 10 or 5 according to table size

end; Compute Statistics analyze table t compute statistics for table; analyze table t compute statistics for all indexes; analyze table t compute statistics for all indexed columns; grant select any dictionary to fkhalid; select value blocksize from v$parameter where name = 'db_block_size' select owner,index_name,table_name,status from dba_indexes where status <> 'VALID' and owner not like '%SYS%' order by 3

select name,value from v$parameter order by 1; select table_name from dba_tables where owner='PAKTEL_ODS' minus select table_name from dba_tables where owner='PERFTEST' grant write on directory "dumps2" to public; TO Drop a user and its tablespaces 1. drop user user_name cascade; 2. drop tablespace abc including contents and datafiles cascade constraints; select * from dba_data_files where status = 'OFFLINE'; select CONSTRAINT_NAME,owner,STATUS,INVALID from dba_constraints where status <>'ENABLED'

To unlock the schemas for analyzing purpose: begin -dbms_stats.gather_table_stats(OWNNAME=>'SOR',tabname=>'PRE_VOICE_SU',cascade=> TRUE,degree=>8,method_opt=>'FOR ALL INDEXED COLUMNS SIZE SKEWONLY',estimate_percent=>5,granularity=>'ALL'); DBMS_STATS.UNLOCK_SCHEMA_STATS (ownname=>'PAKTEL_ODS'); end;

select SEGMENT_NAME,TABLESPACE_NAME,PARTITION_NAME,BYTES/1024000 MB from dba_segments where segment_name like '%&TABLE_NAME%' and segment_type like '%TABLE%' order by 2

The following scripts will generate the scripts for compiling dependent objects. select 'alter ' || type || ' ' || owner || '.' || name || ' compile;' from dba_dependencies where REFERENCED_OWNER='&OWNER' and referenced_name='&TABLE_NAME' and type not in 'PACKAGE BODY' /

select 'alter package ' || owner || '.' || name || ' compile body;' from dba_dependencies where REFERENCED_OWNER='&OWNER' and referenced_name='&TABLE_NAME' and type in 'PACKAGE BODY' /

How can one see who is using a temporary segment?


select s.username, u."USER", u.tablespace, u.contents, u.extents, u.blocks from sys.v_$session s, sys.v_$sort_usage u where s.saddr = u.session_addr / select s.osuser, s.process, s.username, s.serial#, sum(u.blocks)*vp.value/1024 sort_size from sys.v_$session s, sys.v_$sort_usage u, sys.v_$parameter vp where s.saddr = u.session_addr and vp.name = 'db_block_size' and s.osuser like '&1' group by s.osuser, s.process, s.username, s.serial#, vp.value / set appropriate values for pga_aggregate_target and _pga_max_size alter system set pga_aggregate_target=6G; alter system set "_pga_max_size"=2000000000;

select 'alter system kill session '||''''||sid||','||serial#||''''||' immediate;' from v$session where username='SMEHMOOD';

select * from dba_rollback_segs where status='ONLINE' and tablespace_name in ('UNDOTBS1','UNDOTBS2');

Enabling or disabling whole schema constraints


select 'alter table interactive_prod.'||table_name||' disable constraint '||constraint_name||';' from dba_constraints where owner='INTERACTIVE_PROD' and table_name='V8_PROGRAM' and constraint_type='R'; select 'truncate table interactive_prod.'||table_name||';' from dba_tables where owner='INTERACTIVE_PROD'; select 'alter table interactive_prod.'||table_name||' enable constraint '||constraint_name||';' from dba_constraints where owner='INTERACTIVE_PROD' and constraint_type='R'; select constraint_name,constraint_type,table_name,status from dba_constraints where owner='INTERACTIVE_PROD' and STATUS <>'ENABLED';