ORA-00959: tablespace 'EXAMPLE' does not exist in command prompt - oracle

SQL> create user alois identified by alois
2 default tablespace example password expire;
create user alois identified by alois
*
ERROR at line 1:
ORA-00959: tablespace 'EXAMPLE' does not exist
What should I do next step?
below next step like this:
create user alois identified by alois
default tablespace example password expire;
create user afra identified by oracle
default tablespace example quota unlimited on example;
create user anja identified by oracle;

The tablespace 'EXAMPLE' does not exist.
It is possible to change the user creation command and use the existing tablespace.
The USERS tablespace is almost always created.
create user alois identified by alois
default tablespace USERS password expire;
create user afra identified by oracle
default tablespace USERS quota unlimited on example;
create user anja identified by oracle;
Check Tablespace
select FILE_NAME,FILE_ID, TABLESPACE_NAME from dba_data_files
/u01/oradata/DEV/system01.dbf 1 SYSTEM
/u01/oradata/DEV/sysaux01.dbf 3 SYSAUX
/u01/oradata/DEV/undotbs01.dbf 4 UNDOTBS1
/u01/oradata/DEV/users01.dbf 7 USERS
/u01/oradata/DEV/users_ind01.dbf 5 USERS_IND
select a.tablespace_name ,
round(a.used_space*8192/(1024*1024*1024),2) as USED_GB,
round(a.tablespace_size*8192/(1024*1024*1024),2) as MAX_SIZE_GB,
round(a.used_percent ,2) as USED_PERCENT
from dba_tablespace_usage_metrics a
TABLESPACE_NAME USED_GB MAX_SIZE_GB USED_PERCENT
-------------- ------ -------------- ---------
SYSAUX 6,9 32 21,58
SYSTEM 1,11 32 3,48
TEMP 0 32 0,01
UNDOTBS1 0,04 32 0,14
USERS 23,06 32 72,07
USERS_IND 11,04 32 34,49

Apparently the EXAMPLE tablespace doesn't exist; you need to create it before you can assign it to a user as a default. It can be created with the CREATE TABLESPACE command.
Precise syntax will depend on your storage type, datafile naming conventions, etc. See here for details: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/CREATE-TABLESPACE.html#GUID-51F07BF5-EFAF-4910-9040-C473B86A8BF9
You may need to check with your DBA and have them do this, or provide you with the name of an existing tablespace you can use instead.

Related

How to change the default tablespace of the schema in Oracle

