Table space dropped but dbf file still exist - oracle

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

Related

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

how to move undo datafile in running database without disturbing transactions?

Unfortunately one UNDO data file was misplaced in wrong location when I was adding space. I want to move that file to correct location. As it is Production database, I don't want to disturb the ongoing transactions. Can I offline that particular undo data file, while moving... will Database work normally with zero data loss?
Version Of Oracle DB: 11.2.0.4.0
can any one suggest?
During database running and in 24/7 environment, you should need to create new undo tablespace with new location of undo datafile. After creating this newer tablespace, you can switch older to newer undo tablespace online without affecting any ongoing transactions.
Following example shows how to achieve your goal. Using this trick, you can avoid data loss.
SQL>create undo tablespace undotbs2 datafile '/yournewlocation/undotbs02.dbf' size 1000m;
Now set new undo tablespace as default undo tablespace using following command as SYSDBA in SQLPLUS
SQL> alter system set undo_tablespace= undotbs2 ;
After finishing above task you can drop old undotbs tablespace from database using following command.
SQL> drop tablespace undotbs including contents;
I would consider creating the undo tablespace as a BIGFILE datafile:
CREATE BIGFILE UNDO TABLESPACE UNDOTBS02
DATAFILE '/yournewlocation/UNDOTBS02.dbf'
SIZE 100M AUTOEXTEND ON NEXT 100M
MAXSIZE 500G; --or whatever size you consider sufficient for your DB
I would also alter the system with a scope of BOTH, to make sure the change is made in both memory and spfile:
ALTER SYSTEM SET UNDO_TABLESPACE=UNDOTBS02 SCOPE=BOTH;
Then, provided all active transactions and the UNDO_RETENTION period (if any) are done, you'll be able to drop the tablespace as described by doc123.

Lucene Indexing from Oracle:ORA-01652: unable to extend temp segment

I met a problem when using Lucene to build full-text index of the data from the Oracle 11g database, with the following information:
"ora-01652 unable to extend temp segment by 128 in tablespace temp, on MDSYS.SDO_RDF_TRIPLE_S", line 608"
The total size of the dataset is about 1.5GB. After the problem occur, I followed some instructions online:
CREATE TEMPORARY TABLESPACE temp01
TEMPFILE 'D:\oracle\oradata\temp01.dbf' SIZE 2048M AUTOEXTEND ON MAXSIZE UNLIMITED;
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp01;
However, the problem is still there. The disk space is enough, though. Can anyone give me some help? Thanks in advance!
What tablespace is MDSYS.SDO_RDF_TRIPLE_S in? That's the tablespace to which space needs to be added. Also, MAXSIZE UNLIMITED doesn't really mean unlimited; on most platforms, that means 32767 MB.
Changing the default temporary tablespace for the database doesn't modify the assigned value for existing users who explicitly had a temporary tablespace set. Check the user you're connecting as, in dba_users, and if it has a different temporary tablespace do alter user <id> temporary tablespace temp01.
You could also have increased the size of the existing temporary tablespace, by increasing the size of its tempfile, setting that to autoextend, or adding an additional tempfile. However, if this is a one-off task then creating a new large tablespace for it and dropping it afterwards may not be a bad idea.

How to shrink temp tablespace in oracle?

