首页 > Linux操作系统 > Linux操作系统 > 学习笔记之20120825
Shutdown immediate:立即关闭,常用;
Shutdown abort:中止关闭,数据库启动时就行实例恢复;
Shutdown transactional:等待事务结束才关闭;
Shutdown normal(同shutdown):等待会话结束、等待事务结束才关闭;
|
|
Immediate |
Abort |
Transactional |
noraml |
|
允许新连接 |
不 |
不 |
不 |
不 |
|
等待会话结束 |
不 |
不 |
不 |
是 |
|
等待事务结束 |
不(自动rollback) |
不 |
是 |
是 |
|
做一个检查点并关闭数据文件 |
是 |
不 |
是 |
是 |
|
启动时是需要实例恢复 |
不 |
是(自动) |
不 |
不 |
|
适用场合 |
常用 |
少用, 运行复杂业务且immediate不能关闭时 |
少用,业务重要,需等待事务处理结束 |
少用,用户停留在数据库上,都不能正常关闭时 |
2. Oracle启动状态:
-> nomount(Instance started)
-> mount(Control file opened for this instance)
-> open(All files opened as described by the control file for this instance)
nomount,只启动实例(Instance started):startup nomount;
v$instance中status为STARTED。
这个过程oracle做了4件事。
1 打开参数文件,spfile或者pfile。
Ø Spfile和pfile文件内容一致;
Ø Pfile是文本文件,可手工编辑;spfile是二进制文件,不能手工编辑,只能使用数据库命令修改,可在数据库运行时修改,默认使用spfile启动数据库;
Ø 根据spfile文件创建pfile文件:
create pfile=’ E:\oracle\product\10.2.0\db_1\dbs\pfile.ora’ from spfile;
使用pflie文件启动数据库:
Startup nomount pfile=’ E:\oracle\product\10.2.0\db_1\dbs\pfile.ora’;
2 分配内存,即SGA。
3 启动后台进程。
4 写入alert
启动到nomount状态后,可以创建数据库或重新创建控制文件。
总结:这个过程出错,有两个原因,一是参数设置错误,二是操作系统级的问题。总结就是和数据库文件没有关系,因为这个时候还没有打开数据库文件。
mount,读取控制文件(Controlfile):从nomount更改为mount,alter database mount;
v$instance中status为MOUNTED。
这个过程oracle做了3件事:
1 使数据库和实例关联。
2 打开控制文件(控制文件的位置由参数文件指定)。
3 读控制文件中的数据文件和重做日志文件的名称和状态,但是不检查他们是否存在。
默认3个控制文件,内容一致;
在Windows中查看控制文件内容,
备份控制文件:
alter database backup controlfile to trace as 'e:\oracle\backup\ctlfile.trc' reuse;
alter database backup controlfile to 'e:\oracle\backup\ctlfile.bak' reuse;
reuse:覆盖
对控制文件进行备份并恢复:http://blog.sina.com.cn/s/blog_6fd335bb0100qnyv.html
启动到mount状态后,可以进行:
1 重命名数据文件。
2 设置归档状态。
3 数据库恢复等。
总结:这个过程出错,应该是由控制文件引起的。
Open,alter database
open; v$instance中status为OPEN。
这个过程oracle做了3件事:
1 打开数据文件。
2 打开联机重做日志文件。
3 检查数据库的一致性,有可能会进行恢复操作。
总结:这个过程出错,有可能是数据文件和日志文件物理错误。或者一致性的问题。
相关命令:
STARTUP [OPEN|MOUNT|NOMOUNT]
ALTER DATABASE { MOUNT | OPEN }
参考:http://hi.baidu.com/o151d241/blog/item/7f39df003fe5c80a728da558.html
3. 密码文件:E:\oracle\product\10.2.0\db_1\database\PWDorcl.ora,
Show parameter pass / 或remote_login_passwordfile
Exclusive:与shared功能一样。rac中多个实例应该有相同的值。
None: oracle会忽略任何密码文件,此时有权限的用户(比如sys)必须使用操作系统认证。
Share: 一个或多个数据库可以使用密码文件,这时密码文件中可以包含sys和非sys用户
修改:alter system set remote_login_passwordfile=none scope=spfile;
Startup force; (Startup force is equal to shutdown abort + startup normal.)
参考:
http://www.dbasky.com/oracle/remote_login_passwordfile_sqlnet_ora.html
http://wenku.baidu.com/view/0df570bc1a37f111f1855b9b.html
4. 查看表空间:
select tablespace_name as "表空间名称",block_size/1024 as "数据块存储大小(KB)",status as "状态",contents as "类型",logging as "是否有日志" from dba_tablespaces;
查看数据文件:
select t.tablespace_name as "表空间名称",t.file_name as "数据文件路径",t.bytes/1024/1024 as "数据文件大小(MB)",t.autoextensible as "数据文件是否自动扩展",t.maxbytes/1024/1024/1024 as "数据文件最大(GB)" from dba_data_files t;
表空间和数据文件关系:一对多
5. 查看重做日志文件:select * from v$logfile;
6. 设置临时显示数据的长度大小:col file_name for a50;
7. 新建库:
(1) 创建表空间:
Create tablespace bank_tbs
Datafile 'E:\oracle\product\10.2.0\oradata\orcl\bank_data02.dbf'
Size 5M autoextend on maxsize 10G;
(2) 创建用户:
Create user bankuser identified by bankpwd default tablespace bank_tbs;
(3) 给用户赋角色权限:
Grant connect,resource to bankuser;
(4) 测试:
Conn bankuser/bankpwd; / 或 Sqlplus bankuser/bankpwd@orcl;
show user;
8. 使用Export/Import导出/导入数据:
导出:Exp scott/cat@orcl file=e:\oracle\backup\scottData.dmp log= e:\oracle\backup\scottExpLog.log
导入:Imp scott/cat@orcl fromuser=scott touser=scott file= e:\oracle\backup\scottData.dmp log= e:\oracle\backup\scottImpLog.log
9. Data dump:数据泵,数据转储:expdb/impdb
Ø 实现逻辑备份和逻辑恢复;
Ø 在数据库用户之间移动对象;
Ø 在数据库之间移动对象;
Ø 实现表空间搬移;
与exp/imp区别:
Ø Exp/imp是客户端工具程序,可在客户端或服务端使用;
Ø Expdb/impdb是服务端工具程序,只能在服务端使用;
Ø Imp只适用Exp导出的文件,不适用Expdb导出的文件,Impdb只适用Expdb导出的文件;
使用expdb/impdb导出/导入数据:
Ø System登录;
Ø 创建目录:create or replace directory dump_tmp as 'e:\oracle\backup';
Ø 赋权:grant read,write on directory dump_tmp to scott; 退出Exit;
expdp scott/cat@orcl directory=dump_tmp dumpfile=scottdata_expdb.dmp logfile=scottExpdbLog.log
导入:impdp scott/cat@orcl directory=dump_tmp dumpfile=scottdata_expdb.dmp logfile=scottImpdbLog.log
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27663431/viewspace-741914/ ,如需转载,请注明出处,否则将追究法律责任。