how to cleanup the temp tablespace in oracle 10g server , Please provide the steps for linux plateform - oracle

I want to clean up the Temp table space which have datafiles
temp01.dbf and temp02.dbf, so please suggest me should I drop
temp01.dbf file or drop the temp tablespace. Datafiles of Temp tablespaces is given below
33G temp01.dbf
1.5G temp02.dbf

Create Temporary Tablespace Temp
CREATE TEMPORARY TABLESPACE TEMP2 TEMPFILE ‘/u01/app/oradata/temp01.dbf′ SIZE 2000M ;
Move Default Database temp tablespace
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp2;
Make sure No sessions are using your Old Temp tablespace
a. Find Session Number from V$SORT_USAGE:
SELECT USERNAME, SESSION_NUM, SESSION_ADDR FROM V$SORT_USAGE;
b. Find Session ID from V$SESSION:
If the resultset contains any rows then your next step will be to find the SID from the V$SESSION view. You can find session id by using SESSION_NUM or SESSION_ADDR from previous resultset.
SELECT SID, SERIAL#, STATUS FROM V$SESSION WHERE SERIAL#=SESSION_NUM;
OR
SELECT SID, SERIAL#, STATUS FROM V$SESSION WHERE SADDR=SESSION_ADDR;
c. Kill Session:
Now kill the session with IMMEDIATE.
ALTER SYSTEM KILL 'SID,SERIAL#' IMMEDIATE;
Drop temp tablespace
DROP TABLESPACE temp INCLUDING CONTENTS AND DATAFILES;
Recreate Tablespace Temp
CREATE TEMPORARY TABLESPACE TEMP TEMPFILE '/u01/app/temp/temp01.dbf′ SIZE 2000M;
6 Move Tablespace Temp, back to new temp tablespace
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp;
Drop temporary for tablespace temp
DROP TABLESPACE temp2 INCLUDING CONTENTS AND DATAFILES;

Thanks #anudeepks! Just wanna point something, in step 5 the sentence should be as follows:
CREATE TEMPORARY TABLESPACE TEMP TEMPFILE '/u01/app/temp/temp.dbf′ SIZE 2000M;
(Note that the filename has changed from temp01.dbf to temp.dbf). Otherwise we get an error because the file already exists, and also such file will be deleted on step 7.

Related

How to find TEMP tablespace usage?

we are using v$sort_segment to calculate temp file usage. but one of my temp tablespace not available in v$sort_segment table. IS there any other way to get the correct usage which returns the same value as in v$sort_segment?
V$SORT_SEGMENT only gets populated as a temporary segment is required. For example, if I create a second temp tablespace, then it does not appear because it is not in use
SQL> create temporary tablespace temp2 tempfile 'X:\ORACLE\ORADATA\DB19\PDB1\TEMP02.DBF' size 20m;
Tablespace created.
SQL> select tablespace_name from v$sort_segment;
TABLESPACE_NAME
------------------------
TEMP
If you want a view of all of your temporary tablespaces, you can outer join either DBA_TABLESPACES (type=TEMPORARY) or DBA_TEMP_FILES to V$SORT_SEGMENT.

Table space dropped but dbf file still exist

we have dropped a tablespace by command drop tablespace T1 assuming that the datafile will also be dropped. Later we created the same tablespace T1 with different datafile.
Now the problem is that datafile is holding 14GB of diskspace. Is there any way to recover that space from the datafile. Please suggest.
Thanks in advance.
take a look here
https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9004.htm
you needed to drop the datafile at the same time as dropping the tablespace
DROP TABLESPACE tablespace INCLUDING CONTENTS AND DATAFILES CASCADE CONTRAINTS;
if you check DBA_DATA_FILES, if your old datafile is not listed you will be ok to remove it from the OS

Oracle DB: Can one db file be shared between table space

Can one db file be shared between table space ?
I am deleting temp table space as below,
1)Get all the files in table
space :: SELECT FILE_NAME FROM DBA_TEMP_FILES WHERE TABLESPACE_NAME =
'TEMPRM_TEMP';
2)Drop all the files in the table space :: ALTER
TABLESPACE TEMPRM_TEMP DROP TEMPFILE
'/tmp/TEMPRM/create/TEMPRM/datafile/o1_mf_temprm_t_bw3yo9lv_.tmp';
3)Drop the actual table space :: DROP TABLESPACE TEMPRM_TEMP INCLUDING
CONTENTS AND DATAFILES;
Are there any harm with this procedure ?
is this the only temp tablespace in your database? if the answer is yes, then you will not be able to drop it. If anyone is connected to the tablespace, you will not be able to drop it. If this is not the only temp tablespace, and noone is connected to it, then it will work and is safe.
Ok here we go oracle doc
A tablespace in an Oracle database consists of one or more physical datafiles. A datafile can be associated with only one tablespace and only one database.

Oracle tablespace can I drop all files

I am trying drop the temp tables space it has three files
/tmp/TEMPRM/create/TEMPRM/datafile/o1_mf_temprm_t_bw3t4zkp_.tmp
+TEMPDATA/rm/datafile/temprm_tempfile_1.dbf
+TEMPDATA/rm/datafile/temprm_tempfile_2.dbf
Before dropping table space I want to delete all the file, I am able to remove the first two files last one gives the error.
SQL> SQL> ALTER TABLESPACE TEMPRM_TEMP DROP TEMPFILE '+TEMPDATA/rm/datafile/temprm_tempfile_2.dbf'
*
ERROR at line 1:
ORA-03261: the tablespace TEMPRM_TEMP has only one file
If it is not allowed to delete all the files in table space, How to clean the table space?
You cannot make a tablespace file-less. You can however drop a tablespace and it's datafiles in one statement:
DROP TABLESPACE temp_tablespace including contents and datafiles;
Make sure that you have a new temporary tablespace and make it the default before you drop the old one. Follow the below link for an example:
http://dbatricksworld.com/how-to-create-temporary-tablespace-and-drop-existing-temprary-tablespace-in-oracle-11g/
create a new temp tablespace, make this the default for the users. Once there are no connections using the old temp tablespace you should be able to drop the old temp tablespace

ORA-01652 - Query doen't work with hibernate but it works fine in SQL client

I execute a SQL query with hibernate and the application give the error:
ORA-01652: unable to extend temp segment
The TABLE SPACE has 4 GB.
The strange thing is that the query from the application yesterday was working fine, and today it doen't work.
I have not made any changes either in the database or application.
The oracle version is Oracle 11g
You are running short on space in temp tablespace , use this query t check how much space you have in your temp tablespace
SQL> select file_name,SUM(bytes)/1024/1024 "Current_size_mb", sum(maxbytes)/1024/1024 "max_size_mb" from dba_temp_files group by file_name;
FILE_NAME Current_size_mb max_size_mb
---------------------------------------------------------------------- --------------- -----------
C:\AKS\AKDB\ORADATA\RESEARCH\TEMP01.DBF 20 32767.9844
Adding a new tempfile to temp tablespace
SQL> alter tablespace temp add tempfile 'C:\AKS\AKDB\ORADATA\RESEARCH\TEMP02.DBF' size 100m autoextend on maxsize 1g;
Temporary tablespace called TEMP which is used internally by database for operations like distinct, joins,etc to fetch large amount of data.
So, after increasing the size of TEMP tablespace the issue can be resolved.
Follow this link : How to shrink temp tablespace in oracle?

Resources