手动创建数据库步骤:
1、准备工作(创建相关目录、设置ORACLE_SID)
2、生成参数文件
3、启动实例
3、脚本创建数据库
4、脚本创建数据字典
5、打开数据库
一: 准备工作
1、创建相关目录
wyncrac为要创建的数据名,所以创建同名目录用来集中存储相关文件
[oracle@localhost wyncrac]$ ll
total 36
drwxr-xr-x. 2 oracle oinstall 4096 Jun 24 09:57 archivelog --归档日志,
drwxr-xr-x. 2 oracle oinstall 4096 Jun 24 11:03 controlfile --控制文件
drwxr-xr-x. 2 oracle oinstall 4096 Jun 24 12:13 dump
drwxr-xr-x. 2 oracle oinstall 4096 Jun 24 09:58 pwdfile --密码文件
drwxr-xr-x. 2 oracle oinstall 4096 Jun 24 11:03 redolog --重做日志文件
drwxrwxrwx. 2 oracle root 4096 Jun 24 11:02 scripts --常用脚本
drwxr-xr-x. 2 oracle oinstall 4096 Jun 24 11:04 sysdatafile --系统数据文件
drwxr-xr-x. 2 oracle oinstall 4096 Jun 24 09:58 userdatafile --用户数据文件
以上文件在create database脚本中会用到
2、设置当前ORACLE_SID
[oracle@localhost ~]$ export ORACLE_SID=wyncrac
二: 生成参数文件
两种类型:
二进制类型参数文件(无法直编辑) -> spfileSID.ora
修改 -> alter system set paraname='' 同步应用到参数文件
启动 -> startup nomount 默认将寻找该类型参数文件
9i以后默认
文本类型参数文件(可直接编辑) -> pfileSID.ora
修改 -> alter system set paraname='' 不会同步应用到参数文件,要手动调整文件对
启动 -> startup nomount pfile=...
startup nomount阶段读取参数文件,得到db_name、SGA参数、控制文件位置等信息
默认位置 -> $ORACLE_HOME/dbs/
查找顺序 -> $ORACLE_HOME/dbs/spfileSID.ora -> spfile.ora-> initSID.ora
相互生成
pfile ->spfile: create spfile=$ORACLE_HOME/dbs/spfilewyncrac.ora from pfile=$ORACLE_HOME/dbs/pfile.ora
spfile ->pfile: 与以上相反即可
1、从现有的参数文件中另存一份作为新实例的参数文件
[oracle@localhost dbs]$ cp initora.ora initwyncrac.ora
2、编辑文件做调整
将control_files路径设为上面创建的controlfile -> /ora/ora10g/wyncrac/controlfile
dump相关文件路径设为dump -> /ora/ora10g/wyncrac/dump
[oracle@localhost dbs]$ vim initwyncrac.ora
wyncrac.__db_cache_size=188743680
wyncrac.__java_pool_size=4194304
wyncrac.__large_pool_size=4194304
wyncrac.__shared_pool_size=83886080
wyncrac.__streams_pool_size=0
*.audit_file_dest='/ora/ora10g/wyncrac/dump'
*.background_dump_dest='/ora/ora10g/wyncrac/dump'
*.compatible='10.2.0.1.0'
*.control_files='/ora/ora10g/wyncrac/controlfile/control01.ctl','/ora/ora10g/wyncrac/controlfile/control02.ctl','/ora/ora10g/
wyncrac/controlfile/control03.ctl'
*.core_dump_dest='/ora/ora10g/wyncrac/dump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='wyncrac'
*.db_recovery_file_dest='/ora/ora10g/product/10.2.0/db_1/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=wyncracXDB)'
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=284164096
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/ora/ora10g/wyncrac/dump'
3、由pfile生成spfile
SQL> create spfile='/ora/ora10g/product/10.2.0/db_1/dbs/spfilewyncrac.ora'
2 from pfile='/ora/ora10g/product/10.2.0/db_1/dbs/initwyncrac.ora';
File created.
三: 启动实例
1、创建、还原数据库等必须启动实例后到nomount进行,该阶段只会启动实例(分配SGA与后台进程)
SQL> startup nomount
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 92276304 bytes
Database Buffers 188743680 bytes
Redo Buffers 2973696 bytes
2、执行创建数据库脚本
a、在上面创建的scripts目录下创建createdb.sql文件如下:
create database wyncrac
LOGFILE
GROUP 1 ('/ora/ora10g/wyncrac/redolog/redo01.log','/ora/ora10g/wyncrac/redolog/redo01_1.log') size 10m reuse,
GROUP 2 ('/ora/ora10g/wyncrac/redolog/redo02.log','/ora/ora10g/wyncrac/redolog/redo02_1.log') size 10m reuse,
GROUP 3 ('/ora/ora10g/wyncrac/redolog/redo03.log','/ora/ora10g/wyncrac/redolog/redo03_1.log') size 10m reuse
MAXLOGFILES 50
MAXLOGMEMBERS 5
MAXLOGHISTORY 200
MAXDATAFILES 500
MAXINSTANCES 5
ARCHIVELOG
CHARACTER SET UTF8
NATIONAL CHARACTER SET UTF8
DATAFILE '/ora/ora10g/wyncrac/sysdatafile/system01.dbf' SIZE 100M reuse autoextend on next 10m maxsize unlimited extent
management local
SYSAUX DATAFILE '/ora/ora10g/wyncrac/sysdatafile/sysaux01.dbf' SIZE 100M reuse autoextend on next 10m maxsize unlimited
UNDO TABLESPACE UNDOTBS1 DATAFILE '/ora/ora10g/wyncrac/sysdatafile/undo.dbf' SIZE 50M reuse autoextend on next 5M maxsize
unlimited
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE '/ora/ora10g/wyncrac/sysdatafile/temp.dbf' SIZE 50M reuse autoextend on next 5M
maxsize unlimited;
b、数据库创建脚本执行完后,可看到重做日志、系统数据表路径、警告日志等文件会创建在上面定义的目录中
relog -> /ora/ora10g/wyncrac/redolog/
sysdatafile -> /ora/ora10g/wyncrac/sysdatafile/
alertlog -> /ora/ora10g/wyncrac/dump/
controlfile -> /ora/ora10g/wyncrac/controlfile/
默认位置:
relog、datafile、controlfile -> $ORACLE_HOME/oradata/SID/
alertlog -> $ORACLE_HOME/admin/SID/
c、打开数据库
SQL> startup
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 92276304 bytes
Database Buffers 188743680 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
四: 相关视图
1、v$log -> 日志信息
SQL> select group#,thread#,sequence#,bytes,members,archived,status
2 from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS
---------- ---------- ---------- ---------- ---------- --- ----------------
1 1 10 10485760 2 YES INACTIVE
2 1 11 10485760 2 NO CURRENT
3 1 9 10485760 2 YES INACTIVE
STATUS:
INACTIVE -> 已归档
ACTIVE -> 归档中
CURRENT -> 当前正在写
2、v$logfile -> 联机重做日志路径
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/ora/ora10g/wyncrac/redolog/redo01.log
/ora/ora10g/wyncrac/redolog/redo01_1.log
/ora/ora10g/wyncrac/redolog/redo02.log
/ora/ora10g/wyncrac/redolog/redo02_1.log
/ora/ora10g/wyncrac/redolog/redo03.log
/ora/ora10g/wyncrac/redolog/redo03_1.log
6 rows selected.
3、当前数据库是否归档模式:
SQL> select log_mode from v$database;
LOG_MODE
------------
ARCHIVELOG
或
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 9
Next log sequence to archive 11
Current log sequence 11
启动步骤:
startup nomount -> mount ->open 直接startup时将从nomount逐步到open
startup nomount:
1: 仅读取参数文件分配SGA结构
2: 启动后台进程
3: 生成或修改警告或跟踪文件,默认位置在$ORACLE_HOME/admin/SID/alert<SID>.log与<SID>_*.trc
startup mount:
1: 按参文件位置,锁定并读取控制文件获取重做日志与数据文件信息,但并不打开这些信息
控制文件损坏就无法启动,但数据文件丢失对此步骤没影响
startup open
1: 打开数据文件
2: 打开联机重做日志
3: 后台进程会检测控制文件、数据文件、联机日志文件的一致性,即SCN是否一致
4: 如一致性检查失败,由SMON进行实例恢复,通过归档与重做日志将未写入datafile的应用redolog重做,已写入datafile但未提交的应用undo回滚
5: 如数据文件、联机重做日志丢失或异常,启动将终止,需要进行介质恢复