Oracle 10g 快速手工建库步骤
Oracle 10g 快速手工建库步骤记录:
0. 修改环境变量
[oracle@ocm1 ~]$ vi .bash_profile
添加以下内容:
export ORACLE_SID=PROD
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/jdk/bin:$PATH
1. 修改登录标识符和默认编辑器(非必须)
修改$ORACLE_HOME/sqlplus/admin/glogin.sql,在文件末尾添加以下内容:
set sqlprompt '_user''@''_connect_identifier> '
define _editor=vi
2. 创建初始化参数(用于启动数据库实例)
[oracle@ocm1 dbs]$ cat init.ora|grep -v ^$|grep -v ^# > initPROD.ora
[oracle@ocm1 dbs]$ ll
total 32
-rw-r----- 1 oracle oinstall 12920 May 3 2001 initdw.ora
-rw-r----- 1 oracle oinstall 8385 Sep 11 1998 init.ora
-rw-r--r-- 1 oracle oinstall 738 Jan 10 19:18 initPROD.ora
[oracle@ocm1 dbs]$ vi initPROD.ora
db_name=PROD
db_files = 80 # SMALL
db_file_multiblock_read_count = 8 # SMALL
#db_block_buffers = 100 # SMALL
#shared_pool_size = 3500000 # SMALL
log_checkpoint_interval = 10000
processes = 50 # SMALL
parallel_max_servers = 5 # SMALL
log_buffer = 32768 # SMALL
max_dump_file_size = 10240 # limit trace file size to 5 Meg each
global_names = FALSE
control_files = (/u01/app/oacle/oradata/PROD/Disk1/control01.ctl, /u01/app/oacle/oradata/PROD/Disk1/control02.ctl,/u01/app/oacle/oradata/PROD/Disk1/control03.ctl)
undo_management=auto
sga_max_size=300M
sga_target=300M
注意:红色部分为需要添加或修改的地方
3. 创建密码文件
[oracle@ocm1 dbs]$ orapwd file=orapwPROD password=oracle entries=5
[oracle@ocm1 dbs]$ ll
total 36
-rw-r----- 1 oracle oinstall 12920 May 3 2001 initdw.ora
-rw-r----- 1 oracle oinstall 8385 Sep 11 1998 init.ora
-rw-r--r-- 1 oracle oinstall 914 Jan 10 19:21 initPROD.ora
-rw-r----- 1 oracle oinstall 2048 Jan 10 19:24 orapwPROD
4. 创建相关目录
[oracle@ocm1 dbs]$ mkdir /u01/app/oracle/admin/PROD/{a,b,c,u}dump -p
[oracle@ocm1 dbs]$ cd /u01/app/oracle/admin/PROD
[oracle@ocm1 PROD]$ ll
total 16
drwxr-xr-x 2 oracle oinstall 4096 Jan 10 19:23 adump
drwxr-xr-x 2 oracle oinstall 4096 Jan 10 19:23 bdump
drwxr-xr-x 2 oracle oinstall 4096 Jan 10 19:23 cdump
drwxr-xr-x 2 oracle oinstall 4096 Jan 10 19:23 udump
[oracle@ocm1 PROD]$ cd /u01/app/oracle
[oracle@ocm1 oracle]$ mkdir oradata/PROD/Disk{1,2,3,4,5} -p
[oracle@ocm1 oracle]$ cd oradata/PROD/
[oracle@ocm1 PROD]$ ll
total 20
drwxr-xr-x 2 oracle oinstall 4096 Jan 10 19:22 Disk1
drwxr-xr-x 2 oracle oinstall 4096 Jan 10 19:22 Disk2
drwxr-xr-x 2 oracle oinstall 4096 Jan 10 19:22 Disk3
drwxr-xr-x 2 oracle oinstall 4096 Jan 10 19:22 Disk4
drwxr-xr-x 2 oracle oinstall 4096 Jan 10 19:22 Disk5
5. 创建spfile
[oracle@ocm1 PROD]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jan 10 19:25:04 2015
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SYS@PROD> startup nomount
ORACLE instance started.
Total System Global Area 314572800 bytes
Fixed Size 1219184 bytes
Variable Size 96470416 bytes
Database Buffers 213909504 bytes
Redo Buffers 2973696 bytes
SYS@PROD> create spfile from pfile;
File created.
创建spfile并用它启动后,就可以通过alter sysem set xxx来动态修改所需的参数了,主要是可以利用模糊查找得到不熟悉的参数名
6. 创建建库脚本crdb.sql
Reffer:Administration->Database Administrator's Guide->2 Creating an Oracle Database->Manually Creating an Oracle Database->Step 7: Issue the CREATE DATABASE Statement
CREATE DATABASE PROD
USER SYS IDENTIFIED BY oracle
USER SYSTEM IDENTIFIED BY oracle
GROUP 1 ('/u01/app/oracle/oradata/PROD/Disk1/redo01_a.log') SIZE 100M
GROUP 2 ('/u01/app/oracle/oradata/PROD/Disk1/redo02_a.log') SIZE 100M
GROUP 3 ('/u01/app/oracle/oradata/PROD/Disk1/redo03_a.log') SIZE 100M
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXLOGHISTORY 1
MAXDATAFILES 100
MAXINSTANCES 1
CHARACTER SET US7ASCII
NATIONAL CHARACTER SET AL16UTF16
DATAFILE '/u01/app/oracle/oradata/PROD/Disk1/system01.dbf' SIZE 325M REUSE
EXTENT MANAGEMENT LOCAL
SYSAUX DATAFILE '/u01/app/oracle/oradata/PROD/Disk1/sysaux01.dbf' SIZE 325M REUSE
SIZE 20M REUSE
SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;
可以用%s替换加速修改,注意修改实例名和相应的路径,确保目录都存在
6. 开始跑脚本建库(约2分钟)
[oracle@ocm1 PROD]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jan 10 19:51:10 2015
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SYS@PROD> @/home/oracle/crdb.sql
Database created.
至此,已经基本完成了手工建库的步骤,但是这个库目前还用不了,原因是没有数据字典等系统对象
7. 分别运行catalog.sql和catproc.sql脚本(注意先后顺序)
SYS@PROD> @?/rdbms/admin/catalog
SYS@PROD> @?/rdbms/admin/catproc
SYS@PROD> select count(*) from dba_objects;
COUNT(*)
----------
9373
跑完脚本,才能执行对各个系统表和视图的查询,可以看到,默认手工建库跑完脚本后的系统对象是9373个(10g)
还有一种更快的方法,就是设置db_create_file_dest和db_create_online_logfile_dest1,然后直接运行create database xxx;
然后根据需要调整具体的路径或参数
友情提醒:
建完库之后,记得关闭数据库用tar进行冷备份,主要是PROD和dbs这2个目录,这样就不怕误删除了,用tar的之后千万注意解压和压缩的命令参数不要用错,否则一不小心将当前目录不相关的内容变成备份内容,覆盖了原来的备份内容,那可是非常糟糕的,默认如果生成的tar文件同名,会直接覆盖掉,而不是追加到原压缩文件。