Oracle 用脚本安装第二个数据库

  • 安装第二个数据库:

登录oracle用户进入家目录,添加配置环境变量:

vi .bash_profierORACLE_SID=prod2

  

 

  • 临时环境变量:
$export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1$export ORACLE_SID=prod2

  

 

  • 创建第二个数据库文件目录:
$mkdir -p /u01/app/oracle/oradata/prod2

  

 

  • 创建sys用户密码文件:
$cd /u01/app/oracle/product/11.2.0/db_1/dbs$orapwd file=orapwprod2 password=oracle 

  

  • 创建一个可读参数文件:
$vi initprod2.ora添加:DB_NAME=prod2sga_target=500Mcontrol_files=‘/u01/app/oracle/oradata/prod2/control01.ctl‘

  

 

  • 打开实例进入nomount模式,创建数据库系统proc,view ……:
SQL> sqlplus / as sysdbaSQL> startup nomount;SQL> create spfile from pfile;SQL> shutdown immediate;SQL> startup nomount;SQL> alter system set db_create_file_dest=‘/u01/app/oracle/oradata/prod2‘;SQL> create database character set AL32UTF8 extent management local;SQL> @?/rdbms/admin/catalog.sql;SQL> @?/rdbms/admin/catproc.sql;SQL> alter user system identified by oracle account unlock;SQL> conn system/oracleSQL> @?/sqlplus/admin/pupbld.sql;

  

 

  • 验证实例:

 

SQL> show parameter name; NAME TYPE VALUE------------------------------------ ----------- ------------------------------db_file_name_convert stringdb_name string prod2db_unique_name string prod2global_names boolean FALSEinstance_name string prod2lock_name_space stringlog_file_name_convert stringservice_names string prod2 

  

 

  • 多个数据库切换:. oraenv
[oracle@test ~]$ . oraenvORACLE_SID = [prod2] ? prod1The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 is /u01/app/oracle

  

 

  • 当再切入第二的环境变量的时候的,会无法自动识别oracle家目录,需手动输入地址,解决方法如下:

vi /etc/oratab(当用dbca窗口删库时,添加oratab文件后,dbca数据库列表会显示数据库名) 添加到最后一行参数:(Y代表支持dbstart和dbshut启停数据库) prod2:/u01/app/oracle/product/11.2.0/db_1:Y    

# This file is used by ORACLE utilities. It is created by root.sh# and updated by the Database Configuration Assistant when creating# a database. # A colon, ‘:‘, is used as the field terminator. A new line terminates# the entry. Lines beginning with a pound sign, ‘#‘, are comments.## Entries are of the form:# $ORACLE_SID:$ORACLE_HOME:<N|Y>:## The first and second fields are the system identifier and home# directory of the database respectively. The third filed indicates# to the dbstart utility that the database should , "Y", or should not,# "N", be brought up at system boot time.## Multiple entries with the same $ORACLE_SID are not allowed.##prod1:/u01/app/oracle/product/11.2.0/db_1:Yprod2:/u01/app/oracle/product/11.2.0/db_1:Y

  

  • 演示1:
[oracle@test ~]$ ps -ef|grep smonoracle 11062 1 0 00:25 ? 00:00:00 ora_smon_prod2oracle 12799 12285 0 02:12 pts/2 00:00:00 grep smon[oracle@test ~]$ dbshutORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle Net ListenerUsage: /u01/app/oracle/product/11.2.0/db_1/bin/dbshut ORACLE_HOMEProcessing Database instance "prod1": log file /u01/app/oracle/product/11.2.0/db_1/shutdown.logProcessing Database instance "prod2": log file /u01/app/oracle/product/11.2.0/db_1/shutdown.log[oracle@test ~]$ ps -ef|grep smon\oracle 12955 12285 0 02:12 pts/2 00:00:00 grep smon

  

 

  • 演示2:
[oracle@test ~]$ . oraenvORACLE_SID = [prod2] ? prod1The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 is /u01/app/oracle[oracle@test ~]$ dbstartORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net ListenerUsage: /u01/app/oracle/product/11.2.0/db_1/bin/dbstart ORACLE_HOMEProcessing Database instance "prod1": log file /u01/app/oracle/product/11.2.0/db_1/startup.logProcessing Database instance "prod2": log file /u01/app/oracle/product/11.2.0/db_1/startup.log[oracle@test ~]$ ps -ef|grep smonoracle 13130 1 0 02:13 ? 00:00:00 ora_smon_prod1oracle 13239 1 0 02:13 ? 00:00:00 ora_smon_prod2oracle 13390 12285 0 02:14 pts/2 00:00:00 grep smon[oracle@test ~]$ dbshutORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle Net ListenerUsage: /u01/app/oracle/product/11.2.0/db_1/bin/dbshut ORACLE_HOMEProcessing Database instance "prod1": log file /u01/app/oracle/product/11.2.0/db_1/shutdown.logProcessing Database instance "prod2": log file /u01/app/oracle/product/11.2.0/db_1/shutdown.log[oracle@test ~]$ ps -ef|grep smonoracle 13550 12285 0 02:14 pts/2 00:00:00 grep smon 

  

 

  • 监听器没有受到快捷启停命令的影响:
[oracle@test ~]$ ps -ef|grep lsnroracle 13609 1 0 02:18 ? 00:00:00 /u01/app/oracle/product/11.2.0/db_1/bin/tnslsnr LISTENER -inheritoracle 13621 12285 0 02:19 pts/2 00:00:00 grep lsnr 

  

                                                             

相关文章