Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 12

SET UNDO_RETENTION TO 1800

set serveroutput on
declare
cursor c1 is
select owner,table_name,tablespace_name
from dba_indexes
where owner in ('BENDEV','BENLOAD')
AND INDEX_TYPE ='IOT - TOP';
begin
for i in C1 loop
begin
execute immediate 'drop table '||i.owner||'.'||i.table_name||'';
exception
when others then dbms_output.put_line('ORA-'||SQLCODE||' Failed to move IOT '||
i.table_name);
end;
end loop;
end;
/
==================================================

declare
cursor c1 is
select owner,table_name from dba_tables where owner in ('BENLOAD');
begin
for i in c1 loop
begin
execute immediate 'drop table '||i.owner||'.'||i.table_name||' purge';
exception when others then null;
end;
end loop;
end;
/

declare
cursor c1 is
select OWNER,QUEUE_TABLE,name
from dba_queues
where owner in ('BENDEV','BENLOAD');
begin
for i in C1 loop
begin
EXECUTE IMMEDIATE 'SYS.DBMS_AQADM.DROP_QUEUE_TABLE (QUEUE_TABLE => '||
i.OWNER||'.'||i.QUEUE_TABLE||',force=>true)';
exception
when others then dbms_output.put_line('ORA-'||SQLCODE||' Failed to move IOT '||
i.QUEUE_TABLE);
end;
end loop;
end;
/

execute SYS.DBMS_AQADM.DROP_QUEUE_TABLE (QUEUE_TABLE =>


'bendev.METADATA_REFRESH_Q',force=>true);

After this move the objects from NEW_DEVT and FRAGMT tablespaces to the DEVT
tablespaces and resize the datafiles.

-----------------------------------------------------------------------

-- Truncate the following tables:

dbo.document
dbo.import_detail
dbo.export_detail
dbo.batch_detail_log
dbo.batch_message_log
dbo.import_exception
dbo.exception_log
dbo.document ( LOB )
dbo.exception_log ( LOB )
dbo.import_error

-- delete document images


create table SYS.aa (col1 number,col2 date);
alter table dbo.document disable all triggers;

declare
n_cnt number :=0;
cursor c1 is
select doc_id
from dbo.document order by 1;

begin
for i in c1 loop

update dbo.document set doc_image=empty_blob() where doc_id = i.doc_id;


n_cnt := n_cnt + 1;

if mod(n_cnt,1000) = 0 then
insert into sys.aa values(n_cnt,sysdate);
commit;
end if;

end loop;
commit;
end;
/

alter table DBO.DOCUMENT move lob (DOC_IMAGE) store as (tablespace DEVT) PARALLEL
4;

alter table DBO.IMPORT_DETAIL disable all triggers;


alter table DBO.BATCH_DETAIL_LOG disable all triggers;
alter table DBO.EXCEPTION_LOG disable all triggers;
alter table DBO.DOCUMENT disable all triggers;
alter table DBO.IMPORT_ERROR disable all triggers;
alter table DBO.BATCH_MESSAGE_LOG disable all triggers;
alter table DBO.IMPORT_EXCEPTION disable all triggers;
alter table DBO.EXPORT_ERROR disable all triggers;

truncate table DBO.BATCH_DETAIL_LOG;


truncate table DBO.BATCH_MESSAGE_LOG;
truncate table DBO.IMPORT_ERROR;
truncate table DBO.IMPORT_EXCEPTION;
truncate table DBO.EXPORT_ERROR;
truncate table DBO.EXPORT_TEMP;
truncate table DBO.EXCEPTION_LOG;

-----------------IF Error gets ---------------------------


while execute :-truncate table DBO.EXCEPTION_LOG;
ERROR at line 1:
ORA-02266: unique/primary keys in table referenced by enabled foreign keys

select count(*) from dbo.exception_log


workflow.wf_action_history--FK_WF_AC_HIST__EX_LO_ID

