目录搜索
文字
分享

    
ORACLE FOR SUN SOLARIS 维护手册
来源:不详

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

ORACLE FOR SUN SOLARIS 维护手册

 

ORACLE 的维护工作主要有打开和关闭数据库;用exp、imp命令做逻辑备份;用t

ar命令做物理备份;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 <font face="Wingdings">í</font>

 

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#