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.
Related
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.
What is the actual indicator of a full tablespace? The physical file size(allocated) or the used space ?
We have only one schema using DATA01 as the main tablespace in database.
Refer sql below:
Select Bytes/1024/1024/1024,Tablespace_Name,File_Name From Dba_Data_Files;
or
Select df.tablespace_name Tablespace,
totalusedspace Used_MB,
(df.totalspace - tu.totalusedspace) Free_MB,
Df.Totalspace Total_Mb,
round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace)) Pct_Free
from
(select tablespace_name,
round(sum(bytes) / 1048576) TotalSpace
from dba_data_files
Group By Tablespace_Name) Df,
(select round(sum(bytes)/(1024*1024)) totalusedspace, tablespace_name from dba_segments
group by tablespace_name) tu
where df.tablespace_name = tu.tablespace_name;
The first sql give following result:
SQL> Select Bytes/1024/1024/1024,Tablespace_Name,File_Name From Dba_Data_Files;
BYTES/1024/1024/1024 TABLESPACE_NAME
-------------------- ------------------------------
FILE_NAME
------------------------------------------------------------------------------------------------------------------------
.004882813 USERS
+DATA/xxx/datafile/users.289.863434089
1.43066406 UNDOTBS1
+DATA/xxx/datafile/undotbs1.288.863434089
5 SYSAUX
+DATA/xxx/datafile/sysaux.287.863434089
5 SYSTEM
+DATA/xxx/datafile/system.286.863434087
.537109375 UNDOTBS2
+DATA/xxx/datafile/undotbs2.294.863434493
31.9999847 DATA01
+DATA/xxx/datafile/data01a.dbf
31.9999847 DATA01
+DATA/xxx/datafile/data01b.dbf
31.9999847 DATA01
+DATA/xxx/datafile/data01c.dbf
.09765625 DATA02
+DATA/xxx/datafile/data02a.dbf
6.4831543 INDEX02
+DATA/xxx/datafile/index02a.dbf
31.9414063 DATA01
+DATA/xxx/datafile/data01d.dbf
The second sql give following result:
TABLESPACE USED_MB FREE_MB TOTAL_MB PCT_FREE
------------------------------ ---------- ---------- ---------- ----------
UNDOTBS1 27 1438 1465 98
SYSAUX 2211 2909 5120 57
SYSTEM 2579 2541 5120 50
DATA01 86363 44649 131012 34
UNDOTBS2 17 533 550 97
INDEX02 3103 3536 6639 53
As shown, the four datafiles data01a/data01b/data01c/data01d is having size nearly 32G, but why the result of second sql showing there are still 34% free space for tablespace DATA01?
Also, it is much more strange when DBA send the screenshot below from db console:
Datafile Name| Usage | Size | Used | Free |
data01d.dbf| 0% | 31.96 Gb | 47Mb| 31.9Gb
Questions:
As captioned, which statement should be the main reference for full table space? To check the physical files size or the usage?
Why it is showing 0% usage in screenshot for data01d.dbf but the actual physical file size is about 31.94G ?
What is causing the dbf file size expanded to size 31.96Gb ?
Thank you very much for any comments/advice, appreciated that.
A tablespace is simply an amount of space pre-allocated on the disk. It's the database that manages the space usage in the tablespace, so I would tend to go with what the database reports - ie. your 2nd query.
So, to answer your questions:
I'd go with your second query.
Probably because most of the space in that particular file hadn't been used yet, but I would expect that most of the space in the other 3 files has been used.
The apparent difference in size is probably due to rounding issues.
Expanded datafile sizes and actual database usage are two different things. A datafile could be expanded 100% (in your case to 32GB ) but not actually have any meaningful data in that file (but it still takes up all that space on your drive). For example the datafile expanded but later the data was deleted. The datafile itself would not shrink. It stays expanded.
You likely have set your database files to expand up to 32GB each before they move on to fill up the next available file. Check your settings in Oracle. There is a balancing act when it comes to datafile sizes. It might be better to chop up your datafiles to be in smaller chunks for performance, corruption protection, faster backups and restores. Check out:
https://docs.oracle.com/cd/B28359_01/server.111/b28310/dfiles003.htm#ADMIN11423
I have an Oracle XE database with several tablespaces. One of these is used to store image data, and this tablespace has grown to a huge size. We decided that we didn't need to the images any more so deleted them all.
This has freed up a lot of space but the tablespace size is still huge. How can I reduce it back to the size of the data that's actually in it?
This is a bit tricky, you would find DATAFILE RESIZE as the most common answer. However, you need to take care of few things as mentioned by Jonathan Lewis to avoid ORA-03297: file contains used data beyond requested RESIZE value while resizing the datafile.
You need to first find the free space of the tablespace to make sure how much you could reclaim.
The following script by Tim Hall is handy:
SET PAGESIZE 140
COLUMN used_pct FORMAT A11
SELECT tablespace_name,
size_mb,
free_mb,
max_size_mb,
max_free_mb,
TRUNC((max_free_mb/max_size_mb) * 100) AS free_pct,
RPAD(' '|| RPAD('X',ROUND((max_size_mb-max_free_mb)/max_size_mb*10,0), 'X'),11,'-') AS used_pct
FROM (
SELECT a.tablespace_name,
b.size_mb,
a.free_mb,
b.max_size_mb,
a.free_mb + (b.max_size_mb - b.size_mb) AS max_free_mb
FROM (SELECT tablespace_name,
TRUNC(SUM(bytes)/1024/1024) AS free_mb
FROM dba_free_space
GROUP BY tablespace_name) a,
(SELECT tablespace_name,
TRUNC(SUM(bytes)/1024/1024) AS size_mb,
TRUNC(SUM(GREATEST(bytes,maxbytes))/1024/1024) AS max_size_mb
FROM dba_data_files
GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name
)
ORDER BY tablespace_name;
All that remains now is to resize the data files.
ALTER DATABASE DATAFILE '/directory/datafile.dbf' RESIZE value;
I would do a full database export, drop the tablespace, create a new tablespace with a smaller size and import back into it
On my development environment I have Oracle 10G XE installation.
I often run scripts which contains a lot of Stored Procedure definitions.
It may happen that I submit CREATE OR REPLACE PROCEDURE xxxxxxxxxxxx for hundreds of Stored Procedures many times a day.
Can this cause a rapid increase of memory allocation of the tablespace keeping the usage low?
The problem is that once in a while Oracle will refuse to compile new Stored Procedures issuing a "ORA-12952: The request exceeds the maximum allowed database size of 4 GB"
I have to issue a compact storage command (through the Oracle Web interface) to free up some space in order to keep redefining my stored procedures.
I have the following:
TABLESPACE_NAME TOTAL_BYTES USED_BYTES FREE_BYTES
------------------------------ ----------- ---------- ----------
SYSAUX 461373440 461307904
USERS 4414504960 32702464 4386127872
SYSTEM 356515840 355991552 458752
UNDO 524288000 10354688 513867776
As you can see the USERS tablespace has 4GB of allocated memory, but the usage is under 20MBs.
Is there any typical reason for this behavior (high allocation/low usage)?
Can I do something to avoid this?
This is the script I used for getting the statistics:
SELECT * FROM
(SELECT tablespace_name FROM dba_tablespaces)
LEFT OUTER JOIN
(SELECT tablespace_name, SUM(bytes) AS total_bytes
FROM dba_data_files
GROUP BY tablespace_name)
USING (tablespace_name)
LEFT OUTER JOIN
(SELECT tablespace_name, sum(bytes) AS used_bytes
from dba_segments
GROUP BY tablespace_name)
USING (tablespace_name)
LEFT OUTER JOIN
(SELECT tablespace_name, SUM(bytes) AS free_bytes
FROM dba_free_space
GROUP BY tablespace_name)
USING (tablespace_name);
you do not have to worry about the tablespace usage. Most of the storage is consumed by table data not by procedure, function, triggers or packages. Monitor tablespace usage as your table data grows.
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/