Oracle新增实例主要分为5步:创建实例目录,创建密码文件,创建参数文件,创建建库脚本并建库,创建数据字典。
其中,需要特别注意2点:
· 目录的权限,即用户和所属用户组都要是oracle。可以切换到已存在的oracle用户或者以root创建,然后赋权。
· 创建实例的时候指定编码。
下面以 Oracle 12.1.0为例,开始创建:
说明:
· 此服务器上已经有一个正常运行的oracle实例cms,开机自启动,一个监听。
· 已有一个用户oracle,所属用户组oinstall。
· oracle环境变量:
[oracle@localhost admin]$ echo $ORACLE_BASE
/home/oracle/app/oracle
[oracle@localhost admin]$ echo $ORACLE_SID
cms
· 新建的实例叫mydb
1 切换到oracle用户,创建实例目录,这些目录都是ORACLE进程遇到错误或用户手动TRACE时或数据存放需要的:
【注意:下面的红色地方必须为要新建的实例的名字。】
[root@centoscms ~]# su - oracle
[oracle@centoscms oradata]$ ORACLE_SID=mydb
[oracle@centoscms oradata]$ export ORACLE_SID
[oracle@centoscms oradata]$ echo $ORACLE_SID
[oracle@centoscms oradata]$ mydb
[oracle@centoscms oradata]$ mkdir -p $ORACLE_BASE/admin/mydb/adump;mkdir -p $ORACLE_BASE/admin/mydb/bdump;
[oracle@centoscms oradata]$ mkdir -p $ORACLE_BASE/admin/mydb/cdump;mkdir -p $ORACLE_BASE/admin/mydb/udump;
[oracle@centoscms oradata]$ mkdir -p $ORACLE_BASE/admin/mydb/pfile;mkdir -p $ORACLE_BASE/oradata/mydb;
2 创建密码文件,红色地方为密码文件的名字,规则是orapw+实例名,此时即为orapwmydb:
【注意:有可能不同的版本密码文件所在位置不同,找到dbs目录,并看里边是否已经有已经存在的实例的密码文件。以此例,此dbs目录下已经orapwcms文件。】
[oracle@centoscms oradata]$ orapwd file=$ORACLE_BASE/product/12.1.0/dbhome_1/dbs/orapwmydb password=turboblog entries=5 force=y
3 创建.ora参数文件,所在目录和第2步中的相同。文件名规则为init+实例名,此时即为initmydb.ora。将已经存在的实例的参数文件复制修改即可。
比如,此目录中已有一个已存在实例的参数文件,这里为initcms.ora。
[oracle@centoscms oradata]$ cd $ORACLE_BASE/product/12.1.0/dbhome_1/dbs/
[oracle@centoscms dbs]$ cp initcms.ora initmydb.ora
[oracle@centoscms dbs]$ vi initmydb.ora
修改文件内容,注意红色地方都需要修改为我们新建的实例名mydb。
【注意:这些目录都是在第一步中已经建好的,都是应该存在的。undo_tablespace的值需要记住,创建数据库实例的时候需要用到】
原文件内容如下:
##############################################################################
# Copyright (c) 1991, 2013 by Oracle Corporation
##############################################################################
###########################################
# Cache and I/O
###########################################
db_block_size=8192
###########################################
# Cursors and Library Cache
###########################################
open_cursors=300
###########################################
# Database Identification
###########################################
db_domain=""
db_name="orcl"
###########################################
# File Configuration
###########################################
db_create_file_dest="/home/oracle/app/oracle/oradata"
db_recovery_file_dest="/home/oracle/app/oracle/fast_recovery_area"
db_recovery_file_dest_size=4560m
###########################################
# Miscellaneous
###########################################
compatible=12.1.0.2.0
diagnostic_dest=/home/oracle/app/oracle
###########################################
# Processes and Sessions
###########################################
processes=300
###########################################
# SGA Memory
###########################################
sga_target=2356m
###########################################
# Security and Auditing
###########################################
audit_file_dest="/home/oracle/app/oracle/admin/orcl/adump"
audit_trail=db
remote_login_passwordfile=EXCLUSIVE
###########################################
# Shared Server
###########################################
dispatchers="(PROTOCOL=TCP) (SERVICE=orclXDB)"
###########################################
# Sort, Hash Joins, Bitmap Indexes
###########################################
pga_aggregate_target=785m
###########################################
# System Managed Undo and Rollback Segments
###########################################
undo_tablespace=UNDOTBS1
control_files=("/home/oracle/app/oracle/oradata/ORCL/controlfile/o1_mf_dhfzxq93_.ctl", "/home/oracle/app/oracle/fast_recovery_area/ORCL/controlfile/o1_mf_dhfzxqld_.ctl")
修改后:
##############################################################################
# Copyright (c) 1991, 2013 by Oracle Corporation
##############################################################################
###########################################
# Cache and I/O
###########################################
db_block_size=8192
###########################################
# Cursors and Library Cache
###########################################
open_cursors=300
###########################################
# Database Identification
###########################################
db_domain=""
db_name="mydb"
###########################################
# File Configuration
###########################################
db_create_file_dest="/home/oracle/app/oracle/oradata"
db_recovery_file_dest="/home/oracle/app/oracle/fast_recovery_area"
db_recovery_file_dest_size=4560m
###########################################
# Miscellaneous
###########################################
compatible=12.1.0.2.0
diagnostic_dest=/home/oracle/app/oracle
###########################################
# Processes and Sessions
###########################################
processes=300
###########################################
# SGA Memory
###########################################
sga_target=2356m
###########################################
# Security and Auditing
###########################################
audit_file_dest="/home/oracle/app/oracle/admin/mydb/adump"
audit_trail=db
remote_login_passwordfile=EXCLUSIVE
###########################################
# Shared Server
###########################################
dispatchers="(PROTOCOL=TCP) (SERVICE=mydbXDB)"
###########################################
# Sort, Hash Joins, Bitmap Indexes
###########################################
pga_aggregate_target=785m
###########################################
# System Managed Undo and Rollback Segments
###########################################
undo_tablespace=UNDOTBS3
control_files=("/home/oracle/app/oracle/oradata/ORCL/controlfile/o1_mf_dhfzxq93_.ctl", "/home/oracle/app/oracle/fast_recovery_area/ORCL/controlfile/o1_mf_dhfzxqld_.ctl")
4 创建建库脚本:
创建数据库,注意红色字体文件路径,并且还有数据库编码:
[oracle@localhost dbs]$ sqlplus /nolog
SQL> connect /as sysdba
Connected.
SQL> SHUTDOWN immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount pfile=/home/oracle/app/oracle/product/12.1.0/dbhome_1/dbs/initmydb.ora
ORACLE instance started.
Total System Global Area 608174080 bytes
Fixed Size 1220820 bytes
Variable Size 163581740 bytes
Database Buffers 436207616 bytes
Redo Buffers 7163904 bytes
SQL> CREATE DATABASE mydb
2 CONTROLFILE REUSE
3 LOGFILE GROUP 1 ('/home/oracle/app/oracle/oradata/mydb/redo01.log') SIZE 10M REUSE,
4 GROUP 2 ('/home/oracle/app/oracle/oradata/mydb/redo02.log') SIZE 10M REUSE,
5 GROUP 3 ('/home/oracle/app/oracle/oradata/mydb/redo03.log') SIZE 10M REUSE
6 DATAFILE '/home/oracle/app/oracle/oradata/mydb/system01.dbf' SIZE 500M
7 EXTENT MANAGEMENT LOCAL
8 sysaux datafile '/home/oracle/app/oracle/oradata/mydb/sysaux01.dbf' size 120M reuse autoextend on next 10240K maxsize unlimited
9 UNDO TABLESPACE UNDOTBS3 DATAFILE '/home/oracle/app/oracle/oradata/mydb/undotbs01.dbf' SIZE 500M
10 DEFAULT TEMPORARY TABLESPACE TEMP
11 TEMPFILE '/home/oracle/app/oracle/oradata/mydb/temp01.dbf' SIZE 500M
12 EXTENT MANAGEMENT LOCAL UNIFORM SIZE 10M
13 NOARCHIVELOG
14 MAXDATAFILES 1000
15 CHARACTER SET UTF8
16 NATIONAL CHARACTER SET UTF8
17 MAXLOGFILES 10;
Database created.
5 创建数据字典:
SQL> @?/rdbms/admin/catalog.sql;
SQL> @?/rdbms/admin/catproc.sql;
SQL> @?/sqlplus/admin/pupbld.sql;
SQL> exit;
6 启动数据库,保证目前的实例是新增的实例:
[oracle@centoscms ~]$ ORACLE_SID=mydb
[oracle@centoscms ~]$ export ORACLE_SID
[oracle@centoscms ~]$ echo $ORACLE_SID
mydb
SQL> startup force;
ORACLE instance started.
Total System Global Area 608174080 bytes
Fixed Size 1220820 bytes
Variable Size 167776044 bytes
Database Buffers 432013312 bytes
Redo Buffers 7163904 bytes
Database mounted.
Database opened.
用system帐号登录,查看默认用户,默认密码是manager :
SQL> conn system/manager;
Connected.
SQL> select username from all_users;
USERNAME
------------------------------
DBSNMP
TSMSYS
DIP
OUTLN
SYSTEM
SYS
6 rows selected.
此时,一个新的oracle实例就添加完毕了,很多时候我们需要所有的实例都是开机自启动,则需要做以下的修改:
新增下面一行
[root@centoscms oracle]# vi /etc/oratab
orcl:/home/oracle/app/oracle/product/12.1.0/dbhome_1:Y
mydb:/home/oracle/app/oracle/product/12.1.0/dbhome_1:Y
然后拷贝一份:
[root@centoscms oracle]# cp /etc/oratab /var/opt/oracle/oratab
重启服务器:
[root@centoscms oracle]# reboot
如果需要远程链接,监听中增加此实例即可。修改listener.ora:
[root@centoscms oracle]# su - oracle
[oracle@centoscms ~]$ cd $ORACLE_BASE/product/12.1.0/dbhome_1/network/admin
[oracle@centoscms ~]$ vi listener.ora
Listener.ora原文件为:
# listener.ora Network Configuration File: /home/oracle/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
修改后为:
# listener.ora Network Configuration File: /home/oracle/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST=
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
(ADDRESS_LIST=
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /home/oracle/app/oracle/product/12.1.0/dbhome_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = cms)
(ORACLE_HOME = /home/oracle/app/oracle/product/12.1.0/dbhome_1)
(SID_NAME = cms)
)
(SID_DESC =
(GLOBAL_DBNAME = mydb)
(ORACLE_HOME = /home/oracle/app/oracle/product/12.1.0/dbhome_1)
(SID_NAME = mydb)
)
)
重启oracle就可以连上啦。。。
注:其中出现报错TNS-01201: Listener cannot find executable /home/oracle/app/oracle/bin/oracle for SID mydb
Listener failed to start. See the error message(s) above...
是由于ORACLE_HOME = 后面的地址配错导致
备注:以上内容参考网上查找信息结合自己实践效果总结改编,有问题可以留言提问的.