Cannot Create Tablespace - sql

I am using Oracle Database 12c.
I am trying to create a tablespace, but whenever I execute the following command, I run into an error:
create tablespace ts_something
datafile 'C:\test.dbf'
size 32m autoextend on;
The error I get is as follows:
ORA-01119: error in creating database file 'C:\test.dbf'
ORA-27040: file create error, unable to create file
OSD-04002: unable to open file
O/S-Error: (OS 5) Access is denied.
What can I do so that I may successfully create this tablespace?

If you (and apparently, you have) already created a database, locate current database files and specify the same directory. Something like this for my XE:
C:\oraclexe\app\oracle\oradata\XE

You must have the CREATE TABLESPACE system privilege.
i.e. to create a tablespace, you must have the SYSDBA system privilege.
Before you can create a tablespace, you must create a database to contain it, and the database must be open.

Related

Oracle: "no privileges" error when creating table with SEGMENT CREATION IMMEDIATE, success with DEFERRED - why?

I am recreating the schema of a database (without its data) on a local instance of Oracle 21c XE instance, using the DDL scripts exported with SQL Developer. The CREATE TABLE statements include the option SEGMENT CREATION IMMEDIATE. When attempting to run them, I get an error: SQL Error [1950] [42000]: ORA-01950: no privileges on tablespace 'TABLESPACENAME'. If I change from SEGMENT CREATION IMMEDIATE to SEGMENT CREATION DEFERRED, the statement succeeds. Why is this happening? The user has supposedly been granted the necessary privileges. I have already ran the command GRANT RESOURCE TO superuser; on the XEPDB1 instance.
Because with deferred segment creation, not storage is allocated in the tablespace when the table is created, only when the first data is inserted.
From the documentation:
By default, the database uses deferred segment creation to update only database metadata when creating tables, indexes, and partitions.
When a user inserts the first row into a table or partition, the database creates segments for the table or partition, its LOB columns, and its indexes. Deferred segment creation avoids using database resources unnecessarily. For example, installation of an application can create thousands of objects, consuming significant disk space. Many of these objects may never be used.
So with the successful table creation, you will get the same error when you try to insert data, as seen in this db<>fiddle:
insert into t42 (id) values (1);
ORA-01950: no privileges on tablespace 'SYSTEM'
(using SYSTEM just to demonstrate; don't create objects in there...)
You said: "The user has supposedly been granted the necessary privileges."
This isn't about privileges, it's about having a quota allocated in the tablespace(s). You haven't shown the full create statements so we don't know if you included storage clauses to specify the tablespaces to use, or if you're just using the owner's default tablespace.
From the documentation again:
Grant to users who will be creating tables, clusters, materialized views, indexes, and other objects the privilege to create the object and a quota (space allowance or limit) in the tablespace intended to hold the object segment.
and
By default, a user has no quota on any tablespace in the database. If the user has the privilege to create a schema object, then you must assign a quota to allow the user to create objects.
So in addition to granting privileges you will need to assign a quota, with something like:
alter user USERNAME quota 1M on TABLESPACENAME
providing the owner name, tablespace name, and an appropriate limit on the amount of space they are expected to consume, or UNLIMITED if that is appropriate - probably only if the tablespace has been created specifically for that user's objects.
If the user will create objects in more than one tablespace then they will need to have a quota assigned in each one.
Read more

Create a database in sql*plus (sql command line)

I've used mysql shell for creating database (create database testdb), why can't i make a database in sql*plus command line. I also want to see the lists of database but i can't find queries anywhere. Please guide
SQL> create database testdb;
create database testdb
*
ERROR at line 1:
ORA-01501: CREATE DATABASE failed
ORA-01100: database already mounted
SQL>

Why am I getting ORA-02180, if my CREATE TABLESPACE command syntax is correct?

I am trying to create a new temporary tablespace for testing purposes (the code to be tested is actually designed to work with an external Oracle database, all the important tables sharing the same tablespace named `sbrdwh').
To test the code, I have to create my own db with the same schema and the same tablespace, but when it comes to the latter, ORA-02180 is thrown.
My command looks like this:
CREATE TEMPORARY TABLESPACE sbrdwh FILE '/tmp/sbrdwh.dbf' SIZE 10M;
What am I doing wrongly?
The user who issues this command has privileges to create tablespaces and unlimited tablespace quota.
CREATE TEMPORARY TABLESPACE sbrdwh TEMPFILE '/tmp/sbrdwh.dbf' SIZE 10M;
didn't work also.
I think the correct keyword is DATAFILE or TEMPFILE, not FILE:
CREATE TEMPORARY TABLESPACE sbrdwh TEMPFILE '/tmp/sbrdwh.dbf' SIZE 10M;

SQL Temp Tablespace is Empty

Does anyone know why I'm getting this error?
ORA-25153: Temporary Tablespace is Empty
I'm doing a simple SELECT OWNER FROM DBA_TABLES; query and it displays the data properly but when I try to narrow the OWNER columns down then it gives me this error.
SELECT OWNER
FROM DBA_TABLES
WHERE OWNER = 'NAME';
your problem is described perfectly at the following post, but if you don't have DBA rights or knowledge you won't succeed to overcome this error and I strongly suggest you to approach your DBA.
http://www.mydigitallife.info/ora-25153-temporary-tablespace-is-empty-error-in-oracle/
The cause for the ORA-25153 error is because attempt was made to use
space in a temporary tablespace with no files (no datafiles defined).
To solve the problem, the solution is just by adding files (datafiles)
to the TEMP tablespace by using ADD TEMPFILE command, or by using “Add
Datafiles” in Oracle Enterprise Manager.

Deleted some Oracle DBF files by mistake - how can I tell Oracle XE to forget about them?

So I accidentally deleted some DBF files (only ones specific to my tablespaces), fortunately I was only just about to start loading data in so have lost nothing, except now can't re-create the tablespaces.
If I run:
select name from v$datafile;
The results include the DBF files that I deleted.
I attempted to run a command I found on the internet, to delete the DBF files that Oracle thinks are relevant:
alter database datafile '<A_DBF_file_that_no_longer_exists>' offline drop;
And the result is:
alter database datafile succeeded
However the datafile deleted is still returned when I run the select statement.
When I try to just create new tablespaces, I get the error:
SQL Error: ORA-01543: tablespace 'my_tablespace_name' already exists
01543. 00000 - "tablespace '%s' already exists"
*Cause: Tried to create a tablespace which already exists
*Action: Use a different name for the new tablespace
Drop the affected tablespace, too. Droping the datafile will not automagically drop the tablespace.
DROP TABLESPACE mytablespace
INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS;
Try
DROP TABLESPACE <tablespace name> INCLUDING CONTENTS;
How to drop a datafile from a tablespace could be interesting for more information:
NOTE: The ALTER DATABASE DATAFILE <datafile name> OFFLINE DROP command, is not meant to allow you to remove a datafile. What the command really means is that you are offlining the datafile with the intention of dropping the tablespace.