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
Related
We are facing some issue with Oracle temp space. While inserting the data into table, it's quickly filling up and failing with unable to extend temp segment error.
Is there any way to overcome this scenario without adding extra temp file?
To get the total allocated space, used space, and available free space in your tablespaces you can use the following query:
-- Available space, by tablespace
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);
There really isn't a way to "control" your use of temp space. The database will do what it needs to do. But inserting 3.5 million rows at one go is a lot of data. I suggest you restructure your population procedure to commit intermittently.
Best of luck.
Solution for ORA-1652: unable to extend temp segment when doing insert clob
I need to check the newest entries and the size of it in the whole tablespace. Te used db is oracle 10g.
I'm facing the problem, that the data is growing very fast. I need to monitor. How can I do that?
the below query will give you information about tablespaces
select * from user_tablespaces
or this one mentioned by devagree100
select * from dba_data_files
and try this I got it from this site hope it might help
select round((sum(bytes)/1048576/1024),2)
from V$datafile;
select round((sum(bytes)/1048576/1024),2)
from V$tempfile;
Take the sum of this two values which will be your total database size. Record this value daily/weekly/monthly basis and compare the difference.
and if you want the size of a table check the below:
SELECT owner,
segment_name,
segment_type,
tablespace_name,
bytes/1048576 MB,
initial_extent,
next_extent,
extents,
pct_increase
FROM
DBA_SEGMENTS
WHERE
OWNER = 'table owner' AND
SEGMENT_NAME = 'table name' AND
SEGMENT_TYPE = 'TABLE'
i would look in dba_segments to get a view on the size of each object
you can also look at the size of your data files using dba_data_files
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/
I just have materialized view (small no of rows) in my oracle database and nothing but my database is compalining :
Error report:
SQL Error: ORA-12953: The request exceeds the maximum allowed database size of 11 GB
select sum(size_in_mb) from
(
SELECT owner,
segment_name,
segment_type,
sum(bytes)/1024/1024 size_in_mb
FROM dba_segments
WHERE owner NOT IN ('SYS','SYSTEM')
GROUP BY owner,
segment_name,
segment_type
ORDER BY SUM(bytes)/1024/1024
);
How do I find how much space which is using in oracle?
I assume from the error that you are using the express edition of the database.
SELECT owner,
segment_name,
segment_type,
sum(bytes)/1024/1024 size_in_mb
FROM dba_segments
WHERE owner NOT IN ('SYS','SYSTEM')
GROUP BY owner,
segment_name,
segment_type
ORDER BY SUM(bytes)/1024/1024
will show you the size of the objects owned by users other than SYS and SYSTEM ordered by their size in MB.
There are several DBA views, which look at several different aspects of "space":
* dba_free_space
* dba_data_files
* dba_tablespaces
Here are several simple - and useful - scripts:
http://www.dba-oracle.com/t_free_space_script.htm
I would definitely look at these scripts:
http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:285415955510