How can we shrink temp tablespace in oracle? And why it is increasing so much like upto 25 GB since there is only one schema in the database for the application and data table space size is 2 GB and index table space size is 1 GB used.
Oh My Goodness! Look at the size of my temporary table space!
Or... how to shrink temporary tablespaces in Oracle.
Yes I ran a query to see how big my temporary tablespace is:
SQL> SELECT tablespace_name, file_name, bytes
2 FROM dba_temp_files WHERE tablespace_name like 'TEMP%';
TABLESPACE_NAME FILE_NAME BYTES
----------------- -------------------------------- --------------
TEMP /the/full/path/to/temp01.dbf 13,917,200,000
The first question you have to ask is why the temporary tablespace is so large.
You may know the answer to this off the top of your head. It may be due to a
large query that you just run with a sort that was a mistake (I have done that
more than once.) It may be due to some other exceptional circumstance. If that
is the case then all you need to do to clean up is to shrink the temporary
tablespace and move on in life.
But what if you don't know? Before you decide to shrink you may need to do some
investigation into the causes of the large tablespace. If this happens on a
regular basis then it is possible that your database just needs that much space.
The dynamic performance view
V$TEMPSEG_USAGE
can be very useful in determining the cause.
Maybe you just don't care about the cause and you just need to shrink it.
This is your third day on the job. The data in the database is only 200MiB
if data and the temporary tablespace is 13GiB - Just shrink it and move on.
If it grows again then we will look into the cause. In the mean time I am
out of space on that disk volume and I just need the space back.
Let's take a look at shrinking it. It will depend a little on what version
of Oracle you are running and how the temporary tablespace was set up.
Oracle will do it's best to keep you from making any horrendous mistakes
so we will just try the commands and if they don't work we will shrink
in a new way.
First let's try to shrink the datafile. If we can do that then we get back
the space and we can worry about why it grew tomorrow.
SQL>
SQL> alter database tempfile '/the/full/path/to/temp01.dbf' resize 256M;
alter database tempfile '/the/full/path/to/temp01.dbf' resize 256M
*
ERROR at line 1:
ORA-03297: file contains used data beyond requested RESIZE value
Depending on the error message you may want to try this with different sizes
that are smaller than the current site of the file. I have had limited
success with this. Oracle will only shrink the file if the temporary tablespace
is at the head of the file and if it is smaller than the size you
specify. Some old Oracle documentation (they corrected this) said that
you could issue the command and the error message would tell you what
size you could shrink to. By the time I started working as a DBA this was
not true. You just had to guess and re-run the command a bunch of times
and see if it worked.
Alright. That didn't work. How about this.
SQL> alter tablespace YOUR_TEMP_TABLESPACE_NAME shrink space keep 256M;
If you are in 11g (Maybee in 10g too) this is it! If it works you may want
to go back to the previous command and give it some more tries.
But what if that fails. If the temporary tablespace is the default temporary
that was set up when the database was installed then you may need to do a
lot more work. At this point I usually re-evaluate if I really need that
space back. After all disk space only costs $X.XX a GiB. Usually I don't want
to make changes like this during production hours. That means working at 2AM
AGAIN! (Not that I really object
to working at 2AM - it is just that... Well I like to sleep too. And my wife
likes to have me at home at 2AM... not roaming the downtown streets at 4AM trying
to remember where I parked my car 3 hours earlier. I have heard of that "telecommuting"
thing. I just worry that I will get half way through and then my internet connectivity
will fail - then I have to rush downtown to fix it all before folks show up in the
morning to use the database.)
Ok... Back to the serious stuff...
If the temporary tablespace you want to shrink is your default
temporary tablespace, you will have to first create a new temporary
tablespace, set it as the default temporary tablespace then drop
your old default temporary tablespace and recreate it. Afterwords
drop the second temporary table created.
SQL> CREATE TEMPORARY TABLESPACE temp2
2 TEMPFILE '/the/full/path/to/temp2_01.dbf' SIZE 5M REUSE
3 AUTOEXTEND ON NEXT 1M MAXSIZE unlimited
4 EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;
Tablespace created.
SQL> ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp2;
Database altered.
SQL> DROP TABLESPACE temp INCLUDING CONTENTS AND DATAFILES;
Tablespace dropped.
SQL> CREATE TEMPORARY TABLESPACE temp
2 TEMPFILE '/the/full/path/to/temp01.dbf' SIZE 256M REUSE
3 AUTOEXTEND ON NEXT 128M MAXSIZE unlimited
4 EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;
Tablespace created.
SQL> ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp;
Database altered.
SQL> DROP TABLESPACE temp2 INCLUDING CONTENTS AND DATAFILES;
Tablespace dropped.
Hopefully one of these things will help!
The options for managing tablespaces have got a lot better over the versions starting with 8i. This is especially true if you are using the appropriate types of file for a temporary tablespace (i.e. locally managed tempfiles).
So, it could be as simple as this command, which will shrink your tablespace to 128 meg...
alter tablespace <your_temp_ts> shrink space keep 128M;
The Oracle online documentation is pretty good. Find out more.
edit
It would appear the OP has an earlier version of the database. With earlier versions we have to resize individual datafiles. So, first of all, find the file names. One or other of these queries should do it...
select file_name from dba_data_files where tablespace_name = '<your_temp_ts>'
/
select file_name from dba_temp_files where tablespace_name = '<your_temp_ts>'
/
Then use that path in this command:
alter database datafile '/full/file/path/temp01.dbf' resize 128m
/
You should have written what version of Oracle you use. You most likely use something else than Oracle 11g, that's why you can't shrink a temp tablespace.
Alternatives:
1) alter database tempfile '[your_file]' resize 128M; which will probably fail
2) Drop and recreate the tablespace. If the temporary tablespace you want to shrink is your default temporary tablespace, you may have to first create a new temporary tablespace, set it as the default temporary tablespace then drop your old default temporary tablespace and recreate it. Afterwards drop the second temporary table created.
3) For Oracle 9i and higher you could just drop the tempfile(s) and add a new one(s)
Everything is described here in great detail.
See this link: http://databaseguide.blogspot.com/2008/06/resizing-temporary-tablespace.html
It was already linked, but maybe you missed it, so here it is again.
It will be increasing because you have a need for temporary storage space, possibly due to a cartesian product or a large sort operation.
The dynamic performance view V$TEMPSEG_USAGE will help diagnose the cause.
Temporary tablespaces are used for database sorting and joining operations and for storing global temporary tables. It may grow in size over a period of time and thus either we need to recreate temporary tablespace or shrink it to release the unused space.
Steps to shrink TEMP Tablespace
alter database datafile 'C:\ORA_SERVER\ORADATA\AXAPTA\AX_DATA.ORA' resize 40M;
If it doesn't help:
Create new tablespace
Switch to new temporary tablespace
Wait until old tablespace will not be used
Delete old tablespace
I don't bother with dropping the alternate temp in case i need to reclaim storage again in the future...
from temp group set default to stand-alone temp
wait awhile, then resize members of temp group
set default back to temp group
wait awhile, resize stand alone temp. there's no rush to do the last step

Resources