Archive for ‘tablespace’

June 7, 2011

Which query causes “ORA-01652: unable to extend temp segment by % in tablespace TEMP”


connect / as sysdba

drop table temp_usage_t;
create table temp_usage_t ( msg varchar2(4000) );

create or replace trigger failed_to_extend_temp
after servererror on database
declare
l_sql_text ora_name_list_t;
l_n        number;
begin
if ( is_servererror(1652) )
then
insert into temp_usage_t values ( 'ora_sysevent = ' || ora_sysevent );
insert into temp_usage_t values ( 'ora_login_user = ' || ora_login_user );
insert into temp_usage_t values ( 'ora_server_error = ' || ora_server_error(1) );

l_n := ora_sql_txt( l_sql_text );
for i in 1 .. l_n
loop
insert into temp_usage_t values ( 'l_sql_text(' || i || ') = ' || l_sql_text(i)) ;
end loop;
end if;
end;
/

drop tablespace test_temp including contents and datafiles;
/

create temporary tablespace test_temp
tempfile '/tmp/test_temp.dbf' size 512k reuse
extent management local
uniform size 64k
/

alter user &&user_name temporary tablespace test_temp;

connect &&username

select * from all_objects
order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
/

connect / as sysdba

set echo on termout on


select * from temp_usage_t;

June 1, 2011

shrink space tablespace


COLUMN SHRINK_DATAFILES FORMAT A75 WORD_WRAPPED
COLUMN VALUE NEW_VAL BLKSIZE
SELECT VALUE FROM V$PARAMETER WHERE NAME = 'db_block_size';

SELECT 'ALTER DATABASE DATAFILE ''' || FILE_NAME || ''' RESIZE ' || CEIL( (NVL(HWM,1)*&&BLKSIZE)/1024/1024 ) ||
'M;' SHRINK_DATAFILES FROM DBA_DATA_FILES DBADF,
(SELECT FILE_ID, MAX(BLOCK_ID+BLOCKS-1) HWM FROM DBA_EXTENTS GROUP BY FILE_ID ) DBAFS
WHERE DBADF.FILE_ID = DBAFS.FILE_ID(+) AND CEIL(BLOCKS*&&BLKSIZE/1024/1024)- CEIL((NVL(HWM,1)* &&BLKSIZE)/1024/1024 ) > 0;

SHRINK_DATAFILES
-------------------------------------------------------------------------
ALTER DATABASE DATAFILE '/db/oradata/GOLDTEST/centestdata01.dbf'
RESIZE 9139M;

ALTER DATABASE DATAFILE '/db/oradata/GOLDTEST/centestidx01.dbf'
RESIZE 14871M;

.....

Increase the suggested value to avoid potential errors

ALTER DATABASE DATAFILE '/db/oradata/GOLDTEST/centestdata01.dbf' resize 10000M;

Database altered.