0% found this document useful (0 votes)
0 views4 pages

How To Create Tablespace

An Oracle database uses tablespaces to logically store data, which consist of datafiles that conform to the operating system. There are three types of tablespaces: permanent for user data, undo for transaction management, and temporary for intermediate data during operations. Additionally, Oracle employs redo logs to track changes made to the database, ensuring data integrity and recovery, with specific commands available for managing tablespaces and redo logs.

Uploaded by

fahadkhan213910
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views4 pages

How To Create Tablespace

An Oracle database uses tablespaces to logically store data, which consist of datafiles that conform to the operating system. There are three types of tablespaces: permanent for user data, undo for transaction management, and temporary for intermediate data during operations. Additionally, Oracle employs redo logs to track changes made to the database, ensuring data integrity and recovery, with specific commands available for managing tablespaces and redo logs.

Uploaded by

fahadkhan213910
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Tablespace

Tablespace in Oracle
An Oracle database consists of one or more logical storage units called tablespaces, which collectively
store all of the database's data. Each tablespace in an Oracle database consists of one or more files
called datafiles(.dbf), which are physical structures that conform to the operating system in which
Oracle is running.

Tablespace Types
There are three types of tablespaces:

 Permanent
Permanent tablespaces are used to store user and application data. Oracle Database uses
permanent tablespaces to store permanent data, such as system data. Each user is assigned a
default permanent tablespace.
 Undo
A database running in automatic undo management mode transparently creates and manages
undo data in the undo tablespace. Oracle Database uses undo data to roll back transactions, to
provide read consistency, to help with database recovery, and to enable features such as Oracle
Flashback Query. A database instance can have only one active undo tablespace.
 Temporary
Temporary tablespaces are used for storing temporary data, as would be created when SQL
statements perform sort operations. An Oracle database gets a temporary tablespace when the
database is created. You would create another temporary tablespace if you were creating a
temporary tablespace group. Under typical circumstances, you do not have to create additional
temporary tablespaces. If you have an extremely large database, then you might configure
additional temporary tablespaces.
The physical files that comprise a temporary tablespace are called tempfiles.
The TEMP tablespace is typically used as the default temporary tablespace for users who are not
explicitly assigned a temporary tablespace.

View the information tablespaces


SQL>SELECT * from DBA_TABLESPACES;
SQL>CREATE TABLESPACE customer DATAFILE 'd:\customer\customer.dbf' SIZE 100M;
SQL>create tablespace icm datafile 'E:\app\Arif\oradata\icmdb\icm_user.dbf' size 10m
autoextend on next 200k maxsize unlimited;
Add another data file to tablespace
SQL> Alter TABLESPACE customer
Add DATAFILE 'd:\customer\customer1.dbf'
SIZE 100M;
Increase the size of datafile
SQL>ALTER DATABASE DATAFILE 'd:\customer\customer1.dbf' RESIZE 200M;
Increase the auto size to datafile
SQL>ALTER DATABASE
DATAFILE 'd:\student\student.dbf'
autoextend on next 100k maxsize unlimited ;
Crete Table with tablespace:
SQL>create table scott.stm(stm_no number,name varchar2(20)) TABLESPACE users;
Check the free Space in Table Space
SQL>SELECT tablespace_name, bytes / 1024 / 1024 MB FROM
dba_free_space WHERE tablespace_name = 'USERS';

Rename Table Space


SQL>ALTER TABLESPACE customer RENAME TO Corvit_customer;

Calculate the free space


