当前位置:编程学习 > php >>

UNIX下ORACLE数据库的创建

答案:创建数据库虽说是一件很平常的工作,在ORACLE的参考文档中也有一定的描述,但现实中确有很多人都不会,一方面是因为平时很少有这样的机会让你去做,而真有了这样的机会让你做的时候,可能又手忙脚乱的不知道如何下手,本文将为你提供一个完整的参考。

详细步骤如下:

第一步:准备工作

1、 环境变量:
ox1> more .profile_oracyx
# 这部分建议提供
PATH=/data4/ora817/app/oracle/product/8.1.7/bin:/data4/ora817/bin::/usr/bin:.
ORACLE_BASE=/data4/ora817/app/oracle
ORACLE_SID=oracyx
ORA_NLS33=/data4/ora817/app/oracle/product/8.1.7/ocommon/nls/admin/data
ORACLE_HOME=/data4/ora817/app/oracle/product/8.1.7

# 这部分根据你的具体环境,不过有的参数在数据库建成后最好还是明确写出来,
# 如:LD_LIBRARY_PATH等,这样自己看起来会更清楚些。
LD_LIBRARY_PATH=/data4/ora817/app/oracle/product/8.1.7/lib:/usr/lib
TNS_ADMIN=/data4/ora817/app/oracle/product/8.1.7/network/admin
USER=ora817
NLS_LANG=american_america.zhs16cgb231280
LOGNAME=ora817
ORA_DB=/data4/ora817/app/oracle/product/8.1.7/dbs
TERM=vt100
HOME=/data4/ora817
ORACLE_TERM=vt100
SHELL=/bin/ksh
DISPLAY=ox1:0.0

