完整的手工建立ORACLE数据库步骤

作者:Winder(杭州)
E_MAIL: [email protected]
URL: http://www.qyhhschool.com

关键词:经过排错的 经过调试的 完整的 整理他人的 手工建库 ORACLE

数据库: Oracle 8i R2 (8.1.6)
安装路径:/data/ora816
数据库实例:web
数据库全局名称:web.edi.com

1、手工创建相关目录
/data/ora816/admin/web
/data/ora816/admin/web/adhoc
/data/ora816/admin/web/bdump
/data/ora816/admin/web/cdump
/data/ora816/admin/web/create
/data/ora816/admin/web/exp
/data/ora816/admin/web/pfile
/data/ora816/admin/web/udump

/data/ora816/oradata/web
/data/ora816/oradata/web/archive

2、手工创建初始化启动参数文件:/data/ora816/admin/web/pfile/initweb.ora
检查$ORACLE_HOME/dbs目录下是否有初始化文件,比如如果您的sid是web,则在此目录下应该有一个initweb.ora的文件,如果没有,您可以将init.ora文件复制成initweb.ora文件:cp init.ora initweb.ora.如果您的sid是web,则在此目录下应该有一个initweb.ora的文件,如果没有,您可以将init.ora文件复制成initweb.ora文件:cp init.ora initweb.ora.
ln -s /data/ora816/admin/web/initweb.ora /data/ora816/dbs/initweb.ora

附:initweb.ora内容(见后)

3、使用orapwde命令,创建/data/ora816/dbs/orapwweb
命令:orapwd file=/data/ora816/dbs/orapwweb password=ORACLE entries=5

4、检查环境变量是否设置:ORACLE_HOME,ORACLE_SID,检查方法:输入命令echo $ORACLE_HOME,或者echo $ORACLE_SID,如果这两个环境变量没有设置,您将会发现输出一个空行,这时您可以通过以root权限登录,修改/etc/profile文件,在末尾填上:ORACLE_HOME=您安装ORACLE时的主路径,如/data/ora816 ORACLE_SID=您安装时所定的sid,如orcl,我在上面的文件中是web
export ORACLE_HOME ORACLE_SID
同时您还应该修改PATH环境变量,以便于使用工具svrmgrl,sqlplus等。将bin目录加入到PATH中。

5、分别检查是否存在下列文件$ORACLE_HOME/rdbms/admin/catdbsyn.sql,$ORACLE_HOME/rdbms/admin/catproc.sql,$ORACLE_HOME/sqlplus/admin/pupbld.sql,如果不存在,请重新安装您的oracle系统。

6、准备创建脚本:create_db.sql

rem 脚本开始
connect internal
startup nomount pfile="$ORACLE_HOME/admin/web/pfile/initweb.ora"
set echo on
spool makedb.log
create database web
datafile '$ORACLE_HOME/oradata/web/web_syst_01.dbf' size 500M reuse
logfile
'$ORACLE_HOME/oradata/web/web_redo_01.dbf' size 10M reuse,
'$ORACLE_HOME/oradata/web/web_redo_02.dbf' size 10M reuse,
'$ORACLE_HOME/oradata/web/web_redo_03.dbf' size 10M reuse
MAXLOGFILES 32
MAXLOGMEMBERS 2
MAXLOGHISTORY 1
MAXDATAFILES 254
MAXINSTANCES 1
CHARACTER SET ZHS16GBK
NATIONAL CHARACTER SET ZHS16GBK;

connect INTERNAL/oracle
rem --修改系统表空间
ALTER TABLESPACE SYSTEM DEFAULT STORAGE ( INITIAL 64K NEXT 64K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 50);
ALTER TABLESPACE SYSTEM MINIMUM EXTENT 64K;
connect INTERNAL/oracle

rem --修改系统表空间
ALTER TABLESPACE SYSTEM DEFAULT STORAGE ( INITIAL 64K NEXT 64K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 50);
ALTER TABLESPACE SYSTEM MINIMUM EXTENT 64K;

rem --创建回滚表空间
CREATE TABLESPACE RBS DATAFILE '/data/ora816/oradata/web/rbs01.dbf' SIZE 256M REUSE
AUTOEXTEND ON NEXT 5120K
MINIMUM EXTENT 512K
DEFAULT STORAGE ( INITIAL 512K NEXT 512K MINEXTENTS 8 MAXEXTENTS 4096);