alter table WORKFLOW.WF_ACTION_HISTORY disable constraint FK_WF_AC_HIST__EX_LO_ID;


-----------------------------------------------------------------------

declare
cursor c1 is
select owner,table_name,constraint_name
from dba_constraints where table_name in
('EXPORT_ERROR','EXPORT_TEMP','IMPORT_ERROR','IMPORT_EXCEPTION');
begin
for i in c1 loop
execute immediate 'alter table '||i.owner||'.'||i.table_name||' disable constraint
'||i.constraint_name;
end loop;
end;
/

truncate table DBO.EXPORT_DETAIL;


truncate table DBO.IMPORT_DETAIL;

declare
cursor c1 is
select owner,table_name,constraint_name
from dba_constraints where table_name in
('EXPORT_ERROR','EXPORT_TEMP','IMPORT_ERROR','IMPORT_EXCEPTION');
begin
for i in c1 loop
execute immediate 'alter table '||i.owner||'.'||i.table_name||' enable constraint
'||i.constraint_name;
end loop;
end;
/

alter table DBO.IMPORT_DETAIL enable all triggers;


alter table DBO.BATCH_DETAIL_LOG enable all triggers;
alter table DBO.EXCEPTION_LOG enable all triggers;
alter table DBO.DOCUMENT enable all triggers;
alter table DBO.IMPORT_ERROR enable all triggers;
alter table DBO.BATCH_MESSAGE_LOG enable all triggers;
alter table DBO.IMPORT_EXCEPTION enable all triggers;
alter table DBO.EXPORT_ERROR enable all triggers;
alter table DBO.document enable all triggers;

-----------------------------------------------------------------------------------
----
-- Create a new_DEVT tablespace and move the DEVT objects there and rebuild the
unusable indexes
-- MOVE TABLES withIN DEVT TABLESPACE TO FREE UP SPACE AT THE END OF THE FILE
create tablespace DEVT_NEW datafile 'F:\SAG\V3STGER2\DATA\DEVT_01.DBF' size 200m
autoextend on next 100m maxsize unlimited;
alter tablespace FRAGMI_NEW add datafile 'D:\V3PROD\DATAFILE\FRAGMI_02.DBF' size
200m autoextend on next 100m maxsize unlimited;
alter tablespace INDEXES_NEW add datafile '/u02/oradata/c2bv3qanew/indexes_03.dbf'
size 500m autoextend on next 100m maxsize unlimited;
alter tablespace IMAGT add datafile '/u02/oradata/necbfprd/IMAGT_NEW_04.DBF' size
500m autoextend on next 100m maxsize unlimited;
alter tablespace INDEXES add datafile '+DATA' size 200m autoextend on next 100m
maxsize unlimited;
=============================
export ORACLE_SID=+ASM1
export ORACLE_HOME=/u01/app/12.1.0/grid
asmcmd -p
==============================

V3CONV_DATA
create tablespace USERS_NEW datafile 'E:\1199\USERS_01.DBF' size 1g autoextend on
next 1g maxsize unlimited;
alter tablespace USERS_NEW add datafile 'E:\1199\USERS_02.DBF' size 1g autoextend
on next 1g maxsize unlimited;

create tablespace DEVT_NEW datafile '+DATA' size 100m autoextend on next 50m
maxsize unlimited;
alter tablespace DEVT_NEW add datafile '+DATA' size 100m autoextend on next 50m
maxsize unlimited;

alter tablespace DBFS_TS drop datafile


'+DATA/DBFSPROD/DATAFILE/dbfs_ts.309.884399937' offline;

alter database datafile '+DATA/DBFSPROD/DATAFILE/dbfs_ts.309.884399937';

SELECT SUM(BYTES)/(1024*1024*1024) FROM DBA_DATA_FILES WHERE


TABLESPACE_NAME='DEV_DATA';
SELECT DISTINCT OWNER,SEGMENT_NAME,SEGMENT_TYPE FROM DBA_SEGMENTS WHERE
TABLESPACE_NAME='USERS';