There is a schema called Docker, in which there are tables named TABLE2, TABLE3.
Example
SELECT * FROM all_all_tables WHERE TABLE_name= 'TABLE3';
Also, the Docker schema belongs to the DEFAULT TABLESPACE SYSTEM tablespace.
select
username
, default_tablespace from dba_users WHERE USERNAME = 'DOCKER';
The following syntax is used to change the default tablespace of the schema. (TS3 tablespace already exists)
ALTER USER docker DEFAULT tablespace TS3;
Then, when I searched again, I found that the DEFAULT TABLESPACE was changed.
select
username
, default_tablespace from dba_users WHERE USERNAME = 'DOCKER';
And, of course, I thought that the tablespace in which TABLE2 and TABLE3 were designated would also have been changed to TS3, and the following statement was executed.
However, the tablespace of the table was SYSTEM, not TS3. I am curious about why it hasn't changed, and I want to know how.
SELECT * FROM all_all_tables WHERE TABLE_name= 'TABLE3';
The default tablespace is just that-- a default for when you create a segment (normally a table or an index but a segment could be a partition of a table, a materialized view, or anything else that requires space) and don't specify the tablespace. Once you create a segment and it is assigned to a particular tablespace, it will remain in that tablespace unless you move it.
Assuming you are on 12.2 or later so that online moves are an option (in other versions you'd need to remove the online keyword)
alter table table3
move online tablespace ts3;
You'd need to do that for each table. If there are also indexes in the system tablespace, you'd want to move those as well
alter index index_name
rebuild online tablespace ts3;
Depending on the number of tables and indexes involved, you may want to write a bit of dynamic SQL to generate the various alter table and alter index statements for you.

Restore tablespace USERS doesn't work. Oracle backup

I created a schema and my_table_test;
ALTER SESSION SET CURRENT_SCHEMA=c##wojtek_admin;
CREATE TABLE my_table_test
( id_test INT
);
Then I created a backup using: BACKUP TABLESPACE USERS FORMAT 'c:\FRA\users%u';
Then I dropped my_table_test and run below commands:
RMAN> RUN{
2> SQL 'ALTER TABLESPACE USERS OFFLINE';
3> RESTORE TABLESPACE USERS;
4> RECOVER TABLESPACE USERS;
5> SQL 'ALTER TABLESPACE USERS ONLINE';
6> }
Why my_table_test is dropped after I restored USERS TABLESPACE?
In a multitenant database you will have several 'USERS' tablespaces. One at the CDB level and one for each PDB.
RMAN> report schema;
Report of database schema for database with db_unique_name T101N
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 960 SYSTEM YES +DATAC4/T101N/DATAFILE/system.500.1057688607
3 620 SYSAUX NO +DATAC4/T101N/DATAFILE/sysaux.498.1057688643
4 840 UNDOTBS1 YES +DATAC4/T101N/DATAFILE/undotbs1.587.1057688657
5 310 PDB$SEED:SYSTEM NO +DATAC4/T101N/86B637B62FE07A65E053F706E80A27CA/DATAFILE/system.482.1057689319
6 380 PDB$SEED:SYSAUX NO +DATAC4/T101N/86B637B62FE07A65E053F706E80A27CA/DATAFILE/sysaux.503.1057689319
7 5 USERS NO +DATAC4/T101N/DATAFILE/users.499.1057688659
8 190 PDB$SEED:UNDOTBS1 NO +DATAC4/T101N/86B637B62FE07A65E053F706E80A27CA/DATAFILE/undotbs1.489.1057689319
9 310 PDB1:SYSTEM YES +DATAC4/T101N/B52F60948095635FE053B506330A63CA/DATAFILE/system.405.1057690077
10 390 PDB1:SYSAUX NO +DATAC4/T101N/B52F60948095635FE053B506330A63CA/DATAFILE/sysaux.501.1057690077
11 195 PDB1:UNDOTBS1 YES +DATAC4/T101N/B52F60948095635FE053B506330A63CA/DATAFILE/undotbs1.497.1057690077
12 5 PDB1:USERS NO +DATAC4/T101N/B52F60948095635FE053B506330A63CA/DATAFILE/users.566.1057690091
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 67 TEMP 32767 +DATAC4/T101N/TEMPFILE/temp.573.1057688719
2 43 PDB$SEED:TEMP 32767 +DATAC4/T101N/B52F34797E9D6750E053B506330AE7C0/TEMPFILE/temp.481.1057689337
3 43 PDB1:TEMP 32767 +DATAC4/T101N/B52F60948095635FE053B506330A63CA/TEMPFILE/temp.496.1057690079
Note! RMAN's best feature. RMAN can actually tell you what to do in different scenarios.
# data recovery advisor (DRA)
list failure all;
advise failure;
repair failure preview;
repair failure;
First, it's important to note that it looks like you're using a Multitenant Database but you've decided to put user data inside the root container, this is generally a bad idea - you should be using a Pluggable Database for pretty much everything (this will also mean you don't need to prefix your usernames with C##.
Your restore and recover statements will recover the tablespace up until now. If you want to recover it to before you dropped the tablespace then Oracle will also need to do some work on the system tablespace (for the data dictionary) - but you don't only want to restore and recover your USERS tablespace. You'd need to restore your backup somewhere else, recover it to the desired point, then take the USERS tablespace and put it back into your original database.
This is simply referred to as Tablespace Point In Time Recovery, Oracle has helpfully done all the hard scripting work for you, but you should read what's going on https://docs.oracle.com/cd/E11882_01/backup.112/e10642/rcmtspit.htm#BRADV89790
RECOVER TABLESPACE users
UNTIL ?
AUXILIARY DESTINATION '?';
(Once you've read the docs you'll see how to fill this out).
There is also the ability to do this easily at a table level, so if you want to only recover that dropped table and not revert everything else in that tablespace, you could:
RECOVER TABLE c##wojtek_admin.my_table_test
UNTIL ?
AUXILIARY DESTINATION '?' ;
See https://oracle-base.com/articles/12c/rman-table-point-in-time-recovery-12cr1 for further details.

How to solve ORA-01031 - Error When Creating New User PL/SQL

I am trying to create new user in PL/SQL. I am getting an error as follows:
User you use to create another user doesn't have required privileges.
In Oracle, such a "privileged" user is SYS. For example:
SQL> connect sys as sysdba
Enter password:
Connected.
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
SQL> create user brisime identified by blabla
2 default tablespace users
3 temporary tablespace temp
4 quota unlimited on users;
User created.
SQL>
If I try to do the same as a non-privileged user (i.e. the one that doesn't have create user privilege), it'll fail:
SQL> drop user brisime;
User dropped.
SQL> connect scott/tiger
Connected.
SQL> create user brisime identified by blabla
2 default tablespace users
3 temporary tablespace temp
4 quota unlimited on users;
create user brisime identified by blabla
*
ERROR at line 1:
ORA-01031: insufficient privileges
SQL>
But, if SYS grants create user to scott, Scott will also be able to do that:
SQL> connect sys as sysdba
Enter password:
Connected.
SQL> grant create user to scott;
Grant succeeded.
SQL> connect scott/tiger
Connected.
SQL> create user brisime identified by blabla
2 default tablespace users
3 temporary tablespace temp
4 quota unlimited on users;
User created.
SQL>
Therefore, make sure to acquire required privileges before trying to create user.
The same goes for altering the user - you need to have those privileges.

Oracle: how to check space used by a tablespace when no dba privs

I need to check space used by a tablespace but I have no dba privs. Is there a way to do this?
Unfortunately without explicit permissions to the dba_free_space or dba_segments views you are stuck with your users default tablespace:
SELECT
ts.tablespace_name,
TO_CHAR(SUM(NVL(fs.bytes,0))/1024/1024, '99,999,990.99') AS MB_FREE
FROM
user_free_space fs,
user_tablespaces ts,
user_users us
WHERE
fs.tablespace_name(+) = ts.tablespace_name
AND ts.tablespace_name(+) = us.default_tablespace
GROUP BY
ts.tablespace_name;
If you need to check the size of a tablespace for which you don't have a user with that as their default tablespace you're stuck with going back to your DBA.
Test with the system tablespace as default:
Test with an app tablespace as the default tablespace:
This schema does not have query on the dba views:
select * from dba_free_space;
ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error at Line: 13 Column: 15

Oracle TEMPORARY TABLESPACE

I want to import a database to a new tablespace.
So I;m setting up a user using CREATE USER. But how do I set up the TEMPORARY TABLESPACE if I don't know the temporary tablespace the existing database uses?
If you are creating a user and don't specify a temporary tablespace, it should get set to the default. This can be found by:
SELECT * FROM DATABASE_PROPERTIES where PROPERTY_NAME='DEFAULT_TEMP_TABLESPACE';
If you want to find other TEMPORARY tablespaces within the database you can do:
SELECT * FROM dba_tablespaces WHERE contents = 'TEMPORARY' ORDER BY tablespace_name;
SELECT temporary_tablespace
FROM dba_users
WHERE USERNAME = 'SCOTT'

Resources