One of our datafiles hit the max of 32G. So, we created a 2nd datafile in that tablespace.
However, we forgot to give a default NEXT size. So, file 1 has a NEXT of 50MB. And file 2 has a NEXT of 8k.
These are locally managed, so, I am guessing the only thing to do is create a new tablespace, and move all the objects. Or is there another solution? One question: How do I move TYPES? Do I need to drop & recreate those? Which will invalidate a ton of things.......
Any suggestions? Can I isolate the objects in just that datafile?
Thanking you.
You should always consult Oracle documentation first. What you ask for is a straightforward, single-SQL-command-involving action. The crucial piece of knowledge you missed is that you do not alter a tablespace, you alter a datafile.
Proof of concept
First, I'll just query my example tablespace for its block size, as I'll use the value for proving that my datafile was altered correctly.
SQL> select tablespace_name, block_size
SQL> from dba_tablespaces
SQL> where tablespace_name = 'EXAMPLE';
TABLESPACE_NAME BLOCK_SIZE
------------------------------ ----------
EXAMPLE 8192
OK, the tbs uses a block size of 8KB.
Now, what my example data files look like?
SQL> select file_name, file_id, tablespace_name, autoextensible, increment_by * &example_tbs_block_size_b / 1048576 as increment_by_mbytes
SQL> from dba_data_files
SQL> where tablespace_name = 'EXAMPLE';
FILE_NAME FILE_ID TABLESPACE_NAME AUTOEXTENSIBLE INCREMENT_BY_MBYTES
---------------------------------- ---------- --------------- -------------- -------------------
D:\ORA\MY_CDB\MY_PDB\EXAMPLE01.DBF 10 EXAMPLE YES 1
OK, I see just a single data file with the autoextend of 1MB.
Now alter the datafile...
SQL> alter database datafile 10 autoextend on next &target_autoextend maxsize unlimited;
Database altered
And recheck the tbs datafiles once again
SQL> select file_name, file_id, tablespace_name, autoextensible, increment_by * &example_tbs_block_size_b / 1048576 as increment_by_mbytes
SQL> from dba_data_files
SQL> where tablespace_name = 'EXAMPLE';
FILE_NAME FILE_ID TABLESPACE_NAME AUTOEXTENSIBLE INCREMENT_BY_MBYTES
---------------------------------- ---------- --------------- -------------- -------------------
D:\ORA\MY_CDB\MY_PDB\EXAMPLE01.DBF 10 EXAMPLE YES 8
And, voilá, I have an autoextend of 8MB.
Related
I got a problem with my temporary tablespace. I'm on Oracle.
I need a temporary tablespace of about 8G for an import. Problem is I don't have that much place in just one place of my server.
So I did multiple tempfiles :
CREATE TEMPORARY TABLESPACE TEMP_X0DDBA TEMPFILE
'/var/X0DNAT_temp01.dbf' SIZE 1536M,
'/var/log/audit/X0DNAT_temp02.dbf' SIZE 1740M,
'/logiciels/X0DNAT_temp03.dbf' SIZE 2662M,
'/appli/projects/X0DNAT_temp04.dbf' SIZE 1126M,
'/logiciels/oracle/diag/X0DNAT_temp05.dbf' SIZE 1228M,
'/home/oracle/X0DNAT_temp06.dbf' SIZE 1843M;
Total, I could have a temporary tablespace of 9.8G.
But I think that Oracle is fulling the different files fairly. And when 1 of the files is full it stops the execution and says that files are full :
When I check the size of temp files, I got this :
SELECT TABLESPACE_NAME, sum(BYTES)/1024/1024 FROM DBA_TEMP_FILES group by TABLESPACE_NAME;
TABLESPACE_NAME SUM(BYTES)/1024/1024
------------------------------ ---------------------------------------
TEMP_X0DDBA 10135
But when I check the size of the tablespace :
SELECT TABLESPACE_NAME, SUM(BYTES_USED)/1024/1024 from V$TEMP_SPACE_HEADER group by TABLESPACE_NAME;
TABLESPACE_NAME SUM(BYTES_USED)/1024/1024
------------------------------ ---------------------------------------
TEMP_X0DDBA 6707
So clearly the tablespace isn't taking all the space he has in files.
Do you know how to make it take all the place he has, and not fairly between files ?
Thanks.
I often reduce tablespace in our Oracle instance (11g).
Using the following script (from system user) I can know exactly the allocated space for each object in choosen tablespace (e.g. MY_TABLESPACE):
select
tablespace_name, file_id, block_id,
block_id + blocks - 1 end_block, owner,
segment_name, partition_name, segment_type
from
dba_extents
where 1=1
and tablespace_name = 'MY_TABLESPACE'
union all
select
tablespace_name, file_id, block_id,
block_id + blocks - 1 end_block,
'free' owner, 'free' segment_name,
null partition_name, null segment_type
from
dba_free_space
where 1=1
and tablespace_name = 'MY_TABLESPACE'
order by
file_id desc,
block_id desc;
Something I try the following strange thing, consecutive free block that I can't resize:
Consecutive free blocks
This means which we have 19095 free blocks (about 150 Mb) that can't resize.
To avoid the complete drop and create back of tablespace, could someone help me?
How are you trying to "resize" the tablespace?
Looks like all you need to do is run the Tablepsace level Shrink option of the Segment Advisor, which will do the shrinking for you and reclaim that space.
Easy to do from OEM if you have it - just run Segment Advisor for your tablespace.
If you need a script to do it, check the DBMS_ADVISOR package usage here:
https://docs.oracle.com/cd/B28359_01/server.111/b28310/schema003.htm
I am interested in finding certain information about the tablespaces in my database, but I am not quite sure where to begin. I was asked to find the following information:
Summarize in a report, the following:
List all tablespaces including tablespace name, owner, type and total bytes used
By tablespace, list usage statistics,free bytes and fragments
I was looking around the net and I found this:
select tablespace_name from dba_tablespaces
select tablespace_name from user_tablespaces
That's about all I have at the moment, but I don't know where to go from there.
Can someone guide me through what I should to do gather the required information?
Thanks!
I can help with these...
Name: dba_tablespaces.Tablespace_Name
Type (Permanent, Temporary, Undo): dba_tablespaces.Contents
Size: sum DBA_Data_Files.Bytes for the tablespace
Free bytes: sum DBA_Free_Space.Bytes for the tablespace
Total bytes used: Size - Free bytes
Fragments: Do you mean segments? If so, count DBA_Segments rows for
the tablespace
... but not the owner; no idea how to find that.
Here's a query to get name, type, size, used, free and segments:
WITH
ts AS (
SELECT Tablespace_Name, SUM(Bytes/1024) AS TotSize
FROM DBA_Data_Files
GROUP BY Tablespace_Name),
tx AS (SELECT Tablespace_Name, COUNT(*) AS Segments
FROM DBA_Segments
GROUP BY Tablespace_Name),
tf AS (SELECT Tablespace_Name, SUM(Bytes/1024) AS TotFree
FROM DBA_Free_Space
GROUP BY Tablespace_Name)
SELECT
Tablespace_Name,
DBA_Tablespaces.Contents,
ts.TotSize,
ts.TotSize - tf.TotFree AS TotUsed,
tf.TotFree,
tx.Segments
FROM DBA_Tablespaces
INNER JOIN ts USING (Tablespace_Name)
INNER JOIN tx USING (Tablespace_Name)
INNER JOIN tf USING (Tablespace_Name)
ORDER BY Tablespace_Name
You can use the below queries:
Query TS (TABLESPACE) information
Dba_tablespaces
SQL>SELECT TABLESPACE_NAME,EXTENT_MANAGEMENT,
2 ALLOCATION_TYPE,CONTENTS,
3 SEGMENT_SPACE_MANAGEMENT
4 FROM DBA_TABLESPACES;
TABLESPACE_NAME EXTENT_MAN ALLOCATIO CONTENTS SEGMEN
————— ———- ——— ——– ——
SYSTEM DICTIONARY USER PERMANENT MANUAL
UNDOTBS LOCAL SYSTEM UNDO MANUAL
TEMP LOCAL SYSTEM TEMPORARY MANUAL
TOOL LOCAL SYSTEM PERMANENT MANUAL
USERS LOCAL SYSTEM PERMANENT MANUAL
APP_DATA DICTIONARY USER PERMANENT MANUAL
APP_INDEX LOCAL SYSTEM PERMANENT AUTO
ii. DBA_FREE_SPACE
SQL>SELECT TABLESPACE_NAME,SUM(BYTES)FREE_SPACE
2 FROM DBA_FREE_SPACE
3 GROUP BY TABLESPACE_NAME;
TABLESPACE_NAME FREE_SPACE
————————— ———
APP_DATA 10481664
APP_INDEX 10223616
SYSTEM 88281088
UNDOTBS 208338944
USERS 24051712
iii. DBA_EXTENTS,USER_EXTENTS – shows information about the extents,extent sizes,associated segment and tablespace.
DBA_DATA_FILES – shows data files belonging to tablespaces
DBA_TEMP_FILES – shows temporary files belonging to locally managed temporary managed tablespaces.
iv.DBA_USERS
SQL>SELECT DEFAULT_TABLESPACE,TEMPORARY_TABLESPACE
2 FROM DBA_USERS
3 WHERE USERNAME = ‘HR’;
DEFAULT_TABLESPACE TEMPORARY_TABLESPACE
——————————- ——————–
EXAMPLE TEMP
Read all about oracle tablespace and oracle tablspace management here:
http://www.techienawa.com/logical-structure/oracle-tablespace/
http://www.techienawa.com/logical-structure/tablespace-oracle/
SELECT tablespace_name, sum(bytes)/1024/1024 "MB Free"
FROM dba_free_space
WHERE tablespace_name = 'USERS'
GROUP BY tablespace_name;
Hi everyone, the above query is what i use for showing the free space in user tablespace but how do i write a separate PL/SQL script to store it in separate table with tablespace name and time stamp.
Kindly help me as i need this run on job scheduler for every hour.
Thanks in advance
Assuming you've already created the table you want to store the data in, simply
CREATE OR REPLACE PROCEDURE snap_free_space
AS
BEGIN
INSERT INTO new_table( tablespace_name, free_bytes, collection_time )
SELECT tablespace_name, sum(bytes), sysdate
FROM dba_free_space
GROUP BY tablespace_name;
END;
I got the following error on Oracle: ORA-01536
What is the problem?
The online documentation includes a book with explanations and resolutions for all the error messages. Some of them are a bit cryptic but it is the place to start. Find out more.
Anyhoo, here is an illustrated solution for ORA-01536.
A DBA creates a new user:
SQL> create user fox_in_socks identified by tweetlebeetle
2 default tablespace users quota 1M on users
3 /
User created.
SQL> grant create session, create table to fox_in_socks
2 /
Grant succeeded.
SQL>
In another session our brave user creates a table...
SQL> conn fox_in_socks/tweetlebeetle
Connected.
SQL> create table t23 (col1 varchar2(4000))
2 /
Table created.
SQL>
.. and does some work....
SQL> begin
2 for i in 1..1000 loop
3 insert into t23 values (rpad('a', 4000, 'a'));
4 commit;
5 end loop;
6 end;
7 /
begin
*
ERROR at line 1:
ORA-01536: space quota exceeded for tablespace 'USERS'
ORA-06512: at line 3
SQL>
Uh-oh! So our user goes to their tame DBA and asks for more quota, which they get:
SQL> alter user fox_in_socks
2 quota 10M on users
3 /
User altered.
SQL>
Work proceeds:
SQL> begin
2 for i in 1..1000 loop
3 insert into t23 values (rpad('a', 4000, 'a'));
4 commit;
5 end loop;
6 end;
7 /
PL/SQL procedure successfully completed.
SQL>
If the user were an application owner then the DBA could have decided to give them unlimited quota (especially if they were the only user with privileges on that tablespace):
alter user fox_in_socks
quota unlimited on users
/
(in real life this situation is unlikely to be true for the USERS tablespace).
Users can check their current quota using the appropriate view:
SQL> select * from user_ts_quotas
2 /
TABLESPACE_NAME BYTES MAX_BYTES BLOCKS MAX_BLOCKS DRO
------------------------------ ---------- ---------- ---------- ---------- ---
USERS 9437184 10485760 1152 1280 NO
SQL>
ORA-01536: space quota exceeded for tablespace 'string'
Cause: The space quota for the segment owner in the tablespace has been exhausted and the operation attempted the creation of a new segment extent in the tablespace.
Action: Either drop unnecessary objects in the tablespace to reclaim space or have a privileged user increase the quota on this tablespace for the segment owner.