根据https://blog.csdn.net/qq_24058757/article/details/88220437
步骤操作后总结整理的自己的新建实例过程
内存检查,应该没啥问题,内存小了的话,注意一下挂载的情况吧
[oracle@oracledb ~]$ grep -i memtotal /proc/meminfo
MemTotal: 16265868 kB
设置ORACLE的SID为我们要新建的实例
#切换到oracle用户环境
[root@oracledb ~]# su oracle
#本次创建的ORACLE的SID为tfcpzx
[oracle@oracledb ~]$ export ORACLE_SID=tfcpzx
#打印当前ORACLE的SID
[oracle@oracledb ~]$ echo $ORACLE_SID
tfcpzx
如果echo $ORACLE_SID查到的值不是新设置的SID
可以修改.bash_profile里面的SID
#上述操作没成功的执行这步
#进入根目录
[oracle@oracledb ~]$ cd ~
#编辑.bash_profile,修改其中的export ORACLE_SID=tfcpzx
[oracle@oracledb ~]$ vi .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
umask 022
export ORACLE_HOSTNAME=oracledb
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/
export ORACLE_SID=tfcpzx #修改成你新建的实例名
export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH
export LC_ALL="en_US"
export LANG="en_US"
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
".bash_profile" 24L, 556C
按i,进入编辑模式,进行修改完毕后,按ESC退出编辑,输入:wq保存并退出
然后重新加载配置
#重新加载配置
[oracle@oracledb ~]$ source .bash_profile
#选择新建的实例SID
[oracle@oracledb ~]$ export ORACLE_SID=tfcpzx
[oracle@oracledb ~]$ echo $ORACLE_SID
tfcpzx
查看无误
#将tfcpzx换成自己的SID
[oracle@oracledb ~]$ mkdir -p $ORACLE_BASE/admin/tfcpzx/{a,b,c,u}dump
[oracle@oracledb ~]$ mkdir -p $ORACLE_BASE/admin/tfcpzx/pfile
[oracle@oracledb ~]$ mkdir -p $ORACLE_BASE/oradata/tfcpzx
这里一定要注意控制文件的生成
等下在下面创建新的实例的初始文件时,注意文件的这里(可以先看下面创建新实例的初始化文件,把注意事项写前面是怕你们直接新建初始化文件了)
control_files = (ora_control3, ora_control4)
这里写的两个控制文件一定不要和当前库中其他的实例的控制文件重复了!!!
检查是否重复的方法:
可以进入cd $ORACLE_HOME/dbs目录下检查,有了的(ora_control数字 就不要写这个了,换一个大一点的,如下已经存在的ora_control数字 控制文件就不要用了
[oracle@oracledb ~]$ cd $ORACLE_HOME/dbs
[oracle@oracledb dbs]$ ls
ora_control4 ora_control9 hc_tfcpzx.dat lkTFCPZX
hc_tgpt.dat lkTGPT orapwtfcpzx ora_control10 orapwtgpt init.ora ora_control3 inittfcpzx.ora ora_control5 inittgpt.ora ora_control6
另外最好再去看看这个目录下,其他实例的初始化文件比如其他的 init实例名.ora,
cat init其他实例名.ora
看看其他实例的control_files = (ora_control3, ora_control4)这里写的多少,其他实例初始化文件用到了的控制文件避免取名重复!!!
[oracle@oracledb dbs]$ cat inittgpt.ora
#
# $Header: rdbms/admin/init.ora /main/23 2009/05/15 13:35:38 ysarig Exp $
#
# Copyright (c) 1991, 1997, 1998 by Oracle Corporation
# NAME
# init.ora
# FUNCTION
# NOTES
# MODIFIED
# ysarig 05/14/09 - Updating compatible to 11.2
# ysarig 08/13/07 - Fixing the sample for 11g
# atsukerm 08/06/98 - fix for 8.1.
# hpiao 06/05/97 - fix for 803
# glavash 05/12/97 - add oracle_trace_enable comment
# hpiao 04/22/97 - remove ifile=, events=, etc.
# alingelb 09/19/94 - remove vms-specific stuff
# dpawson 07/07/93 - add more comments regarded archive start
# maporter 10/29/92 - Add vms_sga_use_gblpagfile=TRUE
# jloaiza 03/07/92 - change ALPHA to BETA
# danderso 02/26/92 - change db_block_cache_protect to _db_block_cache_p
# ghallmar 02/03/92 - db_directory -> db_domain
# maporter 01/12/92 - merge changes from branch 1.8.308.1
# maporter 12/21/91 - bug 76493: Add control_files parameter
# wbridge 12/03/91 - use of %c in archive format is discouraged
# ghallmar 12/02/91 - add global_names=true, db_directory=us.acme.com
# thayes 11/27/91 - Change default for cache_clone
# jloaiza 08/13/91 - merge changes from branch 1.7.100.1
# jloaiza 07/31/91 - add debug stuff
# rlim 04/29/91 - removal of char_is_varchar2
# Bridge 03/12/91 - log_allocation no longer exists
# Wijaya 02/05/91 - remove obsolete parameters
#
##############################################################################
# Example INIT.ORA file
#
# This file is provided by Oracle Corporation to help you start by providing
# a starting point to customize your RDBMS installation for your site.
#
# NOTE: The values that are used in this file are only intended to be used
# as a starting point. You may want to adjust/tune those values to your
# specific hardware and needs. You may also consider using Database
# Configuration Assistant tool (DBCA) to create INIT file and to size your
# initial set of tablespaces based on the user input.
###############################################################################
# Change '' to point to the oracle base (the one you specify at
# install time)
db_name='tgpt'
memory_target=1G
processes = 150
audit_file_dest='/u01/app/oracle/admin/tgpt/adump'
audit_trail ='db'
db_block_size=8192
db_domain=''
#db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
db_recovery_file_dest_size=2G
diagnostic_dest='/u01/app/oracle'
dispatchers='(PROTOCOL=TCP) (SERVICE=tgptXDB)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
# You may want to ensure that control files are created on separate physical
# devices
control_files = (ora_control5, ora_control6) #检查该目录下其他实例初始化文件的这里,确保不会和其他实例的初始化生成的控制文件重名!!!
compatible ='11.2.0'
[oracle@oracledb ~]$ cd $ORACLE_HOME/dbs
[oracle@oracledb dbs]$ ll
total 57556
-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora
#复制初始化文件,命名规则init+实例名.ora
[oracle@oracledb dbs]$ cp init.ora inittfcpzx.ora
[oracle@oracledb dbs]$ ls
init.ora inittfcpzx.ora
#编辑,将换成对应的绝对路径,不知道的可以通过echo $ORACLE_BASE命令查看
[oracle@oracledb dbs]$ vi inittfcpzx.ora
db_name='tfcpzx' #换成自己的SID
memory_target=1G
processes = 150
audit_file_dest='/u01/app/oracle/admin/tfcpzx/adump'#替换成自己的
audit_trail ='db'
db_block_size=8192
db_domain=''
db_recovery_file_dest='/u01/app/oracle/fash_recovery_area' #替换成自己的
db_recovery_file_dest_size=2G
diagnostic_dest='/u01/app/oracle' #替换成自己的
dispatchers='(PROTOCOL=TCP) (SERVICE=tfcpzxDB)'#tfcpzxDB将替换成自己的SID+DB
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
# You may want to ensure that control files are created on separate physical
# devices
control_files = (ora_control3, ora_control4) #改成在$ORACLE_HOME/dbs下不存在的即可,如果生成失败,会生成这两个文件,下次生成就需要删除已经生成的,或者将这里的数值增加(防止文件已经存在)
compatible ='11.2.0'
修改sys用户的密码为sys
#将orapwtfcpzx的tfcpzx改成自己的SID,password=123456是设置密码,如果设置的密码是字符要加双引号,如"password"
[oracle@oracledb dbs]$ orapwd file=$ORACLE_HOME/dbs/orapwtfcpzx password=123456 entries=5 force=y
#进入到oradata自己的实例下
[oracle@oracledb dbs]$ cd $ORACLE_BASE/oradata/tfcpzx
#创建文件,文件信息里面的路径注意替换为自己实例的
#我这里是在根目录下的data里,一般是在/u01/oracle/oradata/自己的实例/ 目录下的
[oracle@oracledb dbs]$ vi createdb.sql
create database tfcpzx #替换
MAXINSTANCES 1
MAXLOGHISTORY 1
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXDATAFILES 100
DATAFILE
'/data/oracle/oradata/tfcpzx/system01.dbf' size 100m reuse autoextend on next 1m maxsize unlimited extent management local
sysaux datafile
'/data/oracle/oradata/tfcpzx/sysaux01.dbf' size 100m reuse autoextend on next 1m maxsize unlimited
default temporary tablespace TEMP tempfile
'/data/oracle/oradata/tfcpzx/temp01.dbf' size 20m reuse autoextend on next 640k maxsize unlimited
undo tablespace UNDOTBS1 datafile
'/data/oracle/oradata/tfcpzx/undo01.dbf' size 20m reuse autoextend on next 5M maxsize unlimited
logfile
GROUP 1 ('/data/oracle/oradata/tfcpzx/redo1.dbf') size 10m,
GROUP 2 ('/data/oracle/oradata/tfcpzx/redo2.dbf') size 10m,
GROUP 3 ('/data/oracle/oradata/tfcpzx/redo3.dbf') size 10m
CHARACTER SET ZHS16GBK
NATIONAL CHARACTER SET AL16UTF16
;
#切换到oracle的根目录
[oracle@oracledb ~]$ cd ~
#打印当前ORACLE的SID,如果不是或没显示,就按第一步进行选择到新建的实例下
[oracle@oracledb ~]$ echo $ORACLE_SID
tfcpzx
#连接数据库
[oracle@oracledb ~]$ sqlplus / as sysdba
#当前数据库并未建立,所以通过startup nomount只启动实例
SQL> startup nomount
SQL> @$ORACLE_BASE/oradata/tfcpzx/createdb.sql#替换成自己的SID路径
SQL> @?/rdbms/admin/catalog.sql;#直接执行这句话,需要时间,请等待结束标志再操作
SQL> @?/rdbms/admin/catproc.sql;#直接执行这句话,需要时间,请等待结束标志再操作
SQL> @?/rdbms/admin/catexp.sql;#直接执行这句话,需要时间,请等待结束标志再操作
#上述操作执行完毕后quit退出sqlplus
拓展:
startup nomount 只是启动了实例而没有启动数据库,
startup mount 启动了实例,并加载了数据库,但是数据库没有打开,
startup 最全的操作,实例,数据库加载,数据库打开都完成
catalog.sql 该脚本用户创建oracle动态性能视图,比如v s e s s i o n , v session,v session,vsession_wait,v$transactoin等,这类性能视图主要用于监控oracle实例运行的状态
创建以下项目的对象
catproc.sql 脚本建立 PL/SQL 功能的使用此外它创建几个可用于扩展RDBMS 功能的 PL/SQL 程序包catproc.sql 脚本还为以下项目创建其它程序包和视图
catexp.sql EXPORT需要的VIEW是由CATEXP.SQL创建,这些内部VIEW用于EXPORT组织DUMP文件中数据格式。大部分VIEW用于收集创建DDL语句的,其他的主要供ORACLE开发人员用
[oracle@oracledb ~]$ cd $ORACLE_HOME/network/admin
[oracle@oracledb admin]$ ls
listener.ora samples shrept.lst sqlnet.ora tnsnames.ora
[oracle@oracledb admin]$ vi tnsnames.ora
[oracle@oracledb admin]$ vi listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = oracledb)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
#将tfcpzx替换成自己的SID,将HOST替换为自己的IP,1521是默认的oracle端口,如果改了改成你自己的端口,下同
tfcpzx =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.50)(PORT = 1521))
)
)
)
#将tfcpzx替换成自己的SID,将HOST替换为自己的IP,目录改成自己的ORACLE_HOME(自己oracle的安装目录)
SID_LIST_tfcpzx =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = tfcpzx)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0)
(SID_NAME = tfcpzx)
)
)
#这个一般自带,不用改,HOST写自己的主机ip
LISTENER_FATPASE =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracledb)(PORT = 1521))
#这里要指明启动哪个数据库实例的监听
[oracle@oracledb adminl start tfcpzx
#查看监听状态lsnrctl status
[oracle@oracledb admin]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 18-MAY-2021 17:43:51
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 18-MAY-2021 14:21:58
Uptime 0 days 3 hr. 21 min. 53 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/oracledb/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracledb)(PORT=1521)))
Services Summary...
Service "tfcpzx" has 1 instance(s).
Instance "tfcpzx", status READY, has 1 handler(s) for this service...
Service "tfcpzxDB" has 1 instance(s).
Instance "tfcpzx", status READY, has 1 handler(s) for this service...
The command completed successfully
#拓展,无需操作
#停止监听,全部关闭
[oracle@oracledb admin]$ lsnrctl stop
#启动监听,全部启动
[oracle@oracledb admin]$ lsnrctl start
#切换到oracle的根目录
[oracle@oracledb ~]$ cd ~
#打印当前ORACLE的SID,如果不是或没显示,就按第一步进行选择到新建的实例下
[oracle@oracledb ~]$ echo $ORACLE_SID
tfcpzx
#连接数据库
[oracle@oracledb ~]$ sqlplus / as sysdba
#关闭服务,刚才开启了实例的,现在这里全部关闭
SQL> shutdown
#启动服务
SQL> startup
启动服务完毕后,就可以进行PLSQL连接了
我们创建的密码是 sys用户,密码为我们前面设置的123456
如果密码不对
可以在linux服务器上修改用户密码
#连接数据库
[oracle@oracledb ~]$ sqlplus / as sysdba
#修改密码,字符串要加双引号,sys为DBA用户,需要加as sysdba,其他的用户不需要
SQL> alter user sys identified by 123456 as sysdba;