DBA的工作列表上寫了些什么
2024-07-21 02:39:23
供稿:網(wǎng)友
數(shù)據(jù)庫(kù)治理員(DBA)的主要工作
啟動(dòng)和關(guān)閉數(shù)據(jù)庫(kù)
一) 啟動(dòng)數(shù)據(jù)庫(kù)
$ svrmgrl
SVRMGR> connect internal (實(shí)例啟動(dòng))
SVRMGR> startup
二) 關(guān)閉數(shù)據(jù)庫(kù)
$ svrmgrl
SVRMGR> connect internal
SVRMGR> shutdown [immediate/abort]
immediate:正在訪問(wèn)數(shù)據(jù)庫(kù)的會(huì)話被完全終止、資源有序釋放后才關(guān)閉 數(shù)據(jù)庫(kù)。
abort: 會(huì)話立即中止,數(shù)據(jù)庫(kù)立即關(guān)閉。
備份與恢復(fù)
一) 邏輯備份與恢復(fù)(即卸庫(kù)與裝庫(kù))
1. 卸庫(kù):eXPort
不帶參數(shù):
$ 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 工作開(kāi)始自動(dòng)進(jìn)行最終出現(xiàn):
Export terminated successfully without warnings.
帶參數(shù),可選參數(shù)如下(可用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.裝庫(kù):
不帶參數(shù)
$ 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 工作開(kāi)始自動(dòng)進(jìn)行最終出現(xiàn):
Import terminated successfully with warnings.
帶參數(shù),可選參數(shù)如下(可用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
(二) 物理備份與恢復(fù)
1. 冷備份與熱備份
冷備份
在數(shù)據(jù)庫(kù)關(guān)閉狀態(tài)與進(jìn)行。將所有的數(shù)據(jù)文件、重演日志文件及控制文件拷貝到磁盤。空閑的時(shí)間再將備份移到磁帶上。
(1)可通過(guò):SVRMGR> select * from v$logfile;
select * from v$dbfile;
select * from v$control.file;
這些語(yǔ)句來(lái)了解數(shù)據(jù)文件、重演日志文件及控制文件的相應(yīng)位置及名稱。
(2)利用$cp 命令來(lái)拷貝:
例:$cp /u01/u02/pz_ts.ora /dbfile_b/
熱備份
數(shù)據(jù)庫(kù)必須工作在“ARCHIVELOG”方式下
可利用SVRMGR> archive log list 語(yǔ)句來(lái)查歸檔日志狀態(tài)
若在“NOARCHIVELOG”方式下,進(jìn)行轉(zhuǎn)換
SVRMGR> connect internal
SVRMGR> shutdown immediate ——關(guān)閉數(shù)據(jù)庫(kù)——
SVRMGR> startup mount ——為暫停日志方式轉(zhuǎn)換預(yù)備數(shù)據(jù)庫(kù)——
SVRMGR> alter database archivelog; ——轉(zhuǎn)換——
SVRMGR> alter database open; ——打開(kāi)數(shù)據(jù)庫(kù)——
拷貝
1> 將一個(gè)表空間置為備份方式
SVRMGR> alter tablespace pzts begin backup;
2> 拷貝
SVRMGR>$cp /u01/u02/pz_ts.ora /dbfile_b/
3> 取消該表備份方式
SVRMGR>alter tablespace pzts end backup;
利用以上3步,將所有表空間下的數(shù)據(jù)文件進(jìn)行備份
4> 拷貝控制文件
5> 拷貝歸檔重演日志
2.恢復(fù)
磁盤出現(xiàn)故障,數(shù)據(jù)庫(kù)自行關(guān)閉。
(1) 將駐留在磁盤上的備份拷貝到其他磁盤或磁帶上
(2) 執(zhí)行
SVRMGR> connect internal
SVRMGR> startup mount
SVRMGR> alter database open;
會(huì)出現(xiàn)錯(cuò)誤信息,提示需要恢復(fù)
(3)執(zhí)行
SVRMGR> recover database
根據(jù)提示,自動(dòng)恢復(fù)
(4)執(zhí)行
SVRMGR>alter database open
恢復(fù)完成,數(shù)據(jù)庫(kù)打開(kāi)。