rem --创建用户表空间
CREATE TABLESPACE USERS DATAFILE '/data/ora816/oradata/web/users01.dbf' SIZE 128M REUSE
AUTOEXTEND ON NEXT 1280K
MINIMUM EXTENT 128K
DEFAULT STORAGE ( INITIAL 128K NEXT 128K MINEXTENTS 1 MAXEXTENTS 4096 PCTINCREASE 0);

rem --创建临时表空间
CREATE TABLESPACE TEMP DATAFILE '/data/ora816/oradata/web/temp01.dbf' SIZE 32M REUSE
AUTOEXTEND ON NEXT 640K
MINIMUM EXTENT 64K
DEFAULT STORAGE ( INITIAL 64K NEXT 64K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0) TEMPORARY;

rem --创建工具表空间
CREATE TABLESPACE TOOLS DATAFILE '/data/ora816/oradata/web/tools01.dbf' SIZE 64M REUSE
AUTOEXTEND ON NEXT 320K
MINIMUM EXTENT 32K
DEFAULT STORAGE ( INITIAL 32K NEXT 32K MINEXTENTS 1 MAXEXTENTS 4096 PCTINCREASE 0);

rem --创建索引表空间
CREATE TABLESPACE INDX DATAFILE '/data/ora816/oradata/web/indx01.dbf' SIZE 32M REUSE
AUTOEXTEND ON NEXT 1280K
MINIMUM EXTENT 128K
DEFAULT STORAGE ( INITIAL 128K NEXT 128K MINEXTENTS 1 MAXEXTENTS 4096 PCTINCREASE 0);

rem --创建回滚段
CREATE PUBLIC ROLLBACK SEGMENT RBS0 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS1 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS2 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS3 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS4 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS5 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS6 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS7 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS8 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS9 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS10 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS11 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS12 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS13 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS14 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS15 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS16 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS17 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS18 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS19 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS20 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS21 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS22 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS23 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );
CREATE PUBLIC ROLLBACK SEGMENT RBS24 TABLESPACE RBS STORAGE ( OPTIMAL 4096K );

rem --使回滚段在线
ALTER ROLLBACK SEGMENT "RBS0" ONLINE;
ALTER ROLLBACK SEGMENT "RBS1" ONLINE;
ALTER ROLLBACK SEGMENT "RBS2" ONLINE;
ALTER ROLLBACK SEGMENT "RBS3" ONLINE;
ALTER ROLLBACK SEGMENT "RBS4" ONLINE;
ALTER ROLLBACK SEGMENT "RBS5" ONLINE;
ALTER ROLLBACK SEGMENT "RBS6" ONLINE;
ALTER ROLLBACK SEGMENT "RBS7" ONLINE;
ALTER ROLLBACK SEGMENT "RBS8" ONLINE;
ALTER ROLLBACK SEGMENT "RBS9" ONLINE;
ALTER ROLLBACK SEGMENT "RBS10" ONLINE;
ALTER ROLLBACK SEGMENT "RBS11" ONLINE;
ALTER ROLLBACK SEGMENT "RBS12" ONLINE;
ALTER ROLLBACK SEGMENT "RBS13" ONLINE;
ALTER ROLLBACK SEGMENT "RBS14" ONLINE;
ALTER ROLLBACK SEGMENT "RBS15" ONLINE;
ALTER ROLLBACK SEGMENT "RBS16" ONLINE;
ALTER ROLLBACK SEGMENT "RBS17" ONLINE;
ALTER ROLLBACK SEGMENT "RBS18" ONLINE;
ALTER ROLLBACK SEGMENT "RBS19" ONLINE;
ALTER ROLLBACK SEGMENT "RBS20" ONLINE;
ALTER ROLLBACK SEGMENT "RBS21" ONLINE;
ALTER ROLLBACK SEGMENT "RBS22" ONLINE;
ALTER ROLLBACK SEGMENT "RBS23" ONLINE;
ALTER ROLLBACK SEGMENT "RBS24" ONLINE;

rem --修改sys用户的临时表空间为TEMP
alter user sys temporary tablespace TEMP;

rem --创建数据字典表
connect system/manager
@$ORACLE_HOME/rdbms/admin/catdbsyn.sql

connect internal
@/data/ora816/rdbms/admin/catalog.sql;
@/data/ora816/rdbms/admin/catexp7.sql
@/data/ora816/rdbms/admin/catproc.sql
@/data/ora816/rdbms/admin/caths.sql

connect system/manager
@/data/ora816/sqlplus/admin/pupbld.sql

connect internal/oracle
@/data/ora816/rdbms/admin/catrep.sql

