Professional Documents
Culture Documents
Cleenup
Cleenup
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;
/
After this move the objects from NEW_DEVT and FRAGMT tablespaces to the DEVT
tablespaces and resize the datafiles.
-----------------------------------------------------------------------
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
declare
n_cnt number :=0;
cursor c1 is
select doc_id
from dbo.document order by 1;
begin
for i in c1 loop
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;
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;
/
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;
/
-----------------------------------------------------------------------------------
----
-- 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;
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;
/
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;
/
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;
/
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;
/
-----------------------------------------------------------------------------------
-
--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
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';
MERGE.NT_CLIENT_EST_TAB
MERGE.NT_PRODUCT_EST_TAB
===================================================================================
===============================
create tablespace CLAIMS_DATA_NEW datafile '+DATA' size 100m autoextend on next 50m
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);