set serveroutput on
DECLARE
cursor c1 is
select owner,table_name
from dba_tables
where tablespace_name='USERS';

begin
for i in c1 loop

begin
EXECUTE IMMEDIATE 'alter table '||i.owner||'.'||i.table_name||' ENABLE ROW
MOVEMENT';
execute immediate 'alter table '||i.owner||'.'||i.table_name||' move parallel 4
TABLESPACE USERS_NEW';
EXECUTE IMMEDIATE 'alter table '||i.owner||'.'||i.table_name||' DISABLE ROW
MOVEMENT';
exception
when others then null;
end;
end loop;
end;
/

select segment_type,count(*) from dba_segments where tablespace_name='USERS' group


by segment_type;
select segment_type,count(*) from dba_segments where tablespace_name='DEVT' group
by segment_type;

set serveroutput on
DECLARE
CURSOR C1 IS
select OWNER,TABLE_NAME,column_name
from dba_lobs
where tablespace_name='USERS';

BEGIN

for i in C1 loop
begin
execute immediate 'ALTER TABLE '||i.OWNER||'.'||i.TABLE_NAME||' move lob ('||
i.column_name||') store as (tablespace USERS_NEW)';
exception
when others then dbms_output.put_line('ORA-'||SQLCODE||' Failed to move lob on '||
i.TABLE_NAME);
end;
end loop;
END;
/
==========================================
-- -- Move indexes from USERS tablespace to USERS_NEW tablespace (without online
option)
SET SERVEROUTPUT ON
DECLARE
CURSOR C1 IS
select i.owner,i.index_name
from dba_indexes i
where i.tablespace_name = 'USERS';

