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

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!)

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-02199: missing DATAFILE/TEMPFILE clause

I exported a database and it created a sql file for me with create and insert but I get an error saying ORA-02199: missing DATAFILE/TEMPFILE clause
in sql plus I run the sql script and get a bunch of ORA-00942: table or view does not exist Then i noticed when it creates a table it has TABLESPACE "LOCALDEV" ; So I enter CREATE tablespace LOCALDEV
Prior to all that I enter create user localdev identified by localdev;
and
grant ALTER SESSION, CREATE SESSION, CREATE DATABASE LINK, CREATE MATERIALIZED VIEW, CREATE PROCEDURE, CREATE PUBLIC SYNONYM, CREATE ROLE,CREATE SEQUENCE, CREATE SYNONYM, CREATE TABLE, CREATE TRIGGER, CREATE TYPE, CREATE VIEW, UNLIMITED TABLESPACE to localdev;
SQL> create tablespace localdev datafile '/u01/app/localdev.dbf'
size 100m;
ERROR at line 1:
ORA-01119: error in creating database file '/u01/app/localdev.dbf'
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 13: Permission denied
Additional information
: 1
I get no error until I run the sql script. If I had a BDA to ask I would but do not. Any advice will be greatly appreciated.
I exported a database and it created a sql file for me with create and
insert but I get an error saying ORA-02199: missing DATAFILE/TEMPFILE
clause (bla bla bla)
In my opinion, the very first step you did was wrong. If you wanted to export the "database" (I presume it is, actually, a "schema" (i.e. "user")), then you should have done that. Oracle offers Data Pump utility, export and import.
If you performed export, you'd take the DMP file with you and import it into another database using import data pump with the REMAP_TABLLESPACE parameter which accepts two values: the old, "source" tablespace and the new, "target" tablespace, separated by colon. For example:
impdp scott/tiger#new_database REMAP_TABLESPACE=localdev:users DIRECTORY=dump_dir DUMPFILE=scott.dmp
Alternatively, as you currently have a textual file that contains CREATE & INSERT statements, why didn't you open it in any text editor and replaced the old tablespace name (localdev) with a tablespace name used in your new database (that would be "users" in my IMPDP example)?
It takes a few seconds, you run it, everything gets created and you don't have to reinvent the wheel by doing everything you did after the first sentence (that would be bla bla part).

error encountered when processing the current DDL statement in pluggable database ORAPDB1: the tablespace 'INTERVENTION_TBS' does no exist

I am using oracle 12c and I'm having a little trouble trying to attribute tablespace to a user.
Here is the error I got when processing the current DDL statement in pluggable database ORAPDB1:
the tablespace 'INTERVENTION_TBS' does no exist
Note that the tablespace was created successfully. So could someone suggest a solution please?
For more details I used this syntax query
CREATE USER c##DBAINTERVENTION
Identified by interventiondb
Default Tablespace INTERVENTION_TBS
Temporary Tablespace INTERVENTION_TempTBS;
run the following statements:
alter session set "_ORACLE_SCRIPT"=TRUE;
ALTER USER [username] IDENTIFIED BY [password];
You are trying to create a common user which will have access to all the PDBs in a CDB. As the user has access to all PDBs it can also create an object on those PDBs hence we need tablespace to create the objects. This is the reason why you need to have the tablespace specified in the CREATE USER command on all PDBs.
Please verify that you the INTERVENTION_TBS tablespace exists on all PDBs using the following query.
select cp.pdb_name
from cdb_pdbs cp join v$tablespace tb on(cp.con_id=tb.con_id)
where tb.name='INTERVENTION_TBS';
This query list all the PDBs which has the tablespace. If this tablespace doesn't exist on one of your PDBs then create one.

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 execute several ddl words with batch processing

When I deploy my asp.net application,I have to create some tablesapces/users,I use the pqsql,however I want to know is there any way I can create them with batch processing?
For example,I can execute this ddl:
create tablespace TSA.....
Then I can execute:
create user a ... default tablespace TSA...
But when I execute them at the same time:
create tablespace TSA.....
create user a ... default tablespace TSA...
I will get an error.
ANy way?
update
Error is something like this:
ORA-02180: invalid CREATE TABLESPACE words
BTW,I run the sql batches in the sql window of the pl/sql developer.
Now,I just want to know if there is any way I can run a whole ddl sql file?
Suppose this is the content of the init.sql:
create smallfile tablespace "DEV" datafile 'f:\app\administrator\oradata\orcl\dev01.dbf' size 100m autoextend on next 10m maxsize unlimited logging extent management local segment space management auto default nocompress
-- Create the user
create user dev_sa
identified by "000000"
default tablespace DEV
temporary tablespace TEMP;
-- Grant/Revoke role privileges
grant connect to dev_sa;
grant dba to dev_sa;
--create another tablespace
--.....
How to execute it in the batch process model?
If you have the two statements in a file you're running from SQL*Plus, you need to separate the statements with the / character, which also causes each to be executed
create tablespace TSA ...
/
create user a ... default tablespace TSA
/
(That's quite a big 'if', of course as per #APC's comment; but is something that's come up before. As has different ways of running things in SQL Developer, among other things. But really no more than a guess from the minimal info given...)
You have a semi-colon ; missing off the end of your first CREATE TABLE

Resources