=============================================== ****shrinking segment using segment adviser**** =============================================== Prerequisite 1)create tablespace and grant quota to user SQL> create tablespace

tbs datafile '/u01/app/oracle/oradata/jarvis/tbs01.dbf' s ize 10m autoextend on; SQL> alter user hr quota unlimited on tbs; 2)perform some bulk insert and delete operations /* SQL> create table emp tablespace tbs as select * from employees; Table created. SQL> begin 2 for i in 1..1000 loop 3 insert into emp select * from employees; 4 end loop; 5 end; 6 / PL/SQL procedure successfully completed. SQL> delete emp where department_id=50; 45045 rows deleted. SQL> SQL> begin 2 for i in 1..10000 loop 3 insert into emp select * from employees; 4 end loop; 5 end; 6 / PL/SQL procedure successfully completed. SQL> delete from emp where department_id=70; 11001 rows deleted. SQL> delete from emp where department_id=50; 450000 rows deleted. SQL> delete from emp where department_id=30; 66006 rows deleted. SQL> commit; Commit complete. */ **procedure** 1)start enterprise manager

create session to sagar. . 4)attempt to create the following table in user schema SAGAR@orcl>create table emp 2 (eid number) 3 storage(initial 10M). reasons for space allocation error 1)out of space 2)maximum extents reached(only for dictionary managed tablespace) 3)space quota exceeded to run resumable statement enable resumable for session SQL>alter session enable resumable **case study** 1)create a user and grant him quota on tablespace SYS@orcl>create user sagar identified by sagar default tablespace tbs quota 5M on tbs. the sus pended operation automatically resumes.2)goto Related links --> Advisor central--> Advisors --> Segment Advisor --> 3)include the relevant tablespace and submit task 4)view the recommendation of segment adviser to shrink segment ================================== ****resumable space allocation**** ================================== Resumable space allocation Oracle database provides a means for suspending and later resuming. This enables you to take corrective action instead of the Oracle database server returning an error to the user. /* create table emp * ERROR at line 1: ORA-01536: space quota exceeded for tablespace 'TBS' */ 5)Now enable resumable in session SAGAR@orcl>alter session enable resumable timeout 900. note:RESUMABLE_TIMEOUT initialization parameter indicates the number of seconds before a timeout occurs. the executio n of large database operation in the event of space allocation failures. 2)grant user required privileges SYS@orcl>grant create table. After the error condition is corrected. 3)grant resumable privilege to user SYS@orcl>grant resumable to sagar.

HR@orcl>insert into trntable values(sysdate-1). 4)create a table in the tablespace HR@orcl>create table trntable 2 (cal date). note:the statement will be suspended 7)meanwhile grant required quota to user SYS@orcl>alter user sagar quota unlimited on tbs. HR@orcl>commit.log 4)start the target database [oracle@oracle10g ~]$ export ORACLE_SID=yahoo [oracle@oracle10g ~]$ sqlplus / as sysdba SQL> startup 5)create a directory in OS SQL> !mkdir /u01/app/oracle/orcl_directory . 5)insert rows in the table HR@orcl>insert into trntable values(sysdate-2). 2)create a oracle directory object SYS@orcl>create or replace directory external_directory as '/u01/app/oracle/exte rnal_directory'. 3)use data pump to extract metadata [oracle@oracle10g ~]$ expdp directory=external_directory dumpfile=trn. 3)grant quota on the tablespace to user SYS@orcl>alter user hr quota unlimited on trntbs.6)Try to create the table again SAGAR@orcl>create table emp 2 (eid number) 3 storage(initial 10M). **transportable tablespace procedure** 1)make the tablespace read only SYS@orcl>alter tablespace trntbs read only.dmp transp ort_tablespaces=trntbs logfile=trn. HR@orcl>insert into trntable values(sysdate). Now the suspended statement will resume and table will be created ================================ ****transportable tablespace**** ================================ Prerequisites: 1)use two databases for this activity source database jarvis target database orcl 2)create a tablespace in orcl SYS@orcl>create tablespace trntbs datafile '/u01/app/oracle/oradata/orcl/trntbs0 1.dbf' size 10M.

dbf' 9)make tablespace read write SQL> alter tablespace tbs read write. 8)use data pump to import metadata [oracle@station60 ~]$ impdp directory=orcl_directory dumpfile=trn.dmp transport_ datafiles='/u01/app/oracle/orcl_directory/trntbs01.6)ship the datafile dumpfile and logfile of the transportable tablespace to the directory SQL> !cp /u01/app/oracle/transport_directory'/'* /u01/app/oracle/orcl_directory SQL> !cp /u01/app/oracle/oradata/jarvis/tbs01. .dbf /u01/app/oracle/orcl_directory / 7)create oracle object directory to refer the OS directory orcl_directory SQL> create or replace directory orcl_directory as '/u01/app/oracle/orcl_directo ry'.