在Linux平台下,手工创建一个数据库的操作有几个步骤:
1、确认唯一的instance和database name
2、选择database的字符集;
3、设定操作系统的环境变量
4、建立初始化参数文件;
5、启动instance到nomount状态
6、执行create database命令;
7、至少运行两个脚本文件;
测试条件说明:在oracle创建之初,已经创建了一个数据库orcl (这个操作在),这里再用手工的方式创建一个kwen数据库。
1、首先打开putty,切换到oracle用户:
login as: root
root@192.168.1.60's password:
Last login: Thu Jan 21 23:27:52 2010 from 192.168.1.2
[root@localhost root]# su – oracle
查看当前的环境变量的配置:
[oracle@localhost oracle]$ env |grep ORACLE
ORACLE_SID=orcl
ORACLE_BASE=/opt/oracle
ORACLE_HOME=/opt/oracle/10gR2
[oracle@localhost oracle]$ sqlplus /nolog
SQL*Plus: Release 10.1.0.3.0 - Production on Thu Jan 21 23:28:07 2010
Copyright (c) 1982, 2004, Oracle. All rights reserved.
SQL< exit
[oracle@localhost oracle]$ vi env.new RACLE_BASE=/opt/oracle
ORACLE_HOME=$ORACLE_BASE/10gR2
ORACLE_SID=kwen
LD_LIBRARY_PATH=$ORACLE_HOME/lib
PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID LD_LIBRARY_PATH PATH
[oracle@localhost oracle]$ chmod 755 env.new
[oracle@localhost oracle]$ . ./env.new
[oracle@localhost oracle]$ env |grep ORACLE
ORACLE_SID=kwen
ORACLE_BASE=/opt/oracle
ORACLE_HOME=/opt/oracle/10gR2
[oracle@localhost oracle]$mkdir –p /opt/oracle/admin/kwen/bdump
[oracle@localhost oracle]$mkdir –p /opt/oracle/admin/kwen/udump
[oracle@localhost oracle]$mkdir –p /opt/oracle/admin/kwen/cdump
[oracle@localhost oracle]$mkdir –p /opt/oracle/oradata/kwen
创建数据库的密码文件
[oracle@localhost oracle]$ cd /opt/oracle/10gR2/dbs
[oracle@localhost dbs]$ ls
initdw.ora initorcl.ora spfileorcl.ora
orapworcl hc_orcl.dat init.ora lkORCL
[oracle@localhost dbs]$orapwd file=/opt/oracle/10gR2/dbs/orapwkwen password=admin entries=10;
[oracle@localhost dbs]$ ls
hc_kwen.dat hc_orcl.dat initdw.ora init.ora initorcl.ora lkORCL orapwkwen orapworcl spfileorcl.ora
[oracle@localhost dbs]$ cp initorcl.ora initkwen.ora
[oracle@localhost dbs]$ cat initorcl.ora
orcl.__db_cache_size=46137344
orcl.__java_pool_size=8388608
orcl.__large_pool_size=4194304
orcl.__shared_pool_size=41943040
*.background_dump_dest='/opt/oracle/admin/orcl/bdump'
*.compatible='10.1.0.2.0'
*.control_files='/opt/oracle/oradata/orcl/control01.ctl','/opt/oracle/oradata/orcl/control02.ctl','/opt/oracle/oradata/orcl/control03.ctl'
*.core_dump_dest='/opt/oracle/admin/orcl/cdump'
*.db_block_size=8192
*.db_cache_advice='ON'
*.db_cache_size=37748736
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='orcl'
*.db_recovery_file_dest='/opt/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_max_size=104857600
*.sga_target=104857600
*.shared_pool_size=37748736
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/opt/oracle/admin/orcl/udump'
[oracle@localhost dbs]$ cat initkwen.ora
kwen.__db_cache_size=46137344
kwen.__java_pool_size=8388608
kwen.__large_pool_size=4194304
kwen.__shared_pool_size=41943040
*.background_dump_dest='/opt/oracle/admin/kwen/bdump'
*.compatible='10.1.0.2.0'
##*.control_files='/opt/oracle/oradata/kwen/control01.ctl','/opt/oracle/oradata/kwen/control02.ctl','/opt/oracle/oradata/kwen/control03.ctl'
*.core_dump_dest='/opt/oracle/admin/kwen/cdump'
*.db_block_size=8192
*.db_cache_advice='ON'
*.db_cache_size=37748736
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='kwen'
*.db_recovery_file_dest='/opt/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_max_size=104857600
*.sga_target=104857600
*.shared_pool_size=37748736
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/opt/oracle/admin/kwen/udump'
将所有的orcl换成新的SID:kwen,并且注释掉控制文件的一行。在这里要将里面所指定的目录全部建好。
[oracle@localhost dbs]$ sqlplus /nolog
SQL*Plus: Release 10.1.0.3.0 - Production on Fri Jan 22 00:05:07 2010
Copyright (c) 1982, 2004, Oracle. All rights reserved.
SQL< conn / as sysdba;
Connected.
SQL< create spfile from pfile;
SQL< startup nomount;
ORACLE instance started.
Total System Global Area 104857600 bytes
Fixed Size 777932 bytes
Variable Size 57680180 bytes
Database Buffers 46137344 bytes
Redo Buffers 262144 bytes
SQL< !
[oracle@localhost dbs]$ ls
hc_kwen.dat hc_orcl.dat initdw.ora initkwen.ora init.ora initorcl.ora lkKWEN lkORCL orapwkwen orapworcl spfilekwen.ora spfileorcl.ora
[oracle@localhost kwen]$ vi create.sql
create database kwen
controlfile reuse
datafile '/opt/oracle/oradata/kwen/system1.dbf' size 100m autoextend on next 100m maxsize unlimited
sysaux datafile '/opt/oracle/oradata/kwen/sysaux.dbf' size 100m reuse autoextend on next 100m maxsize unlimited
default temporary tablespace temp1
tempfile '/opt/oracle/oradata/kwen/temp1.dbf' size 100m reuse autoextend on next 100m maxsize unlimited
undo tablespace UNDOTBS1
datafile '/opt/oracle/oradata/kwen/undo1.dbf' size 100m reuse autoextend on next 100m maxsize unlimited
default tablespace kwen
datafile '/opt/oracle/oradata/kwen/kwen.dbf' size 100m reuse autoextend on next 100m maxsize unlimited
extent management local autoallocate
logfile
group 1 '/opt/oracle/oradata/kwen/redo1.log' size 100m reuse,
group 2 '/opt/oracle/oradata/kwen/redo2.log' size 100m reuse,
group 3 '/opt/oracle/oradata/kwen/redo3.log' size 100m reuse
character set al32utf8
;
[oracle@localhost oracle]$ exit
exit
SQL< conn /as sysdba;
Connected.
SQL< @/opt/oracle/10gR2/dbs/create.sql
执行结束后,开始去运行catalog.sql及cataproc.sql两个脚本文件,则这两个文件执行完毕后,kwen这个数据库已经创建成功。
SQL< @/opt/oracle/10gR2/rdbms/admin/catalog.sql
SQL< @/opt/oracle/10gR2/rdbms/admin/catproc.sql
至此一个数据库已经创建成功。
可能你在创建的时候会遇到很多的问题,请检查你的脚本文件的语法,或者已经有数据文件存在(这里可不指定size大小,而用reuse选项即可),还有一种可能就是你的权限不足,无法写入等。
这里总结下,主要的步骤:
1、写设置新的环境变量脚本文件
2、创建密码文件及parameter参数文件
3、创建符合OFA的空目录
4、创建create database的脚本文件
5、运行catalog.sql与catproc.sql两个脚本文件