Oracle tablespace can I drop all files - oracle

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

Related

Recovering an Oracle tablespace (APEX) from file system backups of database tablespace files

I'm trying to recover the applications of an Oracle APEX workspace deleted accidentally. The database is 12c and APEX 18.1
What would be the best way to go about it, if the only backup available is an OS level backup of the oradata folder (with all Tablespace files) ?. My APEX schema lives on its own tablespace. Can I simply copy over last night's copy of the APEX table space file over the current one to restore ?
There are no RMAN backups, and the database is installed with all default options, no archive log and no flashback. I also don't have any dump produced with expdp.
I've already tried to use the dbms_flashback package to go back a few hours but to no avail, as I get an error about rollback segment too small. The earliest I can make it work, is already at a state after the desired recovery point.
Clarification
I am assuming you only lost the APEX tablespace but your database is currently functioning. If this is the case, and assuming your APEX tablespace does not span multiple datafiles, you can attempt to swap out the datafile. Please force a backup in rman before trying any of this.
There are a few different options here. All you really need are the following
Datafile
Control file
Archive / redologs (if you want to move forward or backward in time)
I'm going to outline two options because I don't have all the pertinent information. The first option attempts to actually restore the datafiles through rman, the second one simply swaps it out. The first is obviously preferential but may not be achievable.
RMAN Restore
First set the following parameter in your init.ora file
_allow_resetlogs_corruption=TRUE
Move your entire oradata backup directory to /tmp/oradata. Locate then location of your dbf and ctl files in that directory.
Then run rman target / from bash terminal. In rman run the following.
RESTORE CONTROLFILE FROM '/tmp/oradata/your_ctrl_file_dir'
ALTER TABLESPACE apex OFFLINE IMMEDIATE';
SET NEWNAME FOR DATAFILE '/tmp/oradata/apex01.dbf' TO
RESTORE TABLESPACE apex;
SWITCH DATAFILE ALL;
RECOVER TABLESPACE apex;
Swap out Datafile
First find the location of your datafiles. You can find them by running the following in sqlplus / as sysdba or whatever client you use
spool '/tmp/spool.out'
select value from v$parameter where name = 'db_create_file_dest';
select tablespace name from dba_data_files;
View the spool.out file and
Verify the location of your datafiles
See if the datafile still is associated with that tablespace.
If the tablespace is still there run
select file_name, status from dba_data_files WHERE tablespace name = < name >
You want your your datafile to be available. Then you want to set the tablespace to read only and take it offline
alter tablespace < name > read only;
alter tablespace < name > offline;
Now copy your dbf file the directory returned from querying db_create_file_dest value. Don't overwrite the old one, then run.
alter tablespace < name > rename datafile '/u03/waterver/oradata/yourold.dbf' to '/u03/waterver/oradata/yournew.dbf'
This updates your controlfile to point to the new datafile.
You can then bring your tablespace back online and back in read write mode. You may also want to verify the status of the tablespace status, the name of the datafile associated with that tablespace, etc.

ORA-01900: LOGFILE keyword expected when trying to drop tablespace

SQL> alter database drop tablespace XXX including contents and datafiles;
alter database drop tablespace XXX including contents and datafiles
*
ERROR at line 1:
ORA-01900: LOGFILE keyword expected
Note : I do not have datafile regarding this tablespace I have deleted it manually.
Please advice me and also if any article regarding backup tablespaces please share
You seem to be mixing up syntax from different commands. drop tablespace is a standalone statement:
The alter database statement is separate; it has a drop logfile clause, but not drop tablespace. The parser is seeing the drop ... in your statement and is expecting the next word to therefore be logfile - and since it isn't, it generates the error you see.
So you only need to do:
drop tablespace XXX including contents and datafiles;
(assuming you're really sure you do want to get rid of it permenantly, of course!)

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.

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

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.

Resources