ORACLE FOR SUN SOLARIS 维护手册

ORACLE 的维护工作主要有打开和关闭数据库;用exp、imp命令做逻辑备份;用tar命令做物理备份;ORACLE 数据库使用一段时间后的空间扩张和针对具体的工作增加临时或回滚表空间,取消新增的临时或回滚表空间;增加oracle的用户,给用户授权等。以下按顺序详细介绍这些维护操作。

一、打开和关闭数据库

1、打开数据库

①、#su - oracle

②、%dbstart

等待十几秒左右,当看到

oracle instances started,

database mounted,

database opened的时候,oracle数据库打开成功

第二步的操作由如下命令组成

%svrmgrl 唤醒SVRMGR状态

SVRMGR >connect internal 连接内核

SVRMGR>startup 打开数据库

SVRMGR>exit

%

备注:打开数据库startup可带三个参数,分别是

SVRMGR> startup nomount 仅启动instances

SVRMGR> startup mount 启动instances,连上(mount)数据库

SVRMGR> startup normal 启动instances,连上(mount)数据库

打开(open)数据库

startup缺省参数是normal

③、 %lsnrctl start 启动 oracle listener

如果出错检查环境变量是否设好,及lsnrctl文件的内容和执行属性。

2、 关闭数据库

①、#su - oracle

②、%lsnrctl stop 关闭 oracle listener

③、%dbshut

等待几秒左右,当看到

database closed

database dismounted

oracle instances shut down的时候,oracle数据库关闭成功

第三步的操作由如下命令组成

%svrmgrl 唤醒SVRMGR状态

SVRMGR>connect internal 连接内核

SVRMGR>shutdown 关闭数据库

SVRMGR>exit

%

备注:关闭数据库shutdown可带三个参数,分别是

SVRMGR> shutdown abort 非正常立刻关机。等于忽然停电

SVRMGR> shutdown immediate 做回滚操作,立刻关机。

SVRMGR> shutdown normal 正常关机

shutdown缺省参数是normal

二、用exp、imp命令做逻辑备份

1、输出export

基本命令:一般用交互方式,在oracle用户提示符下键入

% exp user/password í

exp 模式

①、table:export 某个用户模式下指定的table ;而不是所有的table ,而且不包括cluster定义;

②、user: export一个用户模式下所有的对象(如表、数据、索引等);

export 示例 user mode:

③、full database: export database 中所有的对象,执行这个必须被给

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) > 如此循环下去,按回车退出

2、输入import

前提:在database建立之后,必须运行oracle-home /rdbms /admin/catexp.sql才能使用export,import。

权限:要使用 import ,必须要有create session 权限。如果要import 其它用户的表,必须要有imp_full_databade角色。(运行了catexp.sql后,dba就有了imp_full_database角色)。

字符:与export有关,只要两台机器的字符设置一样就没问题。

基本命令:一般用交互方式,在oracle用户提示符下键入

% imp user/password

imp 模式

①、table:允许用户import在用户模式下指定的table ,而不是所有的table;

②、user:允许用户import 属于用户本身所有的对象;

③、full database:允许用户import所有的database对象,必须被给予

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

注意事项:

①、import 的权限必须大于、等于export的权限;

②、 对于long colums 由于对内存的特殊要求(需要地址连续的内存区)export 和 import有时不会成功;

③、对于备份到磁带上,export 和import 建议用同一台磁带机。

三、用tar命令做物理备份

1、#su - oracle

2、% tar cvf /dev/rmt/0 .

把oracle 路径下所有文件备份到磁带机上

3、% tar xvf /dev/rmt/0

把备份磁带上所有文件恢复进oracle 当前路径

4、% tar tvf /dev/rmt/0

查看磁带上有些什么文件

四、数据库的扩充

1、增加一个表空间

当我们要开发某个大型的应用程序时,最好建立一个相应的表空间。

命令示例:

SVRMGR>create tablespace application datafile

‘/usr/oracle/dbs/application.dbf’ size 3M

针对具体情况增加回滚和临时表空间

命令示例:

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

回滚和临时表空间用完后,可删除或使它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、增加某个表空间的大小

当一个表空间的大小不能满足工作需要时,应该扩充表空间。

举例:

SVRMGR>alter tablespace system

add datafile ‘/usr/oracle/dbs/sys338.dbf’ size 3M;

五、增加oracle的用户,并给用户授权

1、增加oracle的用户, 并给用户授权

举例:

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

或用户的权限总和,connect 有8个权限,resource 有5个权限,dba有77

个权限。给一般连接用户赋connect,给一般编程人员赋connect加resource,

只有数据库管理员才有dba的权限。

①创建一个角色

SVRMGR>create role newrole identified by rolepasswd;

②给角色赋权限

SVRMGR>grant select on all table to newrolle;

SVRMGR>grant connect to newrole with admin option;

3、中断用户同oracle的连接

当oracle数据库要关机或某个用户占有的大量的资源需要被释放时,dba

需中断用户同oracle的连接。

①、SVRMGR>select sid,serial#,username from v$session;

②、SVRMGR>alter system kill session ‘interger1,interger2’;

interger1,interger2分别对应于sid和serial# 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值