Explain How To Create A New Database: Smallfile Case I
Explain How To Create A New Database: Smallfile Case I
Creating database is very simple in Oracle. We can use the DBCA database configuration assistant to create a
database. We can launch the DBCA by using the windows command prompt utility by just typing dbca. As the
welcome window appears it provides five options out of which one is creating database. This is fairly straightforward
we can create a new database from scratch, using a create database command or doing an RMAN restore of a
template database with many options.
To completely re-name a database you need to change all of the components where the instance name is located:
External files: sqlnet.ora, tnsnames.ora, init.ora (spfile)
Internal locations: Data dictionary.
Follow the steps to rename the database as described:
On the old system sign on as SYSDBA into SQLPLUS and issue: “alter database backup controlfile to
trace”;
Shutdown the old database.
Change all references to the old instance name in all locations for sqlnet.ora, protocol.ora, tnsnames.ora
and the init.ora
Change the database name in the file to reference the new ORACLE_SID instance name.
Oracle provides different types of tablespace namely SYSTEM tablespaces, the SYSAUX tablespace, temporary
tablespaces, undo tablespaces, and bigfile tablespaces.
The procedures and methods available for resizing a tablespace are slightly different, depending on whether the
tablespace is a smallfile or a bigfile tablespace.
Smallfile case I:
For example we need to alter the size of the table space named users which contain one database file starting out of
5 MB. First we will make it to 15 MB and then reduce its size to 10 MB.
An oracle database consists of data files; redo log files, control files, temporary files. And in order to find out the size
of the entire database we need to sum up size of all these files.
The biggest portion of a database's size comes from the data files. To find out how many megabytes are allocated to
ALL data files: select sum (bytes)/1024/1024 "Meg" from dba_data_files;
To get the size of all TEMP files: select nvl (sum (bytes), 0)/1024/1024 "Meg" from dba_temp_files;
To get the size of the on-line redo-logs: select sum (bytes)/1024/1024 "Meg" from sys.v_$log; Hence to find the full
size of database sum up all these files size.
You can easily compute the amount of free space in each tablespace by using the following query:
SQL> select tablespace_name, sum (bytes) from dba_free_space group by tablespace_name;
Remember: The free space does not take into account the space that would be available if and when the datafiles in
a tablespace are auto extended. Also, any space allocated to a table for rows that are later deleted will be available
for future inserts into the table, but it is not counted in the preceding query results as space available for other
database objects
Backup is generally needed for safety reason. For example if something may go wrong in the live database which is
running. Then immediately we can restore the backup and server the purpose. We can take back up as per our wish.
For example if the database is having much of the insert, update and delete query executing daily in large numbers
then we need to take the backup every 5 to 6 days. Rest depends upon the DBA who is managing the database. Or
How often you choose to perform these backup routines is really dependent on the data requirements of your
company. If you do not know what those are then you need to find out either by referring to them or asking for them to
be created through a research and investigation process.
Online backup is one which is taken at the time the database is running in the ARCHIVELOG mode.
Following files should be backed up during the Offline Backup: All data file, all control file and all online redo
log file. But in the case of the online backup following files is backed up: All data files all archived redo log
files and one control file via the alter database command.
Offline database we cannot rely upon but in case of online database no issues.
Offline backup no archived mode is required but in the online backup it is must.
Restoring a database is copying the physical files from a backup medium (disk or tape) to the appropriate file
locations for database operation Recovery is process of updating database files restored from backup w/changes
made to the database since backup, typically using redo log files.
Recovering files typically refers to saving one or more files, while a restore usually refers replacing a complete
system or hard drive from a full system backup.
Restore means restoring a database backup from a backup medium. Recovery" means recovering redolog
information.
Explain how to backup a database using the export utility
The logical backup in Oracle database is done by Export utility. Oracle’s Export utility queries the database, including
the data dictionary, and writes the output to a binary file called an export dump file. The backup through export utility
can be done in four phase. These phases are commonly known as BACKUP modes. The modes are: Full mode,
Tablespace mode, User mode, and Table mode.
In Full mode, the full database is exported. The entire data dictionary is read, and the DDL needed to re-create the
full database is written to the export dump file. This file includes creation commands for all tablespaces, all users, and
all of the objects, data, and privileges in their schemas.
In Tablespace mode, all of the objects contained in the specified tablespace(s) will be exported, including the
definition of indexes on the contained objects, even if they are in another tablespace.
In User mode, a user’s objects are exported, as well as the data within them. All grants and indexes created by the
user on the user’s objects are also exported. Grants and indexes created by users other than the owner are not
exported.
In Table mode, a specified table is exported. The table’s structure, indexes, and grants are exported along with or
without its data. Table mode can also export the full set of tables owned by a user.
To make use of the ARCHIVELOG capability, the database must first be placed in ARCHIVELOG mode. The
following listing shows the steps needed to place a database in ARCHIVELOG mode.
Consistent offline backups occur when the database has been shut down normally using the normal, immediate, or
transactional option of the shutdown command.
Process: While the database is shut down, each of the files actively used by the database is backed up. These files
provide a complete image of the database as it existed at the moment it was shut down. Doing offline backup is easy
the only point that must be kept in mind is:
If we are using raw devices for database storage, with or without ASM, you’ll have to backup these devices
as well using operating system commands such as dd in combination with a compression utility, as dd
if=/dev/sdb | gzip > /mnt/bkup/dw_sdb_backup.img.gz
We should not rely on an offline backup performed following a shutdown abort, because it may be
inconsistent.
Explain how to do on-line database backups
Online backup can be done while the database is open. The only condition needs to be satisfied is it must be in
ARCHIVED mode. Implementing Online Backups:
Set the database into backup state by using the alter tablespace . . . begin backup command for each
tablespace or alter database begin backup to put all tablespaces into online backup mode.
Back up the data files using operating system commands.
Set the database back to its normal state by issuing alter tablespace . . . end backup for each tablespace or
alter database end backup for all tablespaces in the database.
Archive the unarchived redo logs so that the redo required to recover the tablespace backup is used by
issuing the command alter system archive log current.
Back up the archived redo log files. If necessary, compress or delete the backed-up archived redo log files
to free space on disk.
Back up the control file.
RMAN in Oracle stands for Oracle Recovery Manager. RMAN takes backup and recovery to a new level of protection
and ease of use. We can use RMAN with command line mode and with OEM web interface. It serves as an optional
catalog for database recovery in Oracle. In order to use RMAN one has to create RMAN account.
SQL> create tablespace rman datafile '+data1' 2 size 125m auto extend on next 50m maxsize 500m;
We will get am message that tablespace created.
SQL> alter user rman default tablespace rman 2 quota unlimited on rman;
User altered.
Now the RMAN account has been created and we can log on and use it.
RMAN provides two modes of full database backup. Full database backup can be done as:
After that we can connect as sysdba and can view the parameters of recovery.
RMAN provide various options for the recovery of the database. Among the few are block media recovery, restoring a
control file, restoring a table space etc.
RMAN> recover tablespace users;
We can archive logs using RMAN. RMAN provides option that once the backup is completed, we have the option to
leave the logs in place, to delete only the logs that RMAN used for the backup, or to delete all copies of the archived
logs that were backed up to tape.
Recovery Manager is the single tool for guaranteed, efficient, manageable Oracle database backup and recovery.
RMAN integrates with leading 3rd party backup vendors for backup to tape, via the System Backup to Tape API.
These backup vendors have implemented interfaces to their products using the API, allowing RMAN to drive backups
to and restores from tape.
To store backups on tape, RMAN requires media manager software, a third party software program that writes,
reads, and manages sequential media such as tapes to backup and recovery data. The core of the RMAN and media
manager software integration is the media management library, supplied by the backup vendor. This library contains
an implementation of the SBT API functions, and is linked in with the Oracle server binary. Oracle calls these SBT
functions to back up and restore data files to and from media controlled by the media manager. When performing
backups or restores, the RMAN client connects to the target instance and directs the instance to talk to the media
manager. No direct communication occurs between the RMAN client and the media manager; all communication
occurs on the target instance.