SQL select a.tablespace_name, sum(a.bytes)/(1024*1024) total_space_MB,
round(b.free,2) Free_space_MB, round(b.free/(sum(a.bytes)/(1024*1024))* 100,2) percent_free
from dba_data_files a,
(select tablespace_name,sum(bytes)/(1024*1024) free from dba_free_space
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name(+)
group by a.tablespace_name,b.free;
Drop Table Space
SQL>DROP TABLESPACE corvit_customer;
SQL>DROP TABLESPACE corvit_customer INCLUDING CONTENTS;
Drop the datafile from Tablespace
Note: you cannot drop the first datafile
SQL>ALTER TABLESPACE customer
DROP DATAFILE 'd:\customer\customer1.dbf';

SQL>DROP TABLESPACE Customer


INCLUDING CONTENTS AND DATAFILES
CASCADE CONSTRAINTS;
Bring Tablespace Online Or Offline
SQL>ALTER TABLESPACE Customer OFFLINE/ONLINE;
Set a Tablespace as Read-Only & Read Write Temporarily
SQL>ALTER TABLESPACE CUSTOMER READ ONLY;
SQL> ALTER TABLESPACE CUSTOMER READ write;

Oracle Redo Log


Redo Logs consist of two or more pre-allocated files that store all changes made to the database as they
occur. Every instance of an Oracle Database has associated online redo logs to protect the database in
case of an instance failure.
Whenever a transaction is committed, LGWR process writes the transaction redo records from the redo
log buffer of the SGA to a redo log file and assigns a system change number (SCN) to identify the redo
records for each committed transaction. Only when all redo records associated with a given transaction
are safely on disk in the online logs is the user process notified that the transaction has been committed.
The Oracle Database uses only one redo log file at a time to store redo records written from the redo log
buffer. The redo log file that LGWR is actively writing to is called the current redo log file. Redo log files
that are required for instance recovery are called active redo log files. Redo log files that are no longer
required for instance recovery are called inactive redo log files.
If you have enabled archiving (the database is in ARCHIVELOG mode), then the database cannot reuse or
overwrite an active online log file until one of the archiver background processes (ARCn) has archived
the file. If archiving is disabled (the database is in NOARCHIVELOG mode), then when the last redo log
file is full, LGWR continues by overwriting the first available active file.
Oracle redo Logs Terms:
 Current Redo Log File: This is the file that LGWR is currently writing.
 Active Redo Log File: Redo Log file that is required for instance recovery.
 Inactive Redo Log Files: Redo Log files that are no longer required for instance recovery.
 Log Switch: This is the point at which the LGWR stops writing to a file and starts writing to
another.
To view the information of Redo Log File
SQL> select group#, member from v$logfile order by group#, member;
SQL>SELECT * FROM V$LOG;
SQL>select * from V$log_history;
SQL SELECT a.GROUP#, a.THREAD#, a.SEQUENCE#,
a.ARCHIVED, a.STATUS, b.MEMBER AS REDOLOG_FILE_NAME,
(a.BYTES/1024/1024) AS SIZE_MB FROM v$log a,v$logfile b
where a.Group#=b.Group#
ORDER BY a.GROUP#;
Adding Another Log File to an existing Group:
SQL>Alter database add logfile member 'C:\APP\ARIF\ORADATA\NEWDB\REDO01_02.LOG' to group 1;
Adding Redo Log Groups:
SQL>Alter database add logfile group 4 'C:\APP\ARIF\ORADATA\NEWDB\REDO01_02_g4.LOG' size 10m;
Switching a Log File:
SQL>Alter system switch logfile;
Clear a Redo Log file:
A redo log file might become corrupted while the database is open, and ultimately stop database
activity because archiving cannot continue. In this situation we use bellow command to clear the redo
log group.
SQL> ALTER DATABASE CLEAR LOGFILE GROUP 3;
Note: In two Situation dropping redo logs is not possible:.
1. If there are only two log groups.
2. The corrupt redo log file belongs to the current group.

Drop Redo Log groups:


Before dropping redo log group , we need to check the status of redo log groups.
We can only drop INACTIVE or UNUSED.
SQL> select group#,thread#,members,status from v$log;
SQL>Alter database drop logfile group 4;
Drop the Redo Log File:
Before dropping a Redo Log file, please consider the following points:
1. We can only drop member of an inactive group.
2. At least two valid groups available for Oracle instance.
3. To avoid a single point failure for your Log files, you must ensure that all Redo Log groups always
have at least two members.

Sql>alter database drop logfile member ‘C:\APP\ARIF\ORADATA\NEWDB\REDO01_02.LOG’;


Archiving

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy