Oracle - Database Administrations
Contents
This part mainly talk about these points:
- Import and export of database
- Start and Stop database
- Starting and stopping Nodes in the RAC
- Manage available sessions
Import and export of database
Oracle’s
export
(exp) andimport
(imp) utilities are used to perform logical database backup and recovery. When exporting, database objects are dumped to a binary file which can then be imported into another Oracle database.
Thisexp/imp
is different fromexpdp/impdp
inData Pump
, The detail about datapump will talk in other article.
Theexport/import
utilities are commonly used to perform the following tasks:
- Backup and recovery (small databases only, say <
+50GB
, if bigger, useRMAN
instead)- Move data between Oracle databases on different platforms (for example from Solaris to Windows)
- Reorganization of data / eliminate database fragmentation (
export
,drop
andre-import
tables)- Upgrade databases from extremely old versions of Oracle (when in-place upgrades are not supported by the Database Upgrade Assistant any more)
- Detect database corruption. Ensure that all the data can be read
- Transporting tablespaces between databases
How to use
Look for the
imp
andexp
executables in your$ORACLE_HOME/bin
directory. One can run them interactively, using command line parameters, or using parameter files. Look at theimp/exp
parameters before starting. These parameters can be listed by executing the following commands:exp help=yes
orimp help=yes
.
The following examples demonstrate how theimp/exp
utilities can be used:
1 | exp scott/tiger file=emp.dmp log=emp.log tables=emp rows=yes indexes=no |
Export with query
From Oracle 8i one can use the
QUERY=
export parameter to selectively unload a subset of the data from a table. You may need to escape special chars on the command line.
For example:query=\"where deptno=10\"
. Look at these examples:
1 | exp scott/tiger tables=emp query="where deptno=10" |
Other Questions
Before one imports rows into already populated tables, one needs to truncate or drop these tables to get rid of the old data. If not, the new data will be appended to the existing tables. One must always
DROP
existing Sequences before re-importing. If the sequences are not dropped, they will generate numbers inconsistent with the rest of the database.
Note: It is also advisable to drop indexes before importing to speed up the import process. Indexes can easily be recreated after the data was successfully imported.
Start and Stop database
Start database
Ensure oracle other service such as
lsnrctl
,srvctl
,crsctl
is work.
Oracle start has thress modes, step by step start oracle:
- NOMOUNT
PS. This mode just create instance, does not mount database, And just create memory structures and service processess for oracle instance, It can not open any data file.
In this mode, only access the dictionary views related SGA, containsVPARAMETER
,VSGA
,VPROCESS
,VSESSION
etc. Because these views is get from SGA area.
What you can do:create new database
rebuild control files
- MOUNT
PS. This mode will mount database, but database status is closed, so client user can’t operate the database.
In this mode, only access the dictionary views related Control files, containsVTHREAD
,VCONTROLFILE, VDATABASE
,VDATAFILE
,V$LOGFILE
etc. Because these views is get from Control files.
What you can do:Rename datafile
Add/Del/Rename rebuild log files
Execute database recover completely
Change database to Archive mode
- OPEN
PS. Normal mode to start database. If occurred any error, please useSTARTUP FORCE
1 | su - oracle |
Stop database
Shutdown the database has four methods:
- NORMAL
This mode will forbid new client create connection, the current executing transtracion is still doing.
- IMMEDIATE
This mode will not wait users active disconnection and will enforce the transtractions
- TRANSACTIONAL
This mode will wait users not commit transactions to commit.
- ABORT
This mode will ignore everything. Be careful~
1 | su - oracle |
Starting and stopping Nodes in the RAC
Start Node
1 | # check status of instance |
Stop Node
1 | # verify instance running |
Manage available sessions
Enabling and Disabling Restricted Session
1 | select logins from v$instance; |
Disconnect session
1 | SELECT SID, SERIAL#, STATUS |
Kill session
1 | alter system kill session ' sid, serial#' IMMEDIATE; |
Resources:
http://docs.oracle.com/cd/B28359_01/server.111/b28319/exp_imp.htm#i1023983
http://www.orafaq.com/wiki/Import_Export_FAQ
https://docs.oracle.com/cd/E11882_01/rac.112/e41960/admin.htm#RACAD812
Author: itabas016
Link: https://tech.itabas.com/2016/09/27/database/oracle-kt-database-administrations/
License: CC BY-NC-ND 4.0