Release unused space of USERS tablespace in oracle - oracle

I have lots of table with lots of records in oracle 11g. (more than 2 billions) After applying some queries and creating some indexes I am so close to insufficient disk space. Right now for executing each query ORA-01652 error for USERS tablespace appears. I cannot add more datafile to USERS tablespace anymore because of insufficient disk space. I am sure that there are lots of unused space available on this tablespace that is not usable somehow. (I deleted some tables and indexes nothing happened) My question is how can I release this space? Thank you very much.

I don't know if you can to it for an entire tablespace but for a single table the command is:
ALTER TABLE MY_TABLE ENABLE ROW MOVEMENT; -- By defaut ROW MOVEMENT is disabled when you create a table.
ALTER TABLE MY_TABLE SHRINK SPACE CASCADE;
ALTER TABLE MY_TABLE DEALLOCATE UNUSED;
Maybe you have to loop over ALL_TABLES in your schema.
Then you can gain disc space by rebuilding your indexes.
ALTER INDEX THE_INDEX REBUILD;

Related

Oracle DB: Can one db file be shared between table space

Can one db file be shared between table space ?
I am deleting temp table space as below,
1)Get all the files in table
space :: SELECT FILE_NAME FROM DBA_TEMP_FILES WHERE TABLESPACE_NAME =
'TEMPRM_TEMP';
2)Drop all the files in the table space :: ALTER
TABLESPACE TEMPRM_TEMP DROP TEMPFILE
'/tmp/TEMPRM/create/TEMPRM/datafile/o1_mf_temprm_t_bw3yo9lv_.tmp';
3)Drop the actual table space :: DROP TABLESPACE TEMPRM_TEMP INCLUDING
CONTENTS AND DATAFILES;
Are there any harm with this procedure ?
is this the only temp tablespace in your database? if the answer is yes, then you will not be able to drop it. If anyone is connected to the tablespace, you will not be able to drop it. If this is not the only temp tablespace, and noone is connected to it, then it will work and is safe.
Ok here we go oracle doc
A tablespace in an Oracle database consists of one or more physical datafiles. A datafile can be associated with only one tablespace and only one database.

ORA-01652 - Query doen't work with hibernate but it works fine in SQL client

I execute a SQL query with hibernate and the application give the error:
ORA-01652: unable to extend temp segment
The TABLE SPACE has 4 GB.
The strange thing is that the query from the application yesterday was working fine, and today it doen't work.
I have not made any changes either in the database or application.
The oracle version is Oracle 11g
You are running short on space in temp tablespace , use this query t check how much space you have in your temp tablespace
SQL> select file_name,SUM(bytes)/1024/1024 "Current_size_mb", sum(maxbytes)/1024/1024 "max_size_mb" from dba_temp_files group by file_name;
FILE_NAME Current_size_mb max_size_mb
---------------------------------------------------------------------- --------------- -----------
C:\AKS\AKDB\ORADATA\RESEARCH\TEMP01.DBF 20 32767.9844
Adding a new tempfile to temp tablespace
SQL> alter tablespace temp add tempfile 'C:\AKS\AKDB\ORADATA\RESEARCH\TEMP02.DBF' size 100m autoextend on maxsize 1g;
Temporary tablespace called TEMP which is used internally by database for operations like distinct, joins,etc to fetch large amount of data.
So, after increasing the size of TEMP tablespace the issue can be resolved.
Follow this link : How to shrink temp tablespace in oracle?

How to shrink secure file LOBs in Oracle

I noticed today that SQL command that is used to shrink LOBs in oracle does not work in 12c.
ALTER TABLE SAMPLE_TABLE MODIFY lob (LOB_COLUMN) (SHRINK SPACE)
This returns oracle error
ORA-10635: Invalid segment or tablespace type
In the oracle documentation it is mentioned that the SHRINK option is not supported for SecureFiles LOBs.
I want to know how blob compresses in secure files. Does oracle handles that internally?
Thanks
ALTER TABLE SAMPLE_TABLE MOVE LOB(LOB_COLUMN) STORE AS (TABLESPACE USERS)
Note: this is, unlike how it can be read, a move lob operation. It is a move TABLE operation, and while at it, moving a lob too.
This is why it invalidates indexes, - because it moves the whole table not just the lob. And of course it can take a very long time and it will consume 2x space during the operation, because oracle makes a copy of the data and only after it's complete it frees the old segments.
If you want to shrink LOBs using SecureFiles, use this statement:
ALTER TABLE SAMPLE_TABLE MOVE LOB(LOB_COLUMN) STORE AS (TABLESPACE USERS)
Be careful using it - this command invalidates all indexes on SAMPLE_TABLE, so you should rebuild them after you're finished with LOBs:
ALTER INDEX <index_name> REBUILD;

shrink a database in oracle 11g

I am not a database administrator by any means so I might be wrong in stating some of the things here.
In SQL Server, when we add a large amount of data in the database and then when we delete it, the size of the data files (.mdf file) or database (or whatever it is called) does not get reduced to the original size. We need to shrink it.
Do the same fundamentals work in Oracle? If yes then how should I go about shrinking an Oracle 11g database?
Full explanation from the Oracle Documentation: Reclaiming Wasted Space. For the short version:
"You can shrink space in a table, index-organized table, index,
partition, subpartition, materialized view, or materialized view log.
You do this using ALTER TABLE, ALTER INDEX, ALTER MATERIALIZED VIEW,
or ALTER MATERIALIZED VIEW LOG statement with the SHRINK SPACE
clause."
So, after running the Oracle Segment Advisor to recommend areas to shrink, something like the following will shrink space in a table named mytable.
SQL> alter table mytable enable row movement;
Table altered
SQL> alter table mytable shrink space;
Table altered
I have a similar case for a table size 28 Gb, when I deleted data from it, I saw no change occurred.
after I created another table from this table and dropped the first one, the size shrunk by 10 Gb to be 18Gb.
CREATE TABLE NEW_TBL AS SELECT * FROM OLD_TBL

Oracle Database: How can I alter a partitioned table to a new table space for not only the partitions but also the table itself?

How can I alter a partitioned table (in Oracle 10g Database) to a new table space for not only the partitions but also the table itself? Which I mean is, I can do following without issues,
--sql
alter table abc move partition abc01 tablespace new_tablespace;
alter table abc move partition abc02 tablespace new_tablespace;
alter table abc move partition abc03 tablespace new_tablespace;
but somehow the table's definition is still associating with the old table space, and and I have moved all tables data off the old table space. If I query the dba_segment for the old table space, there is nothing there. My question is, may I drop the old table space, even no data in the data files in the old table space, but somehow those partitioned tables definitions still associating with the old table space?
Each partition must be moved, as you've discovered. If you want new partitions to be created in a different tablespace without specifying that new tablespace, you'd have to use the following:
alter table abc modify default attributes tablespace new_tablespace;

Resources