rem --修改system用户默认表空间和临时表空间
alter user system default tablespace SYSTEM;
alter user system temporary tablespace TEMP;

spool off
rem 脚本结束


7、执行脚本
您可以进行执行脚本了,转到目录:$ORACLE_HOME/dbs中去,并且将上面的create_db.sql也放到此目录中,下面开始了:

键入命令:svrmgrl回车
SVRMGR>connect internal
connected.
SVRMGR>startup回车
SVRMGR>@create_db.sql回车(ok,下面您就可以看到屏幕在不断的显时操作过程,大概需要半个多小时的时间或许还要长一点点)。
执行完毕之后您可能需要退出去
SVRMGR>exit
没有错误的话,现在您的数据库已经生成了。

8、生成SQL*Plus帮助系统
sqlplus SYSTEM/manager
@/data/ora816/sqlplus/admin/help/helpbld.sql helpus.sql



9、部分说明

1)、create database web
datafile '$ORACLE_HOME/oradata/web/web_syst_01.dbf' size 500M reuse
logfile
'$ORACLE_HOME/oradata/web/web_redo_01.dbf' size 10M reuse,
'$ORACLE_HOME/oradata/web/web_redo_02.dbf' size 10M reuse,
'$ORACLE_HOME/oradata/web/web_redo_03.dbf' size 10M reuse

请注意看一下生成的文件名字:web_syst_01.dbf,web_redo_01.dbf,web_redo_02.dbf,web_redo_03.dbf,请注意将您的sid换成相应的部分,在我的例子中我的sid是web。

另外还有生成表空间时的几个文件:
create tablespace rollback
datafile '$ORACLE_HOME/dbs/web_roll_01.dbf' size 8M reuse;

create tablespace temp
datafile '$ORACLE_HOME/dbs/web_temp_01.dbf' size 5M reuse
temporary;

create tablespace users
datafile '$ORACLE_HOME/dbs/web_user_01.dbf' size 10M reuse;

最好也要改成相应的名字

2)、connect system/manager
@$ORACLE_HOME/rdbms/admin/catdbsyn.sql
connect internal
@$ORACLE_HOME/rdbms/admin/catproc.sql
connect system/manager
@$ORACLE_HOME/sqlplus/admin/pupbld.sql

其中的connect system/manager 是假设您的system账号的密码就是manager(系统默认的),如果您通过alter user system identified by 修改了密码,请换成正确的密码登录。

3)、initweb.ora文件内容:
db_name = "web"
instance_name = web
service_names = web.edi.com
db_files = 1024
control_files = ("/data/ora816/oradata/web/control01.ctl", "/data/ora816/oradata/web/control02.ctl", "/d
ata/ora816/oradata/web/control03.ctl")
open_cursors = 200
max_enabled_roles = 30
db_file_multiblock_read_count = 8
db_block_buffers = 4096
shared_pool_size = 52428800
large_pool_size = 78643200
java_pool_size = 20971520
log_checkpoint_interval = 10000
log_checkpoint_timeout = 1800
processes = 115
parallel_max_servers = 5
log_buffer = 32768
max_dump_file_size = 10240
global_names = true
oracle_trace_collection_name = ""
background_dump_dest = /data/ora816/admin/web/bdump
user_dump_dest = /data/ora816/admin/web/udump
db_block_size = 16384
remote_login_passwordfile = exclusive
os_authent_prefix = ""
job_queue_processes = 4
job_queue_interval = 60
open_links = 4
distributed_transactions = 10
mts_dispatchers = "(PROTOCOL=TCP)(PRE=oracle.aurora.server.SGiopServer)"
mts_dispatchers = "(protocol=TCP)"
compatible = 8.1.0
sort_area_size = 65536
sort_area_retained_size = 65536

# log_archive_start = true
# log_archive_dest_1 = "location=/data/ora816/oradata/oradb/archive"
# log_archive_format = %%ORACLE_SID%%T%TS%S.ARC
Some additions:

7. after connect as internal, you should run your creat_db.sql. (delete that part: startup).

9- 3). In the initweb.ora, you should add rollback_segments = ( RBS0, RBS1, RBS2 ...) in order for them to be online next time the database is started. Otherwise, you have to bring them online again (you have 24 RBS!).

db_block_size is a important parameter, you should includ it here.

Normally, you don't need to change defaul tablespace for sys and system, they are SYSTEM by default if you create one. If you do want to change them, you should do so before you run those catXX.sql. 
 

你可能感兴趣的:(完整的手工建立ORACLE数据库步骤)