ORACLE FOR SUN SOLARIS 維護(hù)手冊(cè)
ORACLE 的維護(hù)工作主要有打開和關(guān)閉數(shù)據(jù)庫(kù);用exp、imp命令做邏輯備份;用t
ar命令做物理備份;ORACLE 數(shù)據(jù)庫(kù)使用一段時(shí)間后的空間擴(kuò)張和針對(duì)具體的工作
增加臨時(shí)或回滾表空間,取消新增的臨時(shí)或回滾表空間;增加oracle的用戶,給
用戶授權(quán)等。以下按順序詳細(xì)介紹這些維護(hù)操作。
一、打開和關(guān)閉數(shù)據(jù)庫(kù)
1、打開數(shù)據(jù)庫(kù)
①、#su - oracle
②、%dbstart
等待十幾秒左右,當(dāng)看到
oracle instances started,
database mounted,
database opened的時(shí)候,oracle數(shù)據(jù)庫(kù)打開成功
第二步的操作由如下命令組成
%svrmgrl 喚醒SVRMGR狀態(tài)
SVRMGR >connect internal 連接內(nèi)核
SVRMGR>startup 打開數(shù)據(jù)庫(kù)
SVRMGR>exit
%
備注:打開數(shù)據(jù)庫(kù)startup可帶三個(gè)參數(shù),分別是
SVRMGR> startup nomount 僅啟動(dòng)instances
SVRMGR> startup mount 啟動(dòng)instances,連上(mount)數(shù)據(jù)庫(kù)
SVRMGR> startup normal 啟動(dòng)instances,連上(mount)數(shù)據(jù)庫(kù)
打開(open)數(shù)據(jù)庫(kù)
startup缺省參數(shù)是normal
③、 %lsnrctl start 啟動(dòng) oracle listener
如果出錯(cuò)檢查環(huán)境變量是否設(shè)好,及l(fā)snrctl文件的內(nèi)容和執(zhí)行屬性。
2、 關(guān)閉數(shù)據(jù)庫(kù)
①、#su - oracle
②、%lsnrctl stop 關(guān)閉 oracle listener
③、%dbshut
等待幾秒左右,當(dāng)看到
database closed
database dismounted
oracle instances shut down的時(shí)候,oracle數(shù)據(jù)庫(kù)關(guān)閉成功
第三步的操作由如下命令組成
%svrmgrl 喚醒SVRMGR狀態(tài)
SVRMGR>connect internal 連接內(nèi)核
SVRMGR>shutdown 關(guān)閉數(shù)據(jù)庫(kù)
SVRMGR>exit
%
備注:關(guān)閉數(shù)據(jù)庫(kù)shutdown可帶三個(gè)參數(shù),分別是
SVRMGR> shutdown abort 非正常立刻關(guān)機(jī)。等于忽然停電
SVRMGR> shutdown immediate 做回滾操作,立刻關(guān)機(jī)。
SVRMGR> shutdown normal 正常關(guān)機(jī)
shutdown缺省參數(shù)是normal
二、用exp、imp命令做邏輯備份
1、輸出export
基本命令:一般用交互方式,在oracle用戶提示符下鍵入
% exp user/password í
exp 模式
①、table:export 某個(gè)用戶模式下指定的table ;而不是所有的table ,而且不包
括cluster定義;
②、user: export一個(gè)用戶模式下所有的對(duì)象(如表、數(shù)據(jù)、索引等);
export 示例 user mode:
③、full database: export database 中所有的對(duì)象,執(zhí)行這個(gè)必須被給
exp-full-database角色。
export 示例
A、dababase mode
% exp system/manager
... ... ...
enter array fetch buffer size :4096>(return)
export file :expdat.dmp >dba.dmp
e(ntire database),u(sers),t (ables):u>e
export grants (y/n):y>y
export table data (y/n):y>y
compress extents(y/n):y>y
B、table mode
% exp system/manager
... ... ...
enter array fetch buffer size :4096>(return)
export file :expdat.dmp >dba.dmp
e(ntire database),u(sers),t (ables):u>t
export grants (y/n):y>y
export table data (y/n):y>y
compress extents(y/n):y>y
About to exp specified tables ...
Table to be exported (RETURN quit) > emp ( 輸入要輸出的表名 )
.... exporting table EMP 14 rows exported
About to exp specified tables ...
Table to be exported (RETURN quit) > 如此循環(huán)下去,按回車退出
2、輸入import
前提:在database建立之后,必須運(yùn)行oracle-home /rdbms /admin/catexp.sql
才能使用export,import。
權(quán)限:要使用 import ,必須要有create session 權(quán)限。如果要import 其它用戶
的表,必須要有imp_full_databade角色。(運(yùn)行了catexp.sql后,dba就有了imp
_full_database角色)。
字符:與export有關(guān),只要兩臺(tái)機(jī)器的字符設(shè)置一樣就沒問題。
基本命令:一般用交互方式,在oracle用戶提示符下鍵入
% imp user/password
imp 模式
①、table:允許用戶import在用戶模式下指定的table ,而不是所有的table;
②、user:允許用戶import 屬于用戶本身所有的對(duì)象;
③、full database:允許用戶import所有的database對(duì)象,必須被給予
imp-full-database角色。
import 示例
imp system/manager
...
import file :expdat.dmp>
enter insert buffer size (minimum is 4096)30720>
export file created by export:v 07.01.03
list contents of import file only(yds /no):no>
ignore create error due to obyict existence (yes /no):yes >
import grants (yes /no):yes>
import table data (yes /no):yes >
import entire export file (yes /no):yes >no
注意事項(xiàng):
①、import 的權(quán)限必須大于、等于export的權(quán)限;
②、 對(duì)于long colums 由于對(duì)內(nèi)存的特殊要求(需要地址連續(xù)的內(nèi)存區(qū))export
和 import有時(shí)不會(huì)成功;
③、對(duì)于備份到磁帶上,export 和import 建議用同一臺(tái)磁帶機(jī)。
三、用tar命令做物理備份
1、#su - oracle
2、% tar cvf /dev/rmt/0 .
把oracle 路徑下所有文件備份到磁帶機(jī)上
3、% tar xvf /dev/rmt/0
把備份磁帶上所有文件恢復(fù)進(jìn)oracle 當(dāng)前路徑
4、% tar tvf /dev/rmt/0
查看磁帶上有些什么文件
四、數(shù)據(jù)庫(kù)的擴(kuò)充
1、增加一個(gè)表空間
當(dāng)我們要開發(fā)某個(gè)大型的應(yīng)用程序時(shí),最好建立一個(gè)相應(yīng)的表空間。
命令示例:
SVRMGR>create tablespace application datafile
‘/usr/oracle/dbs/application.dbf’ size 3M
針對(duì)具體情況增加回滾和臨時(shí)表空間
命令示例:
SVRMGR>create rollback tablespace rbs8 datafile
‘/usr/oracle/dbs/rbs8.dbf’ size 4M
SVRMGR>create tablespace tmp8 datafile
‘/usr/oracle/dbs/tmp8.dbf’ size 550K
回滾和臨時(shí)表空間用完后,可刪除或使它offline
SVRMGR>drop tablespace rbs8;
SVRMGR>drop tablespaces tmp8;
SVRMGR>alter tablespace rbs offline;
SVRMGR>alter tablespace tmp8 offline;
建立回滾段舉例:
SVRMGR>create rollback segment rs11 tablespace tmp8 ;
SVRMGR>alter rollback segment rs11 online;
SVRMGR>alter rollback segment rs11 offline;
2、增加某個(gè)表空間的大小
當(dāng)一個(gè)表空間的大小不能滿足工作需要時(shí),應(yīng)該擴(kuò)充表空間。
舉例:
SVRMGR>alter tablespace system
add datafile ‘/usr/oracle/dbs/sys338.dbf’ size 3M;
五、增加oracle的用戶,并給用戶授權(quán)
1、增加oracle的用戶, 并給用戶授權(quán)
舉例:
SVRMGR>create user newuser identified by userpasswd
default tablespace application
temporary tablespace tmp8;
SVRMGR>grant connect to newuser;
SVRMGR>grant resource to newuser;
SVRMGR>grant update on emp to newuser;
2、增加oracle的角色
oracle的缺省角色有connect、resource、dba。它是一組可以分配給其它role
或用戶的權(quán)限總和,connect 有8個(gè)權(quán)限,resource 有5個(gè)權(quán)限,dba有77
個(gè)權(quán)限。給一般連接用戶賦connect,給一般編程人員賦connect加resource,
只有數(shù)據(jù)庫(kù)管理員才有dba的權(quán)限。
①創(chuàng)建一個(gè)角色
SVRMGR>create role newrole identified by rolepasswd;
②給角色賦權(quán)限
SVRMGR>grant select on all table to newrolle;
SVRMGR>grant connect to newrole with admin option;
3、中斷用戶同oracle的連接
當(dāng)oracle數(shù)據(jù)庫(kù)要關(guān)機(jī)或某個(gè)用戶占有的大量的資源需要被釋放時(shí),dba
需中斷用戶同oracle的連接。
①、SVRMGR>select sid,serial#,username from v$session;
②、SVRMGR>alter system kill session ‘interger1,interger2’;
interger1,interger2分別對(duì)應(yīng)于sid和serial#
|