2、参数文件
ox1> pwd
/data4/ora817/app/oracle/product/8.1.7/dbs
ox1> cp init.ora initoracyx.ora
ox1> vi initoracyx.ora
# --------------------------BEGIN---------------------------------------------------------
# db_name是唯一一个需要在建库时候提供的参数,
# 但通常以下参数都会做部分调整的
db_name = "oracyx"
instance_name = oracyx
service_names = oracyx
control_files = ('/data4/ora817/oradata/oracyx/control1.ctl', '/data2/oradata/or
acyx/control2.ctl','/data5/oradata/oracyx/control3.ctl')
open_cursors = 1000
max_enabled_roles = 40
db_block_buffers = 18800
shared_pool_size = 204800000
java_pool_size = 0
log_checkpoint_interval = 1000000000
log_checkpoint_timeout = 1800
processes = 2000
log_buffer = 2048000
timed_statistics = true
max_dump_file_size = 10000
log_archive_start = true
log_archive_dest_1 = "location=/data5/archive/oracyx"
log_archive_format = arch_%t_%s.arc
global_names = false
background_dump_dest = /data4/ora817/app/oracle/admin/oracyx/bdump
background_core_dump = partial
core_dump_dest = /data4/ora817/app/oracle/admin/oracyx/cdump
shadow_core_dump = none
user_dump_dest = /data4/ora817/app/oracle/admin/oracyx/udump
db_block_size = 8192
remote_login_passwordfile = exclusive
os_authent_prefix = ""
distributed_transactions = 1500
compatible = "8.1.7.0.0"
sort_area_size = 1024000
sort_area_retained_size = 1024000
db_files = 400
db_file_multiblock_read_count = 16
parallel_max_servers = 8
lm_ress=900000
lm_locks=1500000
session_cached_cursors = 20
transactions_per_rollback_segment = 10
db_block_lru_latches = 6
instance_number = 1
resource_limit=TRUE
# --------------------------END-----------------------------------------------------------

3、密码文件:
ox1> pwd
/data4/ora817/app/oracle/product/8.1.7/dbs
ox1> orapwd file=orapworacyx password=cyx entries=10

值得注意的是,oracle密码文件的文件名是有严格规范的:orapw[sid]。默认的查找顺序是:先找orapwsid,再找orapw,如果同一台机子上有两个数据库,为了区分起见必须有一个要指明SID。

同时不要忘了确认sqlnet.ora含如下内容:
sqlnet.authentication_services = (none)

当然你也可以不用密码文件,那么这一步就可以省略了。

4、准备目录:
ORACLE真的很笨,不会自己建立子目录,所以我们不得不在开始建库之前将所有数据文件存放的目录先建好,这里建的目录有:
/data2/oradata/oracyx
/data3/oradata/oracyx
/data4/ora817/oradata/oracyx/
/data5/oradata/oracyx
/data6/oradata/oracyx
/data7/oradata/oracyx
/data4/ora817/app/oracle/admin/oracyx/bdump
/data4/ora817/app/oracle/admin/oracyx/udump
/data4/ora817/app/oracle/admin/oracyx/cdump


第二步:开始建库

1、 建立基本数据库文件:

在本部分中将建立基本的数据库文件,包括control file, system data file和online redo log file。具体脚本如下:

ox1> more cdb1_base.sh
#!/bin/sh
#---------------------------------BEGIN--------------------------------------------------
ORACLE_SID=oracyx export ORACLE_SID
ORACLE_HOME=/data4/ora817/app/oracle/product/8.1.7 export ORACLE_HOME

/data4/ora817/app/oracle/product/8.1.7/bin/svrmgrl<< EOF
connect internal/cyx
spool /data4/ora817/cyx/cdb/crdb1.log
startup nomount pfile='/data4/ora817/app/oracle/product/8.1.7/dbs/initoracyx.ora'

CREATE DATABASE "oracyx"
CONTROLFILE REUSE
maxdatafiles 254
maxinstances 8
maxloghistory 100
maxlogmembers 2
maxlogfiles 64
character set ZHS16CGB231280
national character set ZHS16CGB231280
DATAFILE '/data4/ora817/oradata/oracyx/system.dbf'
SIZE 240M REUSE AUTOEXTEND OFF

logfile '/data4/ora817/oradata/oracyx/log1.rdo' SIZE 4M REUSE ,
'/data4/ora817/oradata/oracyx/log2.rdo' SIZE 4M REUSE ,
'/data4/ora817/oradata/oracyx/log3.rdo' SIZE 4M REUSE;

disconnect
spool off
exit
EOF
#---------------------------------END----------------------------------------------------

2、 建立其它表空间

此部分首先对系统表空间作适当的修改,然后开始创建其它表空间,详细脚本如下:

ox1> more cdb2_storage.sh
#!/bin/sh
#----------------------BEGIN--------------------------------------------------
ORACLE_SID=oracyx export ORACLE_SID
/data4/ora817/app/oracle/product/8.1.7/bin/svrmgrl << EOF
spool /data4/ora817/cyx/cdb/crdb2.log
connect internal/cyx

REM ********** ALTER SYSTEM TABLESPACE *********
ALTER TABLESPACE SYSTEM
DEFAULT STORAGE (
INITIAL 640K NEXT 640K MINEXTENTS 1
MAXEXTENTS UNLIMITED PCTINCREASE 0);
ALTER TABLESPACE SYSTEM MINIMUM EXTENT 64K;

REM ********** TABLESPACE FOR TOOLS**********
CREATE TABLESPACE TOOLS DATAFILE '/data4/ora817/oradata/oracyx/tools_01.dbf'
SIZE 4000M REUSE AUTOEXTEND OFF
MINIMUM EXTENT 512K
DEFAULT STORAGE ( INITIAL 512K NEXT 512K MINEXTENTS 8 MAXEXTENTS 4096);

REM ********** TABLESPACE FOR INDX1 **********
CREATE TABLESPACE INDX1 DATAFILE '/data2/oradata/oracyx/indx1_01.dbf'
SIZE 4000M REUSE AUTOEXTEND OFF
MINIMUM EXTENT 512K
DEFAULT STORAGE ( INITIAL 512K NEXT 512K MINEXTENTS 8 MAXEXTENTS 4096);

REM ********** TABLESPACE FOR USER**********
CREATE TABLESPACE USER1 DATAFILE '/data6/oradata/oracyx/user1_01.dbf'
SIZE 4000M REUSE AUTOEXTEND OFF
MINIMUM EXTENT 512K
DEFAULT STORAGE ( INITIAL 512K NEXT 512K MINEXTENTS 8 MAXEXTENTS 4096);

REM ********** TABLESPACE FOR TEMP **********
CREATE TABLESPACE TEMP DATAFILE '/data7/oradata/oracyx/temp_01.dbf'
SIZE 4000M REUSE AUTOEXTEND OFF
MINIMUM EXTENT 512K
DEFAULT STORAGE ( INITIAL 512K NEXT 512K MINEXTENTS 8 MAXEXTENTS 4096);

REM ********** TABLESPACE FOR RBS **********
CREATE TABLESPACE RBS DATAFILE '/data3/oradata/oracyx/rbs1_1.dbf'
SIZE 4000M REUSE AUTOEXTEND OFF
MINIMUM EXTENT 512K
DEFAULT STORAGE ( INITIAL 512K NEXT 512K MINEXTENTS 8 MAXEXTENTS 4096);

REM **** Creating Six Rollback Segments ****************
CREATE PUBLIC ROLLBACK SEGMENT RBS_01 TABLESPACE RBS
STORAGE (INITIAL 10m NEXT 10m MINEXTENTS 20 OPTIMAL 200m);
ALTER ROLLBACK SEGMENT RBS_01 ONLINE;

CREATE PUBLIC ROLLBACK SEGMENT RBS_02 TABLESPACE RBS
STORAGE (INITIAL 10m NEXT 10m MINEXTENTS 20 OPTIMAL 200m);
ALTER ROLLBACK SEGMENT RBS_02 ONLINE;

CREATE PUBLIC ROLLBACK SEGMENT RBS_03 TABLESPACE RBS
STORAGE (INITIAL 10m NEXT 10m MINEXTENTS 20 OPTIMAL 200m);
ALTER ROLLBACK SEGMENT RBS_03 ONLINE;

CREATE PUBLIC ROLLBACK SEGMENT RBS_04 TABLESPACE RBS
STORAGE (INITIAL 10m NEXT 10m MINEXTENTS 20 OPTIMAL 200m);
ALTER ROLLBACK SEGMENT RBS_04 ONLINE;

CREATE PUBLIC ROLLBACK SEGMENT RBS_05 TABLESPACE RBS
STORAGE (INITIAL 10m NEXT 10m MINEXTENTS 20 OPTIMAL 200m);
ALTER ROLLBACK SEGMENT RBS_05

上一个:SQL Server和Oracle防止数据锁定的比较
下一个:HP-UX下ORACLE 8I的安装与配置

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,