Best way to shrink database of oracle - oracle

Need help to shrink database of oracle just like MSSQL. I am not so familiar with oracle database.

To shrink the database, you can use ALTER TABLE, ALTER INDEX, ALTER MATERIALIZED VIEW, or ALTER MATERIALIZED VIEW LOG statement with the SHRINK SPACE clause.
SQL> alter table testTable enable row movement;
Table altered
SQL> alter table testTable shrink space;
Table altered

Related

ORACLE Database - Why SYS User can drop tables but not columns?

I am learning PLsql with Oracle 19c. I was wondering - why sys user can drop tables but not specific columns within a table? I found this workaround, where you create a copy of the table for a specific SCHEMA, drop the column in this newly created table, drop the original table, and finally create another copy of the (copied)-table without SCHEMA/USER ROLE.
Is there another, let's say a smoother way, to accomplish this? Or is there any specific reason Oracle implemented it this way?
Thanks.
SQL> SHOW USER;
USER is "SYS"
________________________________________
SQL> ALTER TABLE employees DROP (gender);
ALTER TABLE employees DROP (gender)
*
ERROR at line 1:
ORA-12988: cannot drop column from table owned by SYS
_______________________________________
SQL> DROP TABLE employees;
Table dropped.
"To maintain the integrity of the data dictionary, tables in the SYS schema are manipulated only by the database. They should never be modified by any user or database administrator. You must not create any tables in the SYS schema."
https://docs.oracle.com/database/121/ADMQS/GUID-CF1CD853-AF15-41EC-BC80-61918C73FDB5.htm#ADMQS12003
Try to put in this order:
ALTER TABLE table_name DROP COLUMN column_name;
If the table has data it doesn't work.

Oracle 12c - drop table and all associated partitions

I created table t1 in Oracle 12c.
Table has data and it is partitioned on list partition and also has subpartitions.
Now I want to delete whole table and all associated partitions (and subpartitions).
Is this the right command to delete all?
DROP TABLE t1 PURGE;
The syntax is right but not preferable,
just drop without purge so that whenever you need you could have it back, if your flashback option is enabled. If your database's flashback option is in charge, you could issue this command (provided you don't use purge):
SQL> DROP TABLE T1;
SQL> FLASHBACK TABLE T1 TO BEFORE DROP RENAME TO T1_ver_2;
When you run DROP then the table is removed entirely from database, i.e. the table does not exist anymore.
If you just want to remove all data from that table run
truncate table T1 drop storage;
You can also truncate single (sub-)partition if required.

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: Recreate database view after modifying varchar column size

I've made some changes to columns in a database table (increasing the size of varchar), however I need to have the view of the table refreshed to pick up this change. In SQL server 2005 I would use the script to -> alter to recreate the script for the view. I'm trying to figure out what the Oracle SQL command would be to rebuild the view to display the change of the column?
Unless your view is explicitly restricting the size of the column, it will pick up the change automatically. It may have been invalidated by the table change but would be automatically recompiled when first used; or can be manually recompiled with alter view <view name> compile.
If you do so:
create table sample_table(text varchar2(10));
insert into sample_table (text) values('text...');
create view sample_view as select * from sample_table;
select * from sample_view;
alter table sample_table modify text varchar2(200);
You do not do anything to promote this change in view in Oracle database.
Or you can use "ALTER VIEW sample_view COMPILE" (how wrote #AlexPole or #devio). Oracle do this automatically when you firstly use select on sample_view after alter table.
Try
ALTER VIEW MyView COMPILE;

Flashback Table in Oracle 10g

How to use the Flashback Table feature in Oracle 10g. I want to know all the steps involved in detail.
This article will give you a good start: Flashback Table
e.g. if you accidentally dop a table, simply use this command:
FLASHBACK TABLE mytable TO BEFORE DROP;
if you want to revert the contents of a table to an earlier time:
FLASHBACK TABLE mytable TO SCN 2202666520;
or
FLASHBACK TABLE mytable TO TIMESTAMP
TO_TIMESTAMP(29-JUN-2009 10:30', 'DD-MON-YYYY HH24:MI');
Documentation: Flashback Technology: Recovering from Logical Corruptions

Resources