最大的網站源碼資源下載站,
數據庫管理員(dba)的主要工作
啟動和關閉數據庫
一) 啟動數據庫
$ svrmgrl
svrmgr> connect internal (實例啟動)
svrmgr> startup
二) 關閉數據庫
$ svrmgrl
svrmgr> connect internal
svrmgr> shutdown [immediate/abort]
immediate:正在訪問數據庫的會話被完全終止、資源有序釋放后才關閉 數據庫。
abort: 會話立即中止,數據庫立即關閉。
備份與恢復
一) 邏輯備份與恢復(即卸庫與裝庫)
1. 卸庫:export
不帶參數:
$ cd $oracle_home/bin
$ exp
username: cwadmin
password:
connected to: oracle8 enterprise edition release 8.0.4.0.0 - production
pl/sql release 8.0.4.0.0 - production
enter array fetch buffer size: 4096 >
export file: expdat.dmp > pzexdat.dmp
(1) e(ntire database), (2)u(sers), or (3)t(ables): (2)u > 1
export grants (yes/no): yes > y
export table data (yes/no): yes > y
compress extents (yes/no): yes >y
export 工作開始自動進行最終出現:
export terminated successfully without warnings.
帶參數,可選參數如下(可用exp help=y 得到):
keyword description (default) keyword description (default)
---------------------------------------------------------------------------------------------------
userid username/password full export entire file (n)
buffer size of data buffer owner list of owner usernames
file output file (expdat.dmp) tables list of table names
compress import into one extent (y) recordlength length of io record
grants export grants (y) inctype incremental export type
indexes export indexes (y) record track incr. export (y)
rows export data rows (y) parfile parameter filename
constraints export constraints (y) consistent cross-table consistency
log log file of screen output statistics analyze objects (estimate)
direct direct path (n)
feedback display progress every x rows (0)
point_in_time_recover tablespace point-in-time recovery (n)
recovery_tablespaces list of tablespace names to recover
volsize number of bytes to write to each tape volume
例:$exp userid=cwadmin/cwadmin tables=’(sys_cwxx,sys_menu)’ file=pzexport.dmp
2.裝庫:
不帶參數
$ cd $oracle_home/bin
$ imp
username: cwadmin
password:
connected to: oracle8 enterprise edition release 8.0.4.0.0 - production
pl/sql release 8.0.4.0.0 - production
import file: expdat.dmp > pzexdat.dmp
enter insert buffer size (minimum is 4096) 30720> 10240
export file created by export:v08.00.04 via conventional path
list contents of import file only (yes/no): no >
ignore create error due to object existence (yes/no): no > y
import grants (yes/no):yes > y
import table data (yes/no):yes >y
import entire export file (yes/no):no >y
import 工作開始自動進行最終出現:
import terminated successfully with warnings.
帶參數,可選參數如下(可用imp help=y 得到):
keyword description (default) keyword description (default)
---------------------------------------------------------------------------------------------------
userid username/password full import entire file (n)
buffer size of data buffer fromuser list of owner usernames
file input file (expdat.dmp) touser list of usernames
show just list file contents (n) tables list of table names
ignore ignore create errors (n) recordlength length of io record
grants import grants (y) inctype incremental import type
indexes import indexes (y) commit commit array insert (n)
rows import data rows (y) parfile parameter filename
log log file of screen output
destroy overwrite tablespace data file (n)
indexfile write table/index info to specified file
charset character set of export file (nls_lang)
point_in_time_recover tablespace point-in-time recovery (n)
skip_unusable_indexes skip maintenance of unusable indexes (n)
analyze execute analyze statements in dump file (y)
feedback display progress every x rows(0)
volsize number of bytes in file on each volume of a file on tape
例:$imp userid=cwadmin/cwadmin tables=’(sys_dwxx, sys_menu)’ file=pzexdat.dmp
(二) 物理備份與恢復
1. 冷備份與熱備份
冷備份
在數據庫關閉狀態與進行。將所有的數據文件、重演日志文件及控制文件拷貝到磁盤。空閑的時間再將備份移到磁帶上。
(1)可通過:svrmgr> select * from v$logfile;
select * from v$dbfile;
select * from v$control.file;
這些語句來了解數據文件、重演日志文件及控制文件的相應位置及名稱。
(2)利用$cp 命令來拷貝:
例:$cp /u01/u02/pz_ts.ora /dbfile_b/
熱備份
數據庫必須工作在“archivelog”方式下
可利用svrmgr> archive log list 語句來查歸檔日志狀態
若在“noarchivelog”方式下,進行轉換
svrmgr> connect internal
svrmgr> shutdown immediate ---關閉數據庫---
svrmgr> startup mount ---為暫停日志方式轉換準備數據庫---
svrmgr> alter database archivelog; ---轉換---
svrmgr> alter database open; ---打開數據庫---
拷貝
1> 將一個表空間置為備份方式
svrmgr> alter tablespace pzts begin backup;
2> 拷貝
svrmgr>$cp /u01/u02/pz_ts.ora /dbfile_b/
3> 取消該表備份方式
svrmgr>alter tablespace pzts end backup;
利用以上3步,將所有表空間下的數據文件進行備份
4> 拷貝控制文件
5> 拷貝歸檔重演日志
2.恢復
磁盤出現故障,數據庫自行關閉。
(1) 將駐留在磁盤上的備份拷貝到其他磁盤或磁帶上
(2) 執行
svrmgr> connect internal
svrmgr> startup mount
svrmgr> alter database open;
會出現錯誤信息,提示需要恢復
(3)執行
svrmgr> recover database
根據提示,自動恢復
(4)執行
svrmgr>alter database open
恢復完成,數據庫打開。
新聞熱點
疑難解答