BEGIN
for i in C1 loop
begin
execute immediate 'alter index '||i.owner||'.'||i.index_name||' rebuild PARALLEL 4
tablespace USERS_NEW';
exception
when others then dbms_output.put_line('ORA-'||SQLCODE||' Failed to rebuild index
'||i.index_name);
end;
end loop;
END;
/
===================================================

SET SERVEROUTPUT ON
DECLARE
CURSOR C1 IS
select i.owner,i.segment_name
from dba_segments i
where i.tablespace_name = 'SECURITY_T'
and segment_type='INDEX'
order by 1;

BEGIN
for i in C1 loop
begin
execute immediate 'alter index '||i.owner||'.'||i.segment_name||' rebuild PARALLEL
4 tablespace SECURITY_T_E';
exception
when others then dbms_output.put_line('ORA-'||SQLCODE||' Failed to rebuild index
'||i.segment_name);
end;
end loop;
END;
/

-- Move IOT table to indexes tablespaces


set serveroutput on
declare
cursor c1 is
select owner,table_name,tablespace_name
from dba_indexes
where tablespace_name='USERS'
AND INDEX_TYPE ='IOT - TOP';

begin
for i in C1 loop
begin
execute immediate 'alter table '||i.owner||'.'||i.table_name||' move tablespace
USERS_NEW';
exception
when others then dbms_output.put_line('ORA-'||SQLCODE||' Failed to move IOT '||
i.table_name);
end;
end loop;
end;
/

UNUSABLE INDEXES;
------------------

SET SERVEROUTPUT ON
DECLARE
CURSOR C1 IS
select i.owner,i.table_name,i.index_name
from dba_indexes i
where i.owner NOT IN ('SYS','SYSTEM')
and status = 'UNUSABLE'
order by 1;

BEGIN
for i in C1 loop
begin
execute immediate 'alter index '||i.owner||'.'||i.index_name||' rebuild tablespace
indexes';
exception
when others then dbms_output.put_line('ORA-'||SQLCODE||' Failed to rebuild index
'||i.index_name);
end;
end loop;
END;
/
========================
SET SERVEROUTPUT ON
DECLARE
CURSOR C1 IS
select i.owner,i.table_name,i.index_name
from dba_indexes i
where i.owner NOT IN ('SYS','SYSTEM')
and status = 'UNUSABLE'
order by 2;

BEGIN
for i in C1 loop
begin
execute immediate 'alter index '||i.owner||'.'||i.index_name||' rebuild tablespace
indexes';
exception
when others then dbms_output.put_line('ORA-'||SQLCODE||' Failed to rebuild index
'||i.index_name);
end;
end loop;
END;
/
===========================

SET SERVEROUTPUT ON
DECLARE
CURSOR C1 IS
select i.owner,i.table_name,i.index_name
from dba_indexes i
where i.owner NOT IN ('SYS','SYSTEM')
and status = 'UNUSABLE'
order by 3;

BEGIN
for i in C1 loop
begin
execute immediate 'alter index '||i.owner||'.'||i.index_name||' rebuild tablespace
indexes';
exception
when others then dbms_output.put_line('ORA-'||SQLCODE||' Failed to rebuild index
'||i.index_name);
end;
end loop;
END;
/

-----------------------------------------------------------------------------------
----
Move table patition

set serveroutput on
DECLARE
cursor c1 is
select owner,segment_name,PARTITION_NAME
from dba_segments
where tablespace_name='DEVT' order by 2;

begin
for i in c1 loop

begin
execute immediate 'alter table '||i.owner||'.'||i.segment_name||' move partition
'||i.PARTITION_NAME||' TABLESPACE DEVT_NEW';
exception
when others then null;
end;
end loop;
end;
/

================== select INDEX PARTITIONS ====================


set lines 139 pages 399
col segment_name for a45
col partition_name for a35
select owner,segment_name,PARTITION_NAME
from dba_segments
where tablespace_name='INDEXES' order by 2;

alter index dbo.DISBURSEMENT_DEDUCTION_FK1 rebuild partition SYS_P43 tablespace


indexes_new;
-----------------------------------------------------------------------------------
--------
set serveroutput on
DECLARE
cursor c1 is
select owner,segment_name,PARTITION_NAME
from dba_segments
where tablespace_name='USERS' order by 2;

begin
for i in c1 loop

begin
execute immediate 'alter index '||i.owner||'.'||i.segment_name||' rebuild partition
'||i.PARTITION_NAME||' TABLESPACE USERS_NEW';

exception
when others then null;
end;
end loop;
end;
/

-----------------------------------------------------------------------------------
-

LONG OPPS QUERY


col message for a80
set pagesize 1000 linesize 120
SELECT sid, to_char(start_time,'hh24:mi:ss') stime,
message,( sofar/totalwork)* 100 percent
FROM v$session_longops
WHERE sofar/totalwork < 1
/

--select * from dba_segments where tablespace_name='USERS'


set lines 139 pages 299
select sum(bytes/1024/1024/1024),sum(maxbytes/1024/1024/1024),tablespace_name from
dba_data_files group by tablespace_name;

set lines 139 pages 299


select sum(bytes/1024/1024/1024),sum(maxbytes/1024/1024/1024) from dba_data_files
where tablespace_name='DBFS_TS' group by file_id;

--GRANT unlimited tablespace to dbo

set lines 139 pages 299


select SUM(BYTES/1024/1024/1024),tablespace_name from dba_free_space group by
tablespace_name order by 1 desc;

select last_analyzed from dba_indexes where owner='DBO' and last_analyzed!='12-MAR-


15';

select count(*) from dba_indexes where owner='DBO' and last_analyzed='12-MAR-15';

--ALTER DATABASE DATAFILE '/u02/oradata/v3prod/fragmi_01.dbf' RESIZE 5 M;

--select
sum(bytes/1024/1024/1024),sum(maxbytes/1024/1024/1024),file_id,tablespace_name from
dba_data_files group by file_id order by file_id

--select sum(bytes/1024/1024/1024),file_id from dba_free_space group by file_id


order by file_id

alter index PK_QUERY_REPORT_GROUP rebuild online;

alter table CLIENT.TBL_CONSTRAINT_MDATA_SNAPSHOT move tablespace USERS_NEW;


LONG or LONG_RAW
alter table CLIENT.TBL_CONSTRAINT_MDATA_SNAPSHOT modify ELIG_RULE_EXPRESSION clob;
alter table CLIENT.TBL_CONSTRAINT_MDATA_SNAPSHOT move tablespace USERS_NEW;

select segment_type,count(*) from dba_segments where tablespace_name='USERS' group


by segment_type;
select segment_type,count(*) from dba_segments where tablespace_name='DEVI_NEW'
group by segment_type;
select sum(bytes/1024/1024/1024) from dba_segments where tablespace_name='USERS';
select file_name from dba_Data_files where tablespace_name='WHISTORY';

select segment_type,count(*) from dba_segments where tablespace_name='FRAGMT' group


by segment_type;
select segment_type,count(*) from dba_segments where tablespace_name='FRAGMT_NEW'
group by segment_type;
select segment_type,count(*) from dba_segments where tablespace_name='NEW_FRAGMT'
group by segment_type;
select segment_type,count(*) from dba_segments where tablespace_name='USERS' group
by segment_type;
select sum(bytes/1024/1024/1024) from dba_segments where tablespace_name='USERS';
select file_name from dba_Data_files where tablespace_name='USERS';

select segment_type,count(*) from dba_segments where tablespace_name='INDEXES'


group by segment_type;
select sum(bytes/1024/1024/1024) from dba_segments where tablespace_name='INDEXES';
select file_name from dba_Data_files where tablespace_name='INDEXES';

alter tablespace INDX3 add datafile '/u02/oradata/ufcwp12c/INDX3_03.DBF' size 100m


autoextend on next 50m maxsize unlimited;

alter tablespace INDEXES drop datafile '/u02/oradata/ufcwp12c/INDX3_03.DBF';

select segment_type,count(*) from dba_segments where tablespace_name='USERS' group


by segment_type;
select sum(bytes/1024/1024/1024) from dba_segments where tablespace_name='INDX3';
select file_name from dba_Data_files where tablespace_name='INDX3';

select segment_type,count(*) from dba_segments where tablespace_name='FRAGMT' group


by segment_type;
select sum(bytes/1024/1024/1024) from dba_segments where tablespace_name='FRAGMT';
select file_name from dba_Data_files where tablespace_name='FRAGMT';

select count(*) from dba_indexes where status='UNUSABLE';


select count(*) from dba_indexes where status='UNUSABLE';

select 'alter index '||owner||'.'||index_name||' rebuild online;' from dba_indexes


where status='UNUSABLE';

select 'alter index '||owner||'.'||segment_name||' rebuild tablespace USERS_NEW;'


from dba_segments where tablespace_name='USERS';

select owner,segment_name,segment_type from dba_segments where


tablespace_name='USERS';

select

select sql_id from v$session where sql_id is not null;

select 'alter index '||owner||'.'||index_name||' rebuild PARALLEL 4 tablespace


USERS;' from dba_indexes where tablespace_name like '%NEW%';

=================================current running sql=============================


select sql_id from v$session where sql_id is not null;
select sql_text from v$sql where sql_id='frnu4zjh5gp7w';
==============================================================================

[2/20/2015 4:03 AM] Raju Maku:


---------------------oerr ora 14404----------------

select table_name,partition_name,tablespace_name,'TABLE' as object_type from


dba_tab_partitions
where tablespace_name = 'INDEXES'
union all
select index_name,partition_name,tablespace_name,'INDEX' from dba_ind_partitions
where tablespace_name = 'INDEXES'
order by 1
/

Select 'ALTER INDEX '|| index_name ||' rebuild partition ' || PARTITION_NAME || '
TABLESPACE ' || 'INDEXES_NEW' ||';' from dba_ind_partitions where tablespace_name =
'USERS';

select 'ALTER INDEX ' || INDEX_OWNER || '.' || INDEX_NAME ||' REBUILD PARTITION '||
PARTITION_NAME ||' TABLESPACE ' ||'indexes_new' ||';' from dba_ind_partitions where
tablespace_name = 'INDEXES';

alter table DBO.WORK_HISTORY_1 move partition WORK_HISTORY_MAX tablespace


NEW_USERS;

drop tablespace users including contents and datafiles cascade constraints;


===================================================================================
==============================

alter index IMAGING.PK_ANNOTATION_STAMP_SET rebuild tablespace users_new;


alter index IMAGING.PK_DOCUMENT_IMAGE_TEXT rebuild tablespace users_new;
alter index IMAGING.DOC_SHELL_FOLDER rebuild tablespace users_new;
alter index IMAGING.SYS_C00103362 rebuild tablespace users_new;

MERGE.NT_CLIENT_EST_TAB
MERGE.NT_PRODUCT_EST_TAB

select owner, constraint_name,table_name,index_owner,index_name


from dba_constraints
where (index_owner,index_name) in (select owner,index_name from dba_indexes
where tablespace_name='INDEXES');

alter table MERGE.NT_CLIENT_EST_TAB move tablespace users_new;


alter table MERGE.NT_PRODUCT_EST_TAB move tablespace users_new;

SELECT OWNER, INDEX_NAME FROM DBA_INDEXES WHERE INDEX_TYPE = 'DOMAIN';

SELECT OWNER, TABLE_NAME, 'TABLE', TABLESPACE_NAME, NULL AS LOB


FROM DBA_TABLES
WHERE TABLESPACE_NAME = 'INDEXES'
UNION ALL
SELECT OWNER, INDEX_NAME, 'INDEX', TABLESPACE_NAME,
NULL
FROM DBA_INDEXES
WHERE TABLESPACE_NAME = 'INDEXES'
UNION ALL
SELECT L.OWNER,
L.TABLE_NAME,
S.SEGMENT_TYPE,
S.TABLESPACE_NAME,
L.COLUMN_NAME
FROM DBA_SEGMENTS S, DBA_LOBS L, DBA_TABLES T
WHERE S.SEGMENT_TYPE = 'LOBSEGMENT'
AND S.OWNER = L.OWNER
AND S.SEGMENT_NAME = L.SEGMENT_NAME
AND L.TABLE_NAME = T.TABLE_NAME
AND L.OWNER = T.OWNER
AND L.TABLESPACE_NAME = 'INDEXES';

===================================================================================
===============================

create tablespace CLAIMS_DATA_NEW datafile '+DATA' size 100m autoextend on next 50m

maxsize unlimited EXTENT MANAGEMENT LOCAL ENCRYPTION USING 'AES256' DEFAULT


STORAGE(ENCRYPT) SEGMENT SPACE MANAGEMENT AUTO;

alter tablespace CLAIMS_DATA_NEW add datafile '+DATA' size 100m autoextend on next
50m maxsize unlimited EXTENT MANAGEMENT LOCAL ENCRYPTION USING 'AES256' DEFAULT
STORAGE(ENCRYPT) SEGMENT SPACE MANAGEMENT AUTO;

17 /
ORA--24005 Failed to move IOT AQ$_METADATA_REFRESH_Q_G
ORA--24005 Failed to move IOT AQ$_METADATA_REFRESH_Q_H
ORA--24005 Failed to move IOT AQ$_METADATA_REFRESH_Q_I
exec dbms_aqadm.drop_queue_table('DBO.AQ$_METADATA_REFRESH_Q_I',force=>true);

exec dbms_aqadm.drop_queue_table('DBO.AQ$_METADATA_REFRESH_Q_G',force=>true);

exec dbms_aqadm.drop_queue_table('DBO.AQ$_METADATA_REFRESH_Q_H',force=>true);

You might also like