Oracle的静默安装 升级和卸载 参考规范 20180912 V1
一、Oracle的安装
Oracle产品的三种安装方式分别为:
1.图形化(Java向导)安装引导
2.使用应答文件静默安装
3.直接将装好的oracle复制一份放到另一台服务器安装
注意:
#方法2和方法3的安装前提是:配置好Oracle安装所需要的前提
1、基础环境配置
无论是图形化安装,静默安装还是拷贝安装,都首先需要把基础环境配置好。
1.1 操作系统配置
环境: 在VMware中安装CentOS6.5虚拟机,在此虚拟机里面安装Oracle数据库,
CPU: 2x2=4核 (CPU大小可自定义)
内存: 4G(官方最低要求1G)
硬盘: 比如30G(Oracle EE企业版安装至少需4.29G+1.7G数据文件,硬盘大小可自定义)
系统: CentOS release 6.5 (Final) Minimal最小化安装
内核:Linux 2.6.32-431.el6.x86_64
Oracle: 11.2.0.4
1.2 检查安装目录大小
(root用户)检查虚拟内存和/tmp目录大小,待安装目录设置。
1.2.1 swap大小设置
要求如下,
Available
RAM Swap Space Required
Between 1
GB and 2 GB 1.5 times the size of
the RAM
Between 2
GB and 16 GB Equal to the size of
the RAM
More than
16 GB 16 GB
检查实际swap的大小,
[root@db
~]# free -g
total used
free shared buffers
cached
Mem: 7 7 0 0 0 5
-/+
buffers/cache: 1 5
Swap: 7 0 7
如果swap空间不足(not sufficient),
#1、用dd命令创建一个16G的文件
#比如原有的swap为3G,现在再直接用dd从磁盘中取出16G来做为swap,这样总计内存将会是19G,
[root@db
~]# dd if=/dev/zero of=/var/swapfile bs=1G count=16
#2、将它创建为Linux Swap虚拟交换文件
[root@db
~]# mkswap /var/swapfile
mkswap:
/var/swapfile: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up
swapspace version 1, size = 16777212 KiB
no label,
UUID=17af76cb-2164-4142-b6aa-5dbf88add771
#3、激活并使用/var/swapfile交换文件
[root@db
~]# swapon /var/swapfile
[root@db
~]# free -g
total used free
shared buffers cached
Mem: 125 19 105 0 0 18
-/+
buffers/cache: 1 123
Swap: 19 0 19
#4、设置系统启动后自动激活虚拟交换文件。
#cp
/etc/fstab /etc/fstab.bak && \
echo
'/var/swapfile swap swap defaults 0 0' >> /etc/fstab && \
mount -a
1.2.2
待安装目录大小
检查待安装Oracle的目录,待安装目录要有足够的空间(Oracle EE企业版安装至少需4.29G+1.7G数据文件,硬盘大小可自定义),
[root@db
~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 81G
13G 64G 17% /
tmpfs 3.9G 203M
3.7G 6% /dev/shm
/dev/sda1 485M 33M
427M 8% /boot
/dev/mapper/VolGroup-lv_home 9.9G
152M 9.2G 2% /home
1.2.3
/tmp目录大小
/tmp
目录要大于1G
注:/tmp目录不需要专门的挂载分区,大于1G的目录是oracle在安装过程中要用而已。
[root@db
~]# df -h /tmp
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 27G
8.2G 17G 33% /
1.3 检查系统架构
(root用户)检查系统架构
[root@db
~]# uname -a 或 uname -r
Linux db
2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64
GNU/Linux
[root@db
~]# cat /etc/system-release
CentOS
release 6.5 (Final)
1.4 关闭selinux和防火墙
(root用户)关闭selinux和防火墙
[root@db
~]# setenforce 0 && \
sed -i
"s/^SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config && \
iptables -F
&& \
service
iptables stop && \
chkconfig
iptables off
1.5 配置静态IP地址
需要静态IP,根据情况自定义,
[root@db
~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static"
HWADDR="00:50:56:93:50:0c"
IPV6INIT="no"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
IPADDR=192.168.xx.xx
GATEWAY=192.168.25.1
DNS1=114.114.114.114
DNS2=8.8.8.8
1.6 配置yum源
(root用户)设置163和epel的yum源,并安装基本的依赖,
setenforce
0 > /dev/null 2>&1
sed -i
"s/^SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config && \
cp
/etc/sysconfig/iptables /etc/sysconfig/iptables`date +%F_%T`
iptables -F
&& \
service
iptables save && \
service
iptables stop && \
chkconfig
iptables off && \
cp
/etc/yum.conf /etc/yum.confbak`date +%F_%T`
echo
'exclude=kernel*
exclude=centos-release*'
>> /etc/yum.conf && \
grep
exclude /etc/yum.conf && \
mkdir -p
/tmp/repobak && \
rm -rf
/tmp/repobak/* && \
cd
/etc/yum.repos.d/ && \
mv -f *
/tmp/repobak/ > /dev/null 2>&1
curl -o
/etc/yum.repos.d/CentOS6-Base-163.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
&& \
mv -f
/etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup > /dev/null
2>&1
mv -f
/etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
> /dev/null 2>&1
curl -o
/etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
&& \
rpm
--import /etc/pki/rpm-gpg/RPM* && \
yum clean
all && \
yum
makecache && \
yum
groupinfo 'Development tools' && \
yum
groupinstall -y 'Development tools' && \
yum install
wget vim man rsync openssh-clients openssl -y && \
ls -l
&& cd ~
1.7 安装依赖包
(root用户)安装软件包
[root@db
~]# yum install binutils compat-libstdc*
elfutils-libelf elfutils-libelf-devel
gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio
libaio-devel libgcc libstdc++ libstdc++-devel libgomp make numactl numactl-devel sysstat -y
[root@db
~]# yum install unixODBC unixODBC-devel -y
[root@db
~]# yum localinstall pdksh-5.2.14-30.x86_64.rpm -y
#注1:pdksh包需要单独下载(百度搜索 pdksh rpm)并使用rpm手动安装
#注2:如果安装有问题,就把ksh先卸载了,rpm -e --nodeps ksh
1.8 配置主机名和hosts
(root用户)修改主机名(自定义),添加主机名与IP对应记录,注意下面要修改为自己实际的IP和主机名,
[root@db
~]# sed -i.ori 's#^HOSTNAME=.*#HOSTNAME=centos6#g' /etc/sysconfig/network
&&\
hostname
db &&\
service
network restart &&\
echo
'192.168.xx.xx db' >> /etc/hosts &&\
grep
'HOSTNAME' /etc/sysconfig/network &&\
grep 'db'
/etc/hosts
1.9 操作系统语言环境
[root@db
~]# cp /etc/sysconfig/i18n /etc/sysconfig/i18n`date +%F_%T`
echo
'LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"'
> /etc/sysconfig/i18n
1.10 配置NTP时间同步
[root@db
~]# yes | cp -a /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum install
ntpdate -y && chkconfig ntpdate on && chkconfig --list ntpdate
yum install
-y vixie-cron && chkconfig crond on && chkconfig --list crond
&& service crond start
/usr/sbin/ntpdate
-u cn.pool.ntp.org
crontab -l
> conf
echo
"*/10 * * * * /usr/sbin/ntpdate -u cn.pool.ntp.org > /dev/null 2>&1" >>
conf && \
crontab
conf && \
rm -f conf
&& \
crontab -l
1.11
配置内核参数
(root用户)配置内核参数
[root@db
~]# vim /etc/sysctl.conf
[root@db
~]# cp /etc/sysctl.conf /etc/sysctl.conf.bak
echo 'net.ipv4.ip_forward
= 0
net.ipv4.conf.default.rp_filter
= 1
net.ipv4.conf.default.accept_source_route
= 0
kernel.sysrq
= 0
kernel.core_uses_pid
= 1
net.ipv4.tcp_syncookies
= 1
net.bridge.bridge-nf-call-ip6tables
= 0
net.bridge.bridge-nf-call-iptables
= 0
net.bridge.bridge-nf-call-arptables
= 0
kernel.msgmnb
= 65536
kernel.msgmax
= 65536
kernel.shmmax
= 8589934591
kernel.shmall
= 2097152
fs.aio-max-nr
= 1048576
fs.file-max
= 6815744
kernel.shmmni
= 4096
kernel.sem
= 250 32000 100 128
net.ipv4.ip_local_port_range
= 9000 65500
net.core.rmem_default
= 262144
net.core.rmem_max
= 4194304
net.core.wmem_default
= 262144
net.core.wmem_max
= 1048576' > /etc/sysctl.conf
/sbin/sysctl
-p
[root@db
~]# egrep -v '^#|^$' /etc/sysctl.conf | wc -l
22
[root@db
~]# /sbin/sysctl -p
net.ipv4.ip_forward
= 0
net.ipv4.conf.default.rp_filter
= 1
net.ipv4.conf.default.accept_source_route
= 0
kernel.sysrq
= 0
kernel.core_uses_pid
= 1
net.ipv4.tcp_syncookies
= 1
net.bridge.bridge-nf-call-ip6tables
= 0
net.bridge.bridge-nf-call-iptables
= 0
net.bridge.bridge-nf-call-arptables
= 0
kernel.msgmnb
= 65536
kernel.msgmax
= 65536
kernel.shmmax
= 4294967295
kernel.shmall
= 2097152
fs.aio-max-nr
= 1048576
fs.file-max
= 6815744
kernel.shmmni
= 4096
kernel.sem
= 250 32000 100 128
net.ipv4.ip_local_port_range
= 9000 65500
net.core.rmem_default
= 262144
net.core.rmem_max
= 4194304
net.core.wmem_default
= 262144
net.core.wmem_max
= 1048576
以下为说明:
kernel.shmmax:
64位linux系统:可取的最大值为物理内存值-1byte,建议值为多于物理内存的一半,一般取值大于SGA_MAX_SIZE即可,可以取物理内存-1byte。例如,如果为12GB物理内存,可取128*1024*1024*1024-1=12884901887,SGA肯定会包含在单个共享内存段中。128GB对应的是137438953471。
kernel.shmall:
该参数控制可以使用的共享内存的总页数。Linux共享内存页大小为4KB,共享内存段的大小都是共享内存页大小的整数倍。一个共享内存段的最大大小是16G,那么需要共享内存页数是16GB/4KB=16777216KB
/4KB=4194304(页)。
即16GB对应4194304,8GB对应2097152,128GB对应33554432
net.ipv4.ip_forward
= 0 #不变
net.ipv4.conf.default.rp_filter
= 1 #不变
net.ipv4.conf.default.accept_source_route
= 0 #不变
kernel.sysrq
= 0 #不变
kernel.core_uses_pid
= 1 #不变
net.ipv4.tcp_syncookies
= 1 #不变
net.bridge.bridge-nf-call-ip6tables
= 0 #不变
net.bridge.bridge-nf-call-iptables
= 0 #不变
net.bridge.bridge-nf-call-arptables
= 0 #不变
kernel.msgmnb
= 65536 #不变
kernel.msgmax
= 65536 #不变
kernel.shmmax
= 4294967295 #变
note:4*1024*1024*1024-1=4294967295 共享内存段的最大尺寸,需要小于SGA MAX SIZE,大小为shmall*页大小(4K);
kernel.shmall
= 2097152 #变note:4*1024*1024/4K*2=2097152,两倍, 1倍实际不够,控制共享内存页数
fs.aio-max-nr
= 1048576 #新增 异步I/O请求数目
fs.file-max
= 6815744 #新增 一个进程可以打开的文件句柄的最大数量
kernel.shmmni
= 4096 #新增 共享内存段的最大数量,ipcs -sa
kernel.sem
= 250 32000 100 128 #新增 设置的信号量
net.ipv4.ip_local_port_range
= 9000 65500 #新增 专用服务器模式下与用户进程通信时分配给用户的端口区间
net.core.rmem_default
= 262144 #新增 默认接收缓冲区大小
net.core.rmem_max
= 4194304 #新增 接收缓冲区最大值
net.core.wmem_default
= 262144 #新增 默认发送缓冲区大小
net.core.wmem_max
= 1048586 #新增 默认发送缓冲区大小
1.12
配置资源限制
(root用户)配置文件和进程的资源限制,
soft是指当前系统设置生效的值,而hard表明系统中所能设定的最大值,nofile是指文件句柄数,nproc是指进程数,
[root@db
~]# cp /etc/security/limits.conf /etc/security/limits.conf.bak
sed -i.bak
's/1024/102400/' /etc/security/limits.d/90-nproc.conf
ulimit -u
102400
echo
'session required pam_limits.so' >> /etc/pam.d/login
echo '
oracle soft
nproc 16000
oracle hard
nproc 16384
oracle soft
nofile 60000
oracle hard
nofile 65536
oracle soft
stack 20480
oracle hard
stack 20480
* soft
memlock unlimited
* hard
memlock unlimited' >> /etc/security/limits.conf
[root@db
~]# vim /etc/security/limits.conf
oracle soft nproc
16000 #oracle要求最小为2047
oracle hard nproc
16384 #--进程的最大数目,对oracle用户生效
oracle soft nofile
60000 #oracle要求最小为1024
oracle hard nofile
65536 #--打开文件的最大数目,对oracle用户生效
oracle soft stack
10240
oracle hard stack
10240
* soft memlock unlimited
* hard memlock unlimited #--最大锁定内存地址空间,对所有用户生效
1.13
创建用户和组
(root用户)建立必要的Oracle用户和用户组,
[root@db
~]# id oracle
id: oracle:
No such user
[root@db
~]# groupadd oinstall && groupadd dba && useradd -g oinstall -G
dba oracle && id oracle
#创建密码,密码自定义
[root@db
~]# echo "oracle" | passwd --stdin oracle
1.14
配置安装目录
(root用户)创建安装数据库软件的目录
#安装目录可自行定义,没有要求,一般推荐安装目录为/opt,/u01,或
/data等目录
#对权限来说网上有此说755
这个不用纠结,775,755都行。
#我们只需要把oracle的base目录/data/app/oracle创建好即可,ORACLE_HOME目录不需要创建 oracle会在安装时自动创建。
[root@db
~]# mkdir -p /data/app/oracle && \
mkdir -p
/data/app/oraInventory && \
mkdir -p
/data/dpdata && \
chown -R
oracle:oinstall /data/ && \
chmod -R
775 /data/
1.15
配置环境变量
root用户,
#注意一下有的是11.2.0.4/db_1,有的是 11.2.0/db_1,有的是11.2.0/dbhome_1等
[root@db
~]# cat >> /root/.bash_profile << EOF
export
ORACLE_BASE=/data/app/oracle
export
ORACLE_HOME=\$ORACLE_BASE/product/11.2.0.4/db_1
export
LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib:\$GGS_HOME
export
TNS_ADMIN=\$ORACLE_HOME/network/admin/
EOF
[root@db
~]# source /root/.bash_profile && echo $ORACLE_HOME
oracle用户,
[root@db
~]# su - oracle
[oracle@db
~]$ sed -i.ori 's/^PATH/\#PATH/g' /home/oracle/.bash_profile && \
cat
>> /home/oracle/.bash_profile << EOF
export
ORACLE_BASE=/data/app/oracle
export
ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/dbhome_1
export
ORACLE_SID=orcl
export
ORALCE_OWNER=oracle
PATH=\$PATH:\$HOME/bin:\$ORACLE_HOME/bin:\$ORACLE_HOME/OPatch:\$ORACLE_HOME/jdk/bin:/usr/bin:/usr/sbin:/sbin:/bin:/usr/local/bin:/usr/local/sbin
export PATH
export
LANG="en_US.UTF-8"
export
NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export
NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
export
LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib:\$GGS_HOME
alias
sqlplus='rlwrap sqlplus'
alias
rman='rlwrap rman'
alias
scp='scp -o StrictHostKeyChecking=no'
alias
ssh='ssh -o StrictHostKeyChecking=no'
alias
rsync='rsync -e \"ssh -o stricthostkeychecking=no\"'
EOF
#注:alias sqlplus='rlwrap
sqlplus',alias rman='rlwrap rman' 前面没有export
[oracle@db
~]$ source /home/oracle/.bash_profile
&& echo $ORACLE_HOME && echo $ORACLE_BASE && env
| grep ORA
1.16
上传安装包并解压
oracle用户上传Oracle 11.2.0.4安装软件,rlwrap-0.42.tar.gz等相应软件至/tmp 目录
[oracle@db
~]$ cd /tmp && ll
-rw-r--r--. 1 oracle oinstall 1395582860 Aug 29 19:10
p13390677_112040_Linux-x86-64_1of7.zip
-rw-r--r--. 1 oracle oinstall 1151304589 Aug 29 19:10
p13390677_112040_Linux-x86-64_2of7.zip
-rw-r--r--. 1 oracle oinstall 279608 Aug 29 19:09 rlwrap-0.42.tar.gz
[oracle@db
~]$ cd /tmp/ && \
unzip
p13390677_112040_Linux-x86-64_1of7.zip && \
unzip
p13390677_112040_Linux-x86-64_2of7.zip && \
chown -R
oracle:oinstall /tmp/database/ && \
chmod -R
775 /tmp/database/ && \
cd
/tmp/database && ll
#注意是root用户需要chown -R oracle:oinstall
/tmp/database/
1.17 安装rlwrap
(root用户) 安装rlwrap
[root@db
~]# cd /tmp && \
yum install
readline* -y && \
tar -zxvf
rlwrap-0.42.tar.gz && \
cd
rlwrap-0.42 && \
./configure
&& \
make
&& make install
2、图形化安装
(root用户)安装图形化界面:
[root@db
~]# yum groupinstall "X Window System" -y
[root@db
~]# yum groupinstall "Desktop" -y
[root@db
~]# yum groupinstall "Font" -y
[root@db
~]# yum install tigervnc -y
[root@db
~]# yum install tigervnc-server -y
[root@db
~]# vncserver #设置远程图形化桌面登录的密码后vncserver会自动启动。
You will
require a password to access your desktops.
Password:
Verify:
New 'db:1
(root)' desktop is db:1
Creating
default startup script /root/.vnc/xstartup
Starting
applications specified in /root/.vnc/xstartup
Log file is
/root/.vnc/db:1.log
[root@db
~]# chkconfig vncserver on
[root@db
~]# vim /etc/sysconfig/vncservers #此可不用设置,可忽略
最后一行加入:
VNCSERVERS="1:root"
多个用户用空格分开,并要先su - 到那个用户运行vncserver[:n]来设定配置文件和密码
Windows安装VNC viewer/realVNC (注:是VNC viewer 不是VNC)
Windows界面打开VNC Viewer,输入192.168.137.129:1
登录进去以后,
Open in
terminal,
在root用户下打开普通用户调用Xserver的权利
[root@db
Desktop]# xhost + #(打开普通用户调Xserver的权利)
这样我们就可以在终端使用oracle用户调用图形化了
调用安装程序: cd ~/database ./runInstaller
接下来就是图形化安装了:
http://www.cnblogs.com/smail-bao/p/oracle.html
在生产上我我们就只安装oracle 的产品,不建库。所以我们install database software only
后面我们在使用dbca的方式建库
我们装到最后的时候会检查一下安装环境,回提示你需要装一些什么,回提示我们少一些c包等,还有pdksh
都给他装上,还有一个提示就是swap的警告,老师说这个不用管它,就是给swap设置成0也是没有问题的
还有装到最后的时候
save
Response File
保存的就是应答文件,这个我们可以使用这个文件使用静默方式来安装
3、静默的安装
说到静默安装,就不得不提到响应文件(Response File),在Oracle安装目录下会提供响应文件模板,这个响应文件其实就是配置文件,里面可以配置一些安装细节,在DBCA图形界面中能够看到的安装选项,在响应文件中都有体现。你可以通过响应文件来设置安装企业版、个人版、标准版、安装的语言包,字符集等。
解压后得到database目录,其中包含response目录,该目录中有三个rsp文件,用来作为静默安装时的应答文件的模板。
三个文件作用分别是: db_install.rsp:安装应答 dbca.rsp:创建数据库应答 netca.rsp:建立监听、本地服务名等网络设置的应答
3.1 静默安装数据库软件
3.1.1 配置db_install.rsp
要注意的地方为ORACLE_HOSTNAME=xx。
[root@db
~]# su - oracle
[oracle@db
~]$ cd /tmp/database && ll
[oracle@db
database]$ cd /tmp/database/response && ll
total 80
-rwxrwxr-x
1 oracle oinstall 44533 Aug 27 2013
dbca.rsp
-rwxrwxr-x
1 oracle oinstall 25116 Aug 27 2013
db_install.rsp
-rwxrwxr-x
1 oracle oinstall 5871 Aug 27 2013 netca.rsp
[oracle@db
response]$ vim db_install.rsp
#注:可以通过egrep -v '^#|^$'
/tmp/database/response/db_install.rsp查看。
[oracle@db
response]$ cp /tmp/database/response/db_install.rsp /tmp/database/response/db_install.rsp.bak
cat >
/tmp/database/response/db_install.rsp << EOF
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=sdata01
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/data/app/oraInventory
SELECTED_LANGUAGES=en,zh_CN,th,zh_TW
ORACLE_HOME=/data/app/oracle/product/11.2.0.4/db_1
ORACLE_BASE=/data/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.EEOptionsSelection=true
oracle.install.db.optionalComponents=oracle.rdbms.partitioning:11.2.0.4.0,oracle.oraolap:11.2.0.4.0,oracle.rdbms.dm:11.2.0.4.0,oracle.rdbms.dv:11.2.0.4.0,oracle.rdbms.lbac:11.2.0.4.0,oracle.rdbms.rat:11.2.0.4.0
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oinstall
oracle.install.db.CLUSTER_NODES=
oracle.install.db.isRACOneInstall=
oracle.install.db.racOneServiceName=
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
oracle.install.db.config.starterdb.globalDBName=orcl
oracle.install.db.config.starterdb.SID=orcl
oracle.install.db.config.starterdb.characterSet=AL32UTF8
oracle.install.db.config.starterdb.memoryOption=true
oracle.install.db.config.starterdb.memoryLimit=
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.enableSecuritySettings=true
oracle.install.db.config.starterdb.password.ALL=oracle
oracle.install.db.config.starterdb.password.SYS=oracle
oracle.install.db.config.starterdb.password.SYSTEM=oracle
oracle.install.db.config.starterdb.password.SYSMAN=oracle
oracle.install.db.config.starterdb.password.DBSNMP=
oracle.install.db.config.starterdb.control=DB_CONTROL
oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=
oracle.install.db.config.starterdb.automatedBackup.enable=false
oracle.install.db.config.starterdb.automatedBackup.osuid=
oracle.install.db.config.starterdb.automatedBackup.ospwd=
oracle.install.db.config.starterdb.storageType=
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=
oracle.install.db.config.asm.diskGroup=
oracle.install.db.config.asm.ASMSNMPPassword=
MYORACLESUPPORT_USERNAME=
MYORACLESUPPORT_PASSWORD=
SECURITY_UPDATES_VIA_MYORACLESUPPORT=
DECLINE_SECURITY_UPDATES=true
PROXY_HOST=
PROXY_PORT=
PROXY_USER=
PROXY_PWD=
PROXY_REALM=
COLLECTOR_SUPPORTHUB_URL=
oracle.installer.autoupdates.option=SKIP_UPDATES
oracle.installer.autoupdates.downloadUpdatesLoc=
AUTOUPDATES_MYORACLESUPPORT_USERNAME=
AUTOUPDATES_MYORACLESUPPORT_PASSWORD=
EOF
#以下为Oracle 11.2.04的说明:
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0//标注响应文件版本
oracle.install.option=INSTALL_DB_SWONLY//.只装数据库软件
ORACLE_HOSTNAME=主机名
UNIX_GROUP_NAME=oinstall//指定oracle inventory目录的所有者
INVENTORY_LOCATION=/u01/app/oraInventory指定产品清单oracle inventory目录的路径
SELECTED_LANGUAGES=en,zh_CN//指定语言
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_home1//设置ORALCE_HOME的路径
ORACLE_BASE=/u01/app/oracle//指定ORALCE_BASE的路径
oracle.install.db.InstallEdition=EE//安装数据库软件的版本,企业版
oracle.install.db.EEOptionsSelection=true//手动指定企业安装组件 选true对安装大小影响不大所以选true
oracle.install.db.optionalComponents=oracle.rdbms.partitioning:11.2.0.4.0,oracle.oraolap:11.2.0.4.0,oracle.rdbms.dm:11.2.0.4.0,oracle.rdbms.dv:11.2.0.4.0,oracle.rdbms.lbac:11.2.0.4.0,oracle.rdbms.rat:11.2.0.4.0//如果上面选true,这些就是手动指定的组件
oracle.install.db.DBA_GROUP=dba//指定拥有DBA用户组,通常会是dba组
oracle.install.db.OPER_GROUP=oper//指定oper用户组
oracle.install.db.CLUSTER_NODES=//指定所有的节点
oracle.install.db.isRACOneInstall=false//是否是RACO方式安装
oracle.install.db.racOneServiceName=
oracle.install.db.config.starterdb.type=//选择数据库的用途,一般用途/事物处理,数据仓库
oracle.install.db.config.starterdb.globalDBName=指定GlobalName
oracle.install.db.config.starterdb.SID=//你指定的SID
oracle.install.db.config.starterdb.characterSet=AL32UTF8//设置数据库编码
oracle.install.db.config.starterdb.memoryOption=true//11g的新特性自动内存管理,也就是SGA_TARGET和PAG_AGGREGATE_TARGET都,不用设置了,Oracle会自动调配两部分大小,这个要选true
oracle.install.db.config.starterdb.memoryLimit=上面是true的情况下,指定Oracle自动管理内存的大小,这里不用填或者填写物理内存的40%左右等等自定义;
oracle.install.db.config.starterdb.installExampleSchemas=false是否载入模板示例
oracle.install.db.config.starterdb.enableSecuritySettings=true 是否启用安全设置
oracle.install.db.config.starterdb.password.ALL=123456所有用户名的密码
oracle.install.db.config.starterdb.password.SYS=
oracle.install.db.config.starterdb.password.SYSTEM=
oracle.install.db.config.starterdb.password.SYSMAN=
oracle.install.db.config.starterdb.password.DBSNMP=
oracle.install.db.config.starterdb.control=DB_CONTROL数据库本地管理工具DB_CONTROL,远程集中管理工具GRID_CONTROL
oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=GRID_CONTROL需要设定grid control的远程路径URL
oracle.install.db.config.starterdb.automatedBackup.enable=false设置自动备份
oracle.install.db.config.starterdb.automatedBackup.osuid=.自动备份会启动一个job,指定启动JOB的系统用户ID
oracle.install.db.config.starterdb.automatedBackup.ospwd=自动备份会开启一个job,需要指定OSUser的密码
oracle.install.db.config.starterdb.storageType=要求指定使用的文件系统存放数据库文件还是ASM
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=使用文件系统存放数据库文件才需要指定数据文件、控制文件、Redo log的存放目录
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=使用文件系统存放数据库文件才需要指定备份恢复目录
oracle.install.db.config.asm.diskGroup=使用ASM存放数据库文件才需要指定存放的磁盘组
oracle.install.db.config.asm.ASMSNMPPassword=使用ASM存放数据库文件才需要指定ASM实例密码
MYORACLESUPPORT_USERNAME=指定metalink账户用户名
MYORACLESUPPORT_PASSWORD=指定metalink账户密码
SECURITY_UPDATES_VIA_MYORACLESUPPORT=用户是否可以设置metalink密码
DECLINE_SECURITY_UPDATES=true是否设置安全更新,
PROXY_HOST=代理服务器名
PROXY_PORT=代理服务器端口
PROXY_USER=代理服务器用户名
PROXY_PWD=代理服务器密码
PROXY_REALM=
COLLECTOR_SUPPORTHUB_URL=
oracle.installer.autoupdates.option=SKIP_UPDATES
自动更新
oracle.installer.autoupdates.downloadUpdatesLoc=自动更新下载目录
AUTOUPDATES_MYORACLESUPPORT_USERNAME=自动更新的用户名
AUTOUPDATES_MYORACLESUPPORT_PASSWORD=自动更新的密码
#注意:上面的ORACLE_BASE如果是其它目录需要把/data改为比如/u01或/opt等即可
3.1.2 执行db_install.rsp
(oracle用户) 开始执行安装,第一次有报错如下,
注意:-responseFile参数必须使用绝对路径 。
注意: -responseFile是大写的F。
[oracle@db
~]$ cd /tmp/database/ ; ls
doc install
response rpm runInstaller
sshsetup stage welcome.html
[oracle@db
database]$ unset LANG LANGUAGE;unset DISPLAY;
/tmp/database/runInstaller
-silent -force -ignoreSysPrereqs -ignorePrereq -showprogress -responseFile
/tmp/database/response/db_install.rsp
#由于oracle默认不支持CentOS,安装时加参数-ignoreSysPrereqs 忽略系统检查,或者修改OS系统标识即把/etc/redhat-release内容修改为redhat-6(如果是centos6就改为redhat-6,centos7就改为redhat-7)
Starting
Oracle Universal Installer...
Checking
Temp space: must be greater than 120 MB.
Actual 778012 MB Passed
Checking
swap space: must be greater than 150 MB.
Actual 20479 MB Passed
Preparing
to launch Oracle Universal Installer from /tmp/OraInstall2018-08-29_07-37-23PM.
Please wait ...[oracle@rdata03 database]$ You can find the log of this install
session at:
/data/app/oraInventory/logs/installActions2018-08-29_07-37-23PM.log
Prepare in
progress.
.................................................. 9% Done.
Prepare
successful.
Copy files
in progress.
.................................................. 14% Done.
.................................................. 20% Done.
.................................................. 26% Done.
.................................................. 32% Done.
.................................................. 41% Done.
.................................................. 46% Done.
.................................................. 51% Done.
.................................................. 56% Done.
.................................................. 62% Done.
.................................................. 67% Done.
.................................................. 72% Done.
.................................................. 77% Done.
.................................................. 82% Done.
........................................
Copy files
successful.
Link
binaries in progress.
..........
Link
binaries successful.
Setup files
in progress.
.................................................. 87% Done.
.................................................. 94% Done.
Setup files
successful.
The
installation of Oracle Database 11g was successful.
Please
check '/data/app/oraInventory/logs/silentInstall2018-08-29_07-37-23PM.log' for
more details.
Execute
Root Scripts in progress.
As a root
user, execute the following script(s):
1. /data/app/oraInventory/orainstRoot.sh
2.
/data/app/oracle/product/11.2.0.4/db_1/root.sh
.................................................. 100% Done.
Execute
Root Scripts successful.
Successfully
Setup Software.
安装过程大概需要10分钟左右(根据机型配置时间也不同),安装过程中有警告[WARNING] 是需要安装一些i386 的包。查看log安装即可,不用管它。
同时安装时最好用screen防止xshell中断也最好不要打开新的窗口,
root用户执行上面说的两个脚本,
第一个脚本执行成功,
[oracle@db
database]$ su - root
Password:
[root@rdata03
~]# sh /data/app/oraInventory/orainstRoot.sh
Changing
permissions of /data/app/oraInventory.
Adding
read,write permissions for group.
Removing
read,write,execute permissions for world.
Changing
groupname of /data/app/oraInventory to oinstall.
The
execution of the script is complete.
第二个脚本执行成功,
[root@rdata03
~]# sh /data/app/oracle/product/11.2.0.4/db_1/root.sh
Check
/data/app/oracle/product/11.2.0.4/db_1/install/root_rdata03_2018-08-29_19-42-49.log
for the output of root script
3.2
静默配置监听
静默配置监听 oracle用户,netca.rsp不需要修改,直接建立监听,退出代码是0说明成功,1说明失败。
3.2.1 创建动态监听
[oracle@db
response]$ pwd
/tmp/database/response
[oracle@db
response]$ ls
dbca.rsp db_install.rsp netca.rsp
[oracle@rdata03
database]$ which netca
/data/app/oracle/product/11.2.0.4/db_1/bin/netca
#注:-silent和-responseFile之间有一个空格不要有多个 因为实际测试有报错,另仅写netca也可不用写绝对路径也可。
[oracle@db
response]$ netca -silent -responseFile /tmp/database/response/netca.rsp
Parsing
command line arguments:
Parameter "silent" = true
Parameter "responsefile" =
/tmp/database/response/netca.rsp
Done
parsing command line arguments.
Oracle Net
Services Configuration:
Profile
configuration complete.
Oracle Net
Listener Startup:
Running Listener Control:
/data/app/oracle/product/11.2.0.4/db_1/bin/lsnrctl start LISTENER
Listener Control complete.
Listener started successfully.
Listener
configuration complete.
Oracle Net
Services configuration successful. The exit code is 0
3.2.2
创建静态监听
上面通过netca创建的监听是动态监听,接着最好配置一下静态监听,
注:HOST要根据实际的主机名来改成实际的主机名。
[oracle@db
response]$ cp $ORACLE_HOME/network/admin/listener.ora $ORACLE_HOME/network/admin/listener.ora.bak`date
+%F`
echo
'SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME =
/data/app/oracle/product/11.2.0.4/db_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY =
EXTPROC1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =
db)(PORT = 1521))
)
)
ADR_BASE_LISTENER
= /data/app/oracle' > $ORACLE_HOME/network/admin/listener.ora
[oracle@db
response]$ cp $ORACLE_HOME/network/admin/tnsnames.ora
$ORACLE_HOME/network/admin/tnsnames.ora.bak`date +%F`
echo 'ORCL
=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =
db)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
(SERVER = DEDICATED)
)
)
' >
$ORACLE_HOME/network/admin/tnsnames.ora
[oracle@db
~]$ lsnrctl reload && tnsping orcl && lsnrctl status
LSNRCTL for
Linux: Version 11.2.0.4.0 - Production on 29-AUG-2018 20:01:27
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 29-AUG-2018 19:46:37
Uptime 0 days 0 hr. 14 min. 50 sec
Trace
Level off
Security ON: Local OS Authentication
SNMP OFF
Listener
Parameter File
/data/app/oracle/product/11.2.0.4/db_1/network/admin/listener.ora
Listener
Log File
/data/app/oracle/diag/tnslsnr/rdata03/listener/alert/log.xml
Listening
Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=rdata03)(PORT=1521)))
Services
Summary...
Service
"orcl" has 1 instance(s).
Instance "orcl", status UNKNOWN,
has 1 handler(s) for this service...
The command
completed successfully
注:里面的orcl根据你安装的数据库实例名确定。
查看监听进程是否已经启动,oracle用户,
#通过netstat -tlnp 命令,看到
[oracle@db
~]$ netstat -luntp | grep tnslsnr
(Not all
processes could be identified, non-owned process info
will not be shown, you would have to be root
to see it all.)
tcp 0
0 :::1521 :::* LISTEN 6962/tnslsnr
说明监听器已经在1521端口上开始工作了。
3.3
静默安装数据库(创建实例)
配置静默建立新库(同时也建立一个对应的实例)oracle用户,
3.3.1 配置响应文件dbca.rsp
[oracle@db
oracle]$ mkdir -p /data/app/oracle/oradata && \
mkdir -p
/data/app/oracle/flash_recovery_area
[oracle@db
response]$ vim /tmp/database/response/dbca.rsp
#注:可以通过egrep -v '^#|^$'
/tmp/database/response/dbca.rsp查看。
[oracle@db
response]$ cp /tmp/database/response/dbca.rsp
/tmp/database/response/dbca.rsp.bak
cat >
/tmp/database/response/dbca.rsp << EOF
[GENERAL]
RESPONSEFILE_VERSION
= "11.2.0"
OPERATION_TYPE
= "createDatabase"
[CREATEDATABASE]
GDBNAME =
"orcl"
SID =
"orcl"
TEMPLATENAME
= "General_Purpose.dbc"
SYSPASSWORD
= "oracle"
SYSTEMPASSWORD
= "oracle"
DATAFILEDESTINATION
= /data/app/oracle/oradata
RECOVERYAREADESTINATION=/data/app/oracle/flash_recovery_area
CHARACTERSET
= "AL32UTF8"
[CONFIGUREDATABASE]
SYSDBAUSERNAME
= "sys"
EOF
说明如下:
RESPONSEFILE_VERSION
= "11.2.0" #不能更改
OPERATION_TYPE
= "createDatabase" #不变 默认即可
GDBNAME =
"orcl" #数据库的名字,随便怎么改,不影响,自定义 比如"oracle11g.com"
SID =
"orcl"
#对应的实例名字instance_name,随便怎么改,不影响,自定义 比如"oracle11g.com"
TEMPLATENAME
= "General_Purpose.dbc" #不变 默认即可 建库用的模板文件
SYSPASSWORD
= "oracle" #SYS管理员密码 自定义
SYSTEMPASSWORD
= "oracle" #SYSTEM管理员密码 自定义
DATAFILEDESTINATION
= /data/app/oracle/oradata #数据文件存放目录 可自定义如/data目录但用户和组要是oracle:oinstall即mkdir /data ; chown -R
oracle:oinstall /data ; chmod -R 775 /data; 当然此项默认是$ORACLE_BASE/oradata 此项本来是注释掉的,而$ORACLE_BASE/oradata就是/data/app/oracle/oradata,故此项可不用动,即保持注释掉即也可;
RECOVERYAREADESTINATION=/data/app/oracle/flash_recovery_area
#恢复数据存放目录 闪回区 可自定义
CHARACTERSET
= "AL32UTF8" #字符集,重要!!! 建库后一般不能更改,所以建库前要确定清楚,选AL32UTF8比较合适;
NATIONALCHARACTERSET=
"AL16UTF16" #最好还是保持默认的"AL16UTF16",这里我选的UTF8可能出现了后面的PLSQL中文乱码;
#MEMORYPERCENTAGE
= "40" #服务器物理内存分配给oracle的内存比例,这里先不选
#TOTALMEMORY
= "3500" # //物理内存的60%左右,分配给oracle的总内存3500MB,可自行设定 或者注释不选因为oracle会自行管理;
#-----------------------***
End of CREATEDATABASE section ***------------------------
SOURCEDB =
"myhost:1521:orcl" #End of
CREATEDATABASE sectio后面的很多没有注释掉的选项不用管。
3.3.2
执行响应文件dbca.rsp
(oracle用户)执行静默建立新库,同时也建立一个对应的实例,
注意:-responseFile 参数必须使用绝对路径。
[oracle@db
oracle]$ mkdir -p /data/app/oracle/oradata && \
mkdir -p
/data/app/oracle/flash_recovery_area
[oracle@db
response]$ dbca -silent -responseFile /tmp/database/response/dbca.rsp
Copying
database files
1% complete
3% complete
11%
complete
18%
complete
26%
complete
37%
complete
Creating
and starting Oracle instance
40%
complete
45%
complete
50%
complete
55%
complete
56%
complete
60%
complete
62%
complete
Completing
Database Creation
66%
complete
70%
complete
73%
complete
85%
complete
96%
complete
100%
complete
Look at the
log file "/data/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for
further details.
检查oracle进程,
[oracle@db
~]$ ps -ef | grep ora_ | grep -v grep | wc -l
23
[oracle@db
~]$ ps -ef | grep ora_ | grep -v grep
oracle 7952
1 0 Aug17 ? 00:00:09 ora_pmon_orcl
oracle 7954
1 0 Aug17 ? 00:03:42 ora_vktm_orcl
oracle 7958
1 0 Aug17 ? 00:00:03 ora_gen0_orcl
oracle 7960
1 0 Aug17 ? 00:00:03 ora_diag_orcl
oracle 7962
1 0 Aug17 ? 00:00:02 ora_dbrm_orcl
oracle 7964
1 0 Aug17 ? 00:00:03 ora_psp0_orcl
oracle 7966
1 0 Aug17 ? 00:00:31 ora_dia0_orcl
oracle 7968
1 0 Aug17 ? 00:00:03 ora_mman_orcl
oracle 7970
1 0 Aug17 ? 00:00:12 ora_dbw0_orcl
oracle 7972
1 0 Aug17 ? 00:00:13 ora_lgwr_orcl
oracle 7974
1 0 Aug17 ? 00:00:23 ora_ckpt_orcl
oracle 7976
1 0 Aug17 ? 00:00:08 ora_smon_orcl
oracle 7978
1 0 Aug17 ? 00:00:01 ora_reco_orcl
oracle 7980
1 0 Aug17 ? 00:00:14 ora_mmon_orcl
oracle 7982
1 0 Aug17 ? 00:00:26 ora_mmnl_orcl
oracle 7984
1 0 Aug17 ? 00:00:01 ora_d000_orcl
oracle 7986
1 0 Aug17 ? 00:00:00 ora_s000_orcl
oracle 8025
1 0 Aug17 ? 00:00:01 ora_qmnc_orcl
oracle 8040
1 0 Aug17 ? 00:00:13 ora_cjq0_orcl
oracle 8044
1 0 Aug17 ? 00:00:00 ora_q001_orcl
oracle 8072
1 0 Aug17 ? 00:00:02 ora_smco_orcl
oracle 8383
1 0 Aug17 ? 00:00:03 ora_q002_orcl
oracle 10943
1 0 08:32 ? 00:00:00 ora_w000_orcl
(oracle用户) 这里查看/etc/oratab配置文件,可以看到配置文件的最后多了一行,
orcl:/data/app/oracle/product/11.2.0/dbhome_1:N
,这是配置文件里说的标准格式$ORACLE_SID:$ORACLE_HOME:<N|Y>:
即其中的Y是Oracle随开机启动,N是开机不自动启动,说明:第一个区域的值是sid,第二个区域的值是数据库主目录,第三个区域的值Y或N指定你是否想要dbstart和dbshut脚本启动并关闭数据库,如果不用dbstart脚本启动数据库,而是用自己的脚本来启动,根本不需要oratab文件。
可以根据情况设为Y即
orcl:/data/app/oracle/product/11.2.0/dbhome_1:Y,这里先不设定。
[oracle@db
~]$ ll /etc/oratab
-rw-rw-r--
1 oracle oinstall 725 Aug 17 19:16 /etc/oratab
[oracle@db
~]$ cat /etc/oratab
#
# 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.
#
#
orcl:/data/app/oracle/product/11.2.0/dbhome_1:N
在这个时间,windows死机了则强制重启电脑,然后打开VMware-->打开CentOS6.5-->ps
-ef | grep ora_ | grep -v grep | wc -l 发现结果是0-->则先启动监听lsnrctl start-->再用sqlplus进行启动即可,具体如下 ,
第一步:打开监听
$ lsnrctl start
第二步:进入sqlplus
$ sqlplus /nolog
SQL>
第三步:使用sysdba角色登录sqlplus
SQL> conn /as sysdba
第四步:启动数据库
SQL> startup
具体操作如下,
[oracle@db ~]$ ps -ef | grep
ora_ | grep -v grep | wc -l
0
[oracle@db ~]$ lsnrctl start
[oracle@db ~]$ sqlplus /nolog
SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size 2213776 bytes
Variable Size 973080688 bytes
Database Buffers 620756992 bytes
Redo Buffers 7360512 bytes
Database mounted.
Database opened.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
[oracle@db ~]$ ps -ef | grep
ora_ | grep -v grep | wc -l
23
可以使用show parameter;或者select table_name from dba_tables;看看是否正常
[oracle@db ~]$ sqlplus / as sysdba
SQL> show parameter;
SQL> select table_name from dba_tables;
SQL> show user;
3.4
数据库配置和优化
3.4.1
归档闪回,进程会话
开启强制日志记录,开启归档(归档要在mount下才行),开启闪回(闪回也要在mount下才行),增大线程和会话数。
[oracle@db
~]$ sqlplus / as sysdba
SQL>
shutdown immediate;
startup mount;
--开启归档
alter database archivelog;
--开启闪回
alter database flashback on;
alter database open;
--开启强制日志
alter database force logging;
--增加连接进程,默认是150,更改后重启才能生效
show parameter processes;
alter system set processes=1500 scope=spfile;
--再次查看还是150,是因为只有重启后才能生效,但是注意此更改已经更改到了spfile文件如果此时我们不重启而直接查看spfile文件可以看到已经是*.processes=1500
show parameter processes;
--增加会话数,默认是248,更改后重启才能生效
show parameter sessions ;
alter system set sessions=1500 scope=spfile;
--再次查看还是248,是因为只有重启后才能生效,但是注意此更改已经更改到了spfile文件如果此时我们不重启而直接查看spfile文件可以看到已经是*.sessions=1500
show parameter sessions ;
--默认为200,更改后重启才能生效
alter system set db_files=2000 scope=spfile;
--再次查看还是200,是因为只有重启后才能生效,但是注意此更改已经更改到了spfile文件
show parameter db_files;
--增加归档、闪回区,默认是4GB,修改后会立即生效
alter system set
db_recovery_file_dest_size=50G;
show parameter
db_recovery_file_dest;
shutdown immediate;
startup;
--查看修改后的参数
select status from v$instance;
select
log_mode,open_mode,flashback_on from v$database;
select name,log_mode,force_logging from v$database;
show parameter processes;
show parameter sessions ;
show parameter db_files;
create pfile from spfile;
3.4.2
环境变量和防错
--在sqlplus里切换用户后要非常小心,以防在非想要执行的用户下执行增删改查而导致出错。 --可以修改sqlplus 的提示符:SQL> ,把这个改成我们用户和实例名,这样就不容易出错。
--另外,sqlplus的行和页也设置一下set linesize 9999 pagesize 9999;
查看原文件,
[oracle@db
~]$ cat $ORACLE_HOME/sqlplus/admin/glogin.sql
--
--
Copyright (c) 1988, 2011, Oracle and/or its affiliates.
-- All
rights reserved.
--
-- NAME
-- glogin.sql
--
--
DESCRIPTION
-- SQL*Plus global login "site
profile" file
--
-- Add any SQL*Plus commands here that are to
be executed when a
-- user starts SQL*Plus, or uses the SQL*Plus
CONNECT command.
--
-- USAGE
-- This script is automatically run
--
进行更改,
[oracle@db
~]$ cp $ORACLE_HOME/sqlplus/admin/glogin.sql
$ORACLE_HOME/sqlplus/admin/glogin.sql.bak`date +%F`
cat
>> $ORACLE_HOME/sqlplus/admin/glogin.sql << EOF
set
sqlprompt "_USER'@'_CONNECT_IDENTIFIER > "
set
linesize 9999 pagesize 9999
EOF
[oracle@db
~]$ tail -n 2 $ORACLE_HOME/sqlplus/admin/glogin.sql
set
sqlprompt "_USER'@'_CONNECT_IDENTIFIER > "
set
linesize 9999 pagesize 9999
[oracle@rac01
~]$ sqlplus / as sysdba
SQL*Plus:
Release 11.2.0.4.0 Production on Fri Sep 7 13:14:36 2018
Copyright
(c) 1982, 2013, Oracle. All rights
reserved.
Connected
to:
Oracle
Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the
Partitioning, Real Application Clusters, Automatic Storage Management, Oracle
Label Security,
OLAP, Data
Mining, Oracle Database Vault and Real Application Testing options
SYS@orcl1
>
3.4.3
rman定期删除归档
rman定期删除归档,以免归档爆满了造成数据库无法正常工作,
[oracle@rdata01
~]$ echo '#!/bin/bash
###################
.
/etc/profile
.
~/.bash_profile
##################
echo `date
+%F_%T` >> /home/oracle/deletearchivelog.log
rman target
/ <<EOF
crosscheck
archivelog all;
delete
noprompt expired archivelog all;
DELETE
noprompt ARCHIVELOG ALL COMPLETED BEFORE "SYSDATE-1";
exit;
EOF' >
deletearchivelog.sh
[oracle@rdata01
~]$ chmod a+x deletearchivelog.sh
#注:如果上面的脚本deletearchivelog.sh中的. ~/.bash_profile代表的是rman在执行时要用到两个环境变量
export
ORACLE_HOME=/data/app/oracle/product/11.2.0/db_1
export
ORACLE_SID=phydb
[oracle@rdata01
~]$ crontab -l
0 3 * * *
/home/oracle/deletearchivelog.sh > /home/oracle/deletearchivelog.log
2>&1
#需要root用户
[root@rdata01
~]# yum install -y vixie-cron && chkconfig crond on &&
chkconfig --list crond && service crond start
[root@rdata01
~]# tailf /var/log/cron
Jul 4 15:20:01 rdata01 CROND[22239]: (root) CMD
(/usr/lib64/sa/sa1 1 1)
Jul 4 15:20:01 rdata01 CROND[22242]: (oracle) CMD
(/home/oracle/deletearchivelog.sh >> /home/oracle/deletearchivelog.log
2>&1)
3.4.4
开机启动Oracle服务
根据根据来设置是否开机启动,如果要开启则参数下面的方法,
31、 开机自动启动Oracle服务配置
A、 修改dbstart和dbshut脚本
[oracle@tsp-rls-dbserver
~]$ vi $ORACLE_HOME/bin/dbstart
[oracle@tsp-rls-dbserver
~]$ vi $ORACLE_HOME/bin/dbshut
找到文件中的ORACLE_HOME_LISTNER=$1,修改为:ORACLE_HOME_LISTNER=$ORACLE_HOME
B、 修改oratab文件
[oracle@tsp-rls-dbserver
~]$ vi /etc/oratab
将ORATSP:/home/oracle/app/product/11.2.0/dbhome_1:N
修改为:ORATSP:/home/oracle/app/product/11.2.0/dbhome_1:Y
C、 修改rc.local文件(root用户)
[root@tsp-rls-dbserver
deps]# vi /etc/rc.d/rc.local
文件尾部添加如下信息:
su oracle
-lc "/home/oracle/app/product/11.2.0/dbhome_1/bin/emctl start
dbconsole"
su oracle
-lc "/home/oracle/app/product/11.2.0/dbhome_1/bin/lsnrctl start"
su oracle
-lc "/home/oracle/app/product/11.2.0/dbhome_1/bin/dbstart"
3.4.5
开放防火墙端口
根据根据来设置,如果要开启则参数下面的方法,
执行命令:
[root@tsp-rls-dbserver
deps]# /sbin/iptables -I INPUT -p tcp --dport 1521 -j ACCEPT
[root@tsp-rls-dbserver
deps]# /sbin/iptables -I INPUT -p tcp --dport 1158 -j ACCEPT
保存设置命令:
[root@tsp-rls-dbserver
deps]# /etc/rc.d/init.d/iptables save
查看端口打开情况命令:
[root@tsp-rls-dbserver
deps]# /etc/init.d/iptables status
重启防火墙服务
[root@tsp-rls-dbserver
deps]# /etc/rc.d/init.d/iptables restart
3.5
简单测试一下
创建用户和表空间,
create tablespace trade02 logging datafile '/data/app/oracle/oradata/trade02.dbf' size 2048M autoextend on next 500M maxsize unlimited extent management local segment space management auto;
CREATE TEMPORARY TABLESPACE trade02_temp TEMPFILE '/data/app/oracle/oradata/trade02_temp.dbf' SIZE 10240M AUTOEXTEND ON NEXT 500M MAXSIZE unlimited EXTENT MANAGEMENT LOCAL ;
CREATE USER trade02 IDENTIFIED BY oracle DEFAULT TABLESPACE trade02 TEMPORARY TABLESPACE trade02_temp;
ALTER TABLESPACE trade02 ADD DATAFILE '/data/app/oracle/oradata/trade02_0001.dbf' SIZE 10G AUTOEXTEND ON NEXT 500M MAXSIZE UNLIMITED;
grant connect,resource,dba to trade02;
具体如下,
[oracle@db ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Aug 18 15:42:27 2017
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition
Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> create tablespace trade02 logging datafile '/data/app/oracle/oradata/trade02.dbf' size 2048M autoextend on next 500M maxsize unlimited extent management local segment space management auto;
Tablespace created.
SQL> CREATE TEMPORARY TABLESPACE trade02_temp TEMPFILE '/data/app/oracle/oradata/trade02_temp.dbf' SIZE 10240M AUTOEXTEND ON NEXT 500M MAXSIZE unlimited EXTENT MANAGEMENT LOCAL ;
Tablespace created.
SQL> CREATE USER trade02 IDENTIFIED BY oracle DEFAULT TABLESPACE trade02 TEMPORARY TABLESPACE trade02_temp;
User created.
SQL> ALTER TABLESPACE trade02 ADD DATAFILE '/data/app/oracle/oradata/trade02_0001.dbf' SIZE 10G AUTOEXTEND ON NEXT 500M MAXSIZE UNLIMITED;
SQL> grant connect,resource,dba to trade02;
Grant succeeded.
sys用户创建表和查询表,
[oracle@db
~]$ sqlplus / as sysdba
SQL>
create table STUDENT(ID int, NAME varchar(20));
Table
created.
SQL>
insert into STUDENT values(1, '张三');
1 row
created.
SQL>
select * from student;
ID NAME
----------
--------------------
1 张三
此时用PLSQL在windows机器上登录trade02用户试试,成功登录,创建和查询表OK,
PLSQL中文乱码:
问题描述:
我们可以看到通过Xshell连接到Oracle服务器,插入中文然后查询中文没有乱码,用PLSQL连上云查询也没有乱码,
在PLSQL里面可以插入中文也可以提交,但用PLSQL查询发现是乱码,用XShell连上去发现也是乱码,
[oracle@db
~]$ sqlplus trade02/oracle
SQL> create table WANG(ID int, NAME varchar(20));
Table created.
SQL> insert into wang values(1,'王');
1 row created.
SQL> commit;
Commit complete.
SQL> select * from wang;
ID NAME
----------
--------------------
1 王
SQL> show user;
USER is "TRADE02"
SQL> INSERT INTO WANG VALUES(2,'中华55');
1 row created.
SQL> commit;
Commit complete.
SQL> SELECT * FROM WANG;
ID NAME
----------
--------------------
1 王
2 中华55
SQL> select * from wang;
ID NAME
----------
--------------------
3 ����
1 王
2 中华55
解决方法:本地windows电脑添加环境变量即可解决,
计算机--》鼠标右键--》属性--》高级系统设置--》高级--》环境变量--》新建两个变量
LANG=zh_CN.GBK
NLS_LANG="SIMPLIFIED
CHINESE_CHINA.ZHS16GBK"--》然后重新PLSQL即可。
变量名:LANG
变量值:zh_CN.GBK
变量名:NLS_LANG
变量值:"SIMPLIFIED
CHINESE_CHINA.ZHS16GBK"
可能发生中文乱码的原因,
我认为是在静默建库建实例的时间我把NATIONALCHARACTERSET选的UTF8,应该选"AL16UTF16",因为我查的我们现有的测试环境,模拟盘和实盘都是"AL16UTF16",
Select *
FROM nls_database_parameters where parameter like '%NLS%';
/opt/database/response/dbca.rsp
NATIONALCHARACTERSET=
"UTF8" #最好还是保持默认的"AL16UTF16",这里我选的UTF8可能出现了后面的PLSQL中文乱码;
查看Oracle server的字符集,
select
userenv('language') from dual;
4、拷贝安装
还有最后一种安装方式就是拷贝安装了,我们直切拷贝本机的oracle目录和oraInventory两个目录到别的机器上,或者我们这个把这两个目录保存在一个地方,为了以后可以直接使用(干净的oracle产品,也就是刚刚安装好的oracle)
最后的安装oracle产品的两种方法要注意了,我要配好所有的环境和相关依赖包的安装,这些工作都得提前做好
在生产上提议使用静默安装和图形化安装
现在库也建好了,那接下来就是看下oracle的一些简单命令和一些设置了
su - oracle
我们通过sqlplus / as sysdba的方式连接数据库
还有一种方式就是
sqlplus /
nolog 这个是启动工具,但是不登录
要使用
connect
/ as sysdba 的方式连接到sysdba超级用户,connect可以缩写成conn
show
user; 查看当前是哪个用户登录
sysdba
数据的最高权限拥有者
alter
user scott account unlock
给scott的用户解锁
conn
scott/tiger
连接到scott,使用tiger密码登录
这个时候会提示密码到期了,oracle默认的密码是180天过期,但是只是给你一个警告,让你换密码,但是即使你不换使用以前的密码也是可以的
这里我们会发现我们登录之后,回退键等按键无法使用,这个时候我们就要装一个rlwrap的东西了
select *
from tab;
返回当前用户有哪些表,视图等;
我们使用 sqlplus / as sysdba;登录
然后使用alter user scott
account unlock;给scott用户解锁
还有一种情况就是我们在查看表的时候有几种情况看着比较不舒服
一个就是当一行字符比较多的时候就乱行了
还有一种就是一个页面有多行的时候会分页,所以这里我们就要做一些操作
cd
/home/oracle
vim
login.sql(文件名必须为login.sql)
set
linesize 100 设定一行最多可以显示100个字符
set
pagesize 100 设置一页做多可以显示一百行
set long
50000
set timing
on 在执行完sql之后末尾加上执行时间是多少,做一个时间统计
这个文件我们是保存在/home/oracle目录下的,所以这个美化的功能只可以在/home/oracle目录下连接oracle才能生效,在别的目录下是不生效的,所以我们要给它定义到配置文件中
我们可以查看一下show linesize;
我们也可以在终端设置这个参数,但是退出oracle终端的时候下次登录就没用了,所以我们加一个环境变量
cd
/home/oracle
vim .bashrc
添加一行
export
SQL_PATH=/home/oracle
source
.bashrc
添加这个环境变量的意义就在以后每次不管在任何目录下启动sqlplus,都到/home/oracle下读取login.sql 文件
还有就是我们在使用sqlplus的时候,我们发现回退键以及上下键都不能使用,我们需要装一下rlwrap
装完之后,我们设置一下别名
cd
/home/oracle
vim
.bash_profile
alias
sqlplus='rlwrap sqlplus'
alias
rman='rlwrap rman'
再次登录就可以使用了
5、Windows安装方法
只需要其中的第一个和第二个文件。将2个文件解压缩,然后将第二个文件的内容copy到第一个文件的对应目录里。即将2个文件合成一个文件。
oracle
安装为了我们的生产环境做准备,一定要安装服务器类,
安装类型
一定选 高级配置 因为我们不是小白且要配置语言防止乱码 及如果要测试和联系用的话需要样本数据。
要选择企业版。SID 即server ID 服务ID,与全局数据库名称一致,可自定义,示例方案 是scott用户的测试样本数据,字符集 UTF-8,示例方案打勾没勾没练习用scott数据,计算机 右键 管理 服务,自动改为手动,其中服务器启动慢,。
二、Oracle的卸载
6、Linux环境下的卸载
6.1
完全卸载
完全卸载即把oracle软件和实例全部都卸载掉。
6.1.1 deinstall方法
Oracle11完全卸载方法
在10g中要卸载CRS是件非常繁琐的事。到了11g,oracle提供了卸载工具deinstall,用这个工具可以卸载的非常干净。这个工具默认放在oracle用户下的$ORACLE_HOME/deinstall/deinstall,RAC的话也是grid用户下的$ORACLE_HOME/deinstall/deinstall
。google了下,发现只需要执行这个工具一次就可以了。当中分别oracle用户和grid用户各执行了一次才卸载完成。
su - grid
运行过程中可能需要填写如下项:
指定要取消配置的所有单实例监听程序[LISTENER]:LISTENER指定在此 Oracle 主目录中配置的数据库名的列表 [MYDATA,ORCL]: MYDATA,ORCL是否仍要修改 MYDATA,ORCL 数据库的详细资料? [n]: nCCR check is finished是否继续 (y - 是, n - 否)? [n]: y
6.1.2 手动卸载方法
1.停止OEM,我在生产一般都不装这个(Oracle用户)
emctl stop dbconsole db
2.停止监听服务(oracle用户登录)
[oracle@tsp-rls-dbserver ~]$ lsnrctl stop
3.停止数据库(oracle用户登录)
[oracle@tsp-rls-dbserver
~]$ sqlplus / as sysdba <<EOF
shutdown
immediate;
exit;
EOF
4.删除oracle安装路径(root用户登录)
目录位置记录在oraInst.loc文件中,
$ more /etc/oraInst.loc
inventory_loc=/u01/app/oracle/oraInventory
inst_group=oinstall
[root@tsp-rls-dbserver deps]# rm -rf
/home/oracle/app
[root@tsp-rls-dbserver deps]# rm -rf
/home/oracle/oraInventory
5.删除系统路径文件(root用户登录)
[root@tsp-rls-dbserver deps]#
rm -rf
/usr/local/bin/dbhome
rm -rf
/usr/local/bin/oraenv
rm -rf
/usr/local/bin/coraenv
6.删除数据库实例表(root用户登录)
[root@tsp-rls-dbserver deps]# rm -rf
/etc/oratab
7.删除数据库实例lock文件(root用户登录)
[root@tsp-rls-dbserver deps]# rm -rf
/etc/oraInst.loc
8.删除oracle用户及用户组(root用户登录)
[root@tsp-rls-dbserver
deps]# userdel -r oracle
[root@tsp-rls-dbserver
deps]# groupdel oinstall
[root@tsp-rls-dbserver
deps]# groupdel dba
6.2 只卸载实例
#!/bin/bash
lsnrctl
stop
sqlplus /
as sysdba << EOF
shutdown
immediate
exit
EOF
find $ORACLE_BASE/
-name $ORACLE_SID | xargs rm -rf
find
$ORACLE_BASE/ -name $ORACLE_SID -exec rm -rf {} \;
find
$ORACLE_BASE/* -name '*[Oo][Rr][Cc][Ll]*' | grep -v admin | grep -v oradata
find
$ORACLE_BASE/* -name '*[Oo][Rr][Cc][Ll]*' | grep -v admin | grep -v oradata |
xargs rm -rf
步骤一:关闭数据库
1. lsnrctl
stop ; sqlplus / as sysdba
2. shutdown
immediate
步骤二:删除实例相关文件(先查询,然后检查是否有非实例相关文件,然后根据情况删除)
1. find
$ORACLE_BASE/ -name $ORACLE_SID
2. 用命令删除查询后的文件
find
$ORACLE_BASE/ -name $ORACLE_SID -exec rm -rf {} \;
步骤三:删除配置文件,假设我们删除的实例是YC(先查询,然后检查是否有非实例相关文件,然后根据情况删除)
比如是orcl的话,则
1. find
$ORACLE_BASE/* -name '*[Oo][Rr][Cc][Ll]*' | grep -v admin | grep -v oradata
2. 用命令删除查询的文件
find
$ORACLE_BASE/* -name '*[Oo][Rr][Cc][Ll]*' | grep -v admin | grep -v oradata |
xargs rm -rf
步骤四:删除实例配置文件中的信息
1. vim
/etc/oratab
2. 找到orcl:/opt/oracle/db/product/11g:N
3. 将该行信息删除,并保存文件
经过以上步骤可以实现命令行干净的删除实例
7、windows下卸载
一、在oracle11G以前卸载oracle会存在卸载不干净,导致再次安装失败的情况,在运行services.msc打开服务,停止Oracle的所有服务。
二、 oracle11G自带一个卸载批处理\app\Administrator\product\11.2.0\dbhome_1\deinstall\deinstall.bat运行该批处理程序将自动完成oracle卸载工作,最后手动删除\app文件夹(可能需要重启才能删除)
运行过程中可能需要填写如下项:
指定要取消配置的所有单实例监听程序[LISTENER]:LISTENER指定在此 Oracle 主目录中配置的数据库名的列表 [MYDATA,ORCL]: MYDATA,ORCL是否仍要修改 MYDATA,ORCL 数据库的详细资料? [n]: nCCR check is finished是否继续 (y - 是, n - 否)? [n]: y
三、运行regedit命令,打开注册表。删除注册表中与Oracle相关内容,具体下:
删除HKEY_LOCAL_MACHINE/SOFTWARE/ORACLE目录。删除HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services中所有以oracle或OraWeb为开头的键。删除HKEY_LOCAL_MACHINE/SYSETM/CurrentControlSet/Services/Eventlog/application中所有以oracle开头的键。删除HKEY_CLASSES_ROOT目录下所有以Ora、Oracle、Orcl或EnumOra为前缀的键。删除HKEY_CURRENT_USER/SOFTWARE/Microsoft/windows/CurrentVersion/Explorer/MenuOrder/Start
Menu/Programs中所有以oracle 开头的键。删除HKDY_LOCAL_MACHINE/SOFTWARE/ODBC/ODBCINST.INI中除Microsoft ODBC for Oracle注册表键以外的所有含有Oracle的键。删除环境变量中的PATHT CLASSPATH中包含Oracle的值。删除“开始”/“程序”中所有Oracle的组和图标。删除所有与Oracle相关的目录,包括: (1)、c:\Program
file\Oracle目录。 (2)、ORACLE_BASE目录。(3)、c:\Documents
and Settings\系统用户名、LocalSettings\Temp目录下的临时文件。
三、Oracle的升级
8、升级Oracle从11.2.0.1到11.2.0.4
升级oracle11G从11.2.0.1到11.2.0.4,
由于Oracle从11.2.0.2开始,Oracle database的补丁集合是完整的安装包,将不再需要安装11.2.0.1版本。所以升级的方式和以前的补丁包不同。11.2.0.4的软件需要安装在一个全新的目录,而不是在原有的11.2.0.1的目录下打补丁。可以将Oracle Database 安装的新的OracleHome directory,当安装结束后,旧的database 会迁移到新的Oracle homedirectory。
8.1
备份数据库
完整的备份数据库 升级数据库是一个有风险的过程,需要仔细规划和慎重处理。首先要做数据库的完全备份,备份的内容包括数据文件,控制文件,归档文件,日志文件,控制文件,参数文件,密码文件等。可以备份一下整个ORACLE_HOME目录,如果升级有问题,还可以还原回来。备份的方法可以使用dump数据泵,tar,rman等。
如:RMAN全备
export ORACLE_SID=orcl
rman
target /
RMAN>backup
full database
plus archivelog //全备数据库,并且包括ArchiveLog。
备份老的ORACLE_HOME和oraInventory
[root@db01 ~]#tar –cvfp
product.zip /opt/app/oracle/
[root@db01 ~]#tar –cvfp
oraInventory.zip /opt/app/oraInventory/
8.2
查看数据库的运行环境,设置数据库的升级方案
1.数据库运行的系统架构和版本
这里是64位的硬件架构,建议选择64位的oracle数据库。
[oracle@db
~]$ getconf LONG_BIT
64
SQL> select name from v$database;
NAME
---------
ORCL
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release
11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Productio
2.文件系统的使用情况
这里数据库的安装到/u01分区,需要预留5G左右的空间做升级文件存放,如果不够则添加挂载新硬盘空间,
[root@db
~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 27G
17G 8.7G 66% /
tmpfs 1.9G 72K
1.9G 1% /dev/shm
/dev/sda1 485M 39M
421M 9% /boot
/dev/sdb1 60G 180M
56G 1% /u01
3.查看手中的数据库升级包资源
数据库的升级建议从小版本逐步升级,不能跨大版本升级。这样会产生不可预料的错误。
先知道Oracle 7个更新文件的作用: 第一 和 二个包表示database ,
如果安装或升级数据库,只需要这2个文件即可。 第三个包表示grid, 用来升级RAC 的CRS。如果升级RAC 要先用这个文件。 第四个表示客户端, 第五个表示gateways, 第六个表示 examples, 这个是我们的示例文件安装包。
8.3
执行升级前的环境准备
1.(Oracle用户)干净的关闭数据库
关闭数据库的方法很多,但是为了升级的顺利和生产的需要,建议使用如下命令:
shutdown
immediate;
我们可以通过查看进程的方式确定数据库是否关闭;
ps -ef
|grep ora_|grep -v grep
具体操作如下:
[oracle@db
~]$ sqlplus / as sysdba
SQL*Plus:
Release 11.2.0.1.0 Production on Tue Aug 22 03:41:52 2017
Copyright
(c) 1982, 2009, Oracle. All rights
reserved.
Connected
to:
Oracle
Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the
Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle
Database Vault and Real Application Testing options
SQL>
shutdown immediate;
Database
closed.
Database
dismounted.
ORACLE
instance shut down.
SQL>
exit
Disconnected
from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit
Production
With the
Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle
Database Vault and Real Application Testing options
[oracle@db
~]$ ps -ef |grep ora_|grep -v grep
2.(Oracle用户)关闭数据库的监听
在数据库的升级中,会对数据库的监听文件做重新的配置,建议正常的关闭监听,如下:
lsnrctl
stop
但在实际的应用中,需要查看监听端口是否开放,来确定监听是否已经关闭,如下:
netstat -an
|grep 1521
netstat -an
|grep 55
具体操作如下:
[oracle@db
~]$ lsnrctl stop
LSNRCTL for
Linux: Version 11.2.0.1.0 - Production on 22-AUG-2017 03:43:18
Copyright
(c) 1991, 2009, Oracle. All rights
reserved.
Connecting
to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
The command
completed successfully
或 SQL> host lsnrctl stop
[oracle@db
~]$ netstat -an |grep 1521
3.(Oracle用户)关闭EM 此项忽略,生产环境一般不安装则不需要检查
在升级中需要关闭EM,查看EM是否关闭可以通过查看EM的默认端口1158是否开放:
netstat -an
|grep 1158
然后根据需要关闭,如下:
SQL>
host emctl stopdbconsole
4.(Oracle用户)不对数据库的任何原有文件做操作
本人在升级中,编辑数据库的监听文件,导致配置监听和EM错误,故不对数据库的任何原有文件做操作。
下面的检查同Oracle的全新正常安装即前面的3.1.1前提和3.1.3静默安装,
此次升级实际系统配置,完全接着对上面的3.1.1和3.1.3静默安装的11.2.0.1数据库,由于虚拟磁盘不够创建了/u01目录并新添加了在vmware中新添加了一块虚拟磁盘挂载到此目录,
环境:在VMware中安装CentOS6.5虚拟机,在此虚拟机里面静默安装Oracle数据库,
CPU:2x2=4核 (CPU大小可自定义)
内存:4G(官方最低要求1G)
硬盘:30G+60G(企业版安装所需4.29G和1.7G数据文件,硬盘大小可自定义)
系统:CentOS release 6.5 (Final)
系统内核:Linux 2.6.32-431.el6.x86_64
Oracle:现有版本11.2.0.1,下面将升级到11.2.0.4,
1.(root用户)检查虚拟内存,待安装目录和/tmp目录大小设置
2.(root用户)检查系统架构
3.(root用户)设置yum源 #已配置过
4.(root用户)selinux 关掉 #已配置过
5.(root用户)防火墙关闭 #已配置过了
6.(root用户)修改主机名(自定义) #已配置过
7.(root用户)上传oracle 11.2.0.4软件软件至/u01目录
[root@db
u01]# pwd
/u01
[root@db
u01]# ll
total
2487224
drwx------
2 root root 16384 Aug 22 01:00
lost+found
-rw-r--r--
1 root root 1395582860 Aug 22 02:36 p13390677_112040_Linux-x86-64_1of7.zip
-rw-r--r--
1 root root 1151304589 Aug 22 02:35 p13390677_112040_Linux-x86-64_2of7.zip
8.(root用户)安装软件包 #已安装过
9.(root用户)建立必要的用户和用户组 #已配置过
10.(root用户)配置内核参数 #已配置过
11.(root用户)改文件限制 #已配置过
12.(root用户)创建安装数据库软件的目录
[root@db
u01]# id oracle
uid=501(oracle)
gid=501(oinstall) groups=501(oinstall),502(dba)
[root@db
u01]# mkdir -p /u01/app/oracle
[root@db
u01]# mkdir -p /u01/app/oraInventory
[root@db
u01]# chown -R oracle:oinstall /u01/app
[root@db
u01]# chmod 775 /u01/app
[root@db
u01]# ll -d /u01/app
drwxrwxr-x
4 oracle oinstall 4096 Aug 22 03:05 /u01/app
13. (root用户) 安装rlwrap #已安装过
14.(root,
oracle用户)配置环境变量 #先保持原来的不变
root用户,
[root@db
opt]# vim /root/.bash_profile #先保持原来的不变
oracle用户,
[root@db
~]# su – oracle
[oracle@db
~]$ vim /home/oracle/.bash_profile #先保持原来的不变
15.(root用户)准备安装包及其权限,
进入/opt 解压oracle压缩包
[root@db
~]# cd /u01
[root@db
u01]# ll #注意是root用户
total
2487228
drwxrwxr-x
4 oracle oinstall 4096 Aug 22 03:05
app
drwx------
2 root root 16384 Aug 22 01:00 lost+found
-rw-r--r--
1 root root 1395582860 Aug 22 02:36
p13390677_112040_Linux-x86-64_1of7.zip
-rw-r--r--
1 root root 1151304589 Aug 22 02:35
p13390677_112040_Linux-x86-64_2of7.zip
[root@db
u01]# unzip p13390677_112040_Linux-x86-64_1of7.zip #注意是root用户
[root@db
u01]# unzip p13390677_112040_Linux-x86-64_2of7.zip #注意是root用户
解压后修改文件夹权限
[root@db
u01]# chown -R oracle:oinstall /u01/database/ #注意是root用户
[root@db
u01]# chmod -R 775 /u01/database/ #注意是root用户
[root@db
u01]# ll
total
2487232
drwxrwxr-x
4 oracle oinstall 4096 Aug 22 03:05
app
drwxrwxr-x
7 oracle oinstall 4096 Aug 27 2013 database
drwx------
2 root root 16384 Aug 22 01:00 lost+found
-rw-r--r--
1 root root 1395582860 Aug 22 02:36
p13390677_112040_Linux-x86-64_1of7.zip
-rw-r--r--
1 root root 1151304589 Aug 22 02:35
p13390677_112040_Linux-x86-64_2of7.zip
16.(root用户)安装图形化界面 #已安装和配置
8.4
静默升级安装11.2.0.4
1.(Oracle用户)配置静默升级安装文件db_install.rsp,
解压后得到database目录,其中包含response目录,该目录中有三个rsp文件,用来作为静默安装时的应答文件的模板。
三个文件作用分别是: db_install.rsp:安装应答 dbca.rsp:创建数据库应答 netca.rsp:建立监听、本地服务名等网络设置的应答
[oracle@db
~]$ cd /u01/database/response
[oracle@db
response]$ ll
total 80
-rwxrwxr-x
1 oracle oinstall 44533 Aug 27 2013
dbca.rsp
-rwxrwxr-x
1 oracle oinstall 25312 Aug 22 23:24 db_install.rsp
-rwxrwxr-x
1 oracle oinstall 5871 Aug 27 2013 netca.rsp
[oracle@db
response]$ egrep -v '^#|^$' db_install.rsp
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
#保持不变
oracle.install.option=UPGRADE_DB #升级数据库
ORACLE_HOSTNAME=db
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oraInventory
SELECTED_LANGUAGES=en,zh_CN,th,zh_TW
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
ORACLE_BASE=/u01/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.EEOptionsSelection=true
#要选true,实际测试选true或false对安装大小没有什么影响
oracle.install.db.optionalComponents=oracle.rdbms.partitioning:11.2.0.4.0,oracle.oraolap:11.2.0.4.0,oracle.rdbms.dm:11.2.0.4.0,oracle.rdbms.dv:11.2.0.4.0,oracle.rdbms.lbac:11.2.0.4.0,oracle.rdbms.rat:11.2.0.4.0
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oinstall
oracle.install.db.CLUSTER_NODES= #如果是RAC的安装,在这里指定所有的节点
oracle.install.db.isRACOneInstall=
oracle.install.db.racOneServiceName=
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE #数据库的用途,一般用途/事物处理,数据仓库
oracle.install.db.config.starterdb.globalDBName=orcl #指定GlobalName
oracle.install.db.config.starterdb.SID=orcl
oracle.install.db.config.starterdb.characterSet=AL32UTF8
#11g的新特性自动内存管理,也就是SGA_TARGET和PAG_AGGREGATE_TARGET都#不用设置了,Oracle会自动调配两部分大小
oracle.install.db.config.starterdb.memoryOption=true #oracle会自动管理内存 选true
oracle.install.db.config.starterdb.memoryLimit= #指定Oracle自动管理内存的大小,最小是256MB,实际上不用填就可以
oracle.install.db.config.starterdb.installExampleSchemas=false #是否载入模板示例
oracle.install.db.config.starterdb.enableSecuritySettings=true #是否启用安全设置
oracle.install.db.config.starterdb.password.ALL=oracle #设定所有数据库用户使用同一个密码,其它数据库用户就不用单独设置了。
oracle.install.db.config.starterdb.password.SYS=oracle
oracle.install.db.config.starterdb.password.SYSTEM=oracle
oracle.install.db.config.starterdb.password.SYSMAN=oracle
oracle.install.db.config.starterdb.password.DBSNMP=
oracle.install.db.config.starterdb.control=DB_CONTROL #数据库本地管理工具DB_CONTROL,远程集中管理工具GRID_CONTROL
oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=
oracle.install.db.config.starterdb.automatedBackup.enable=false #设置自动备份,和OUI里的自动备份一样。
oracle.install.db.config.starterdb.automatedBackup.osuid=
#自动备份会启动一个job,指定启动JOB的系统用户ID
oracle.install.db.config.starterdb.automatedBackup.ospwd=
#自动备份会开启一个job,需要指定OSUser的密码
oracle.install.db.config.starterdb.storageType= #自动备份,要求指定使用的文件系统存放数据库文件还是ASM
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=
##使用文件系统存放数据库文件才需要指定数据文件、控制文件、Redo log的存放目录
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=
##使用文件系统存放数据库文件才需要指定备份恢复目录
oracle.install.db.config.asm.diskGroup= ##使用ASM存放数据库文件才需要指定存放的磁盘组
oracle.install.db.config.asm.ASMSNMPPassword=
##使用ASM存放数据库文件才需要指定ASM实例密码
MYORACLESUPPORT_USERNAME= ##指定metalink账户用户名
MYORACLESUPPORT_PASSWORD= ## 指定metalink账户密码
SECURITY_UPDATES_VIA_MYORACLESUPPORT= ## 用户是否可以设置metalink密码
DECLINE_SECURITY_UPDATES=true # 这里必须为 true 否则会失败
PROXY_HOST= ##代理服务器名
PROXY_PORT= ##代理服务器端口
PROXY_USER= ##代理服务器用户名
PROXY_PWD= ##代理服务器密码
PROXY_REALM=
COLLECTOR_SUPPORTHUB_URL=
oracle.installer.autoupdates.option=SKIP_UPDATES
oracle.installer.autoupdates.downloadUpdatesLoc=
AUTOUPDATES_MYORACLESUPPORT_USERNAME=
AUTOUPDATES_MYORACLESUPPORT_PASSWORD=
2.(Oracle用户)开始执行安装,
安装过程大概需要15分钟左右(根据机型配置时间也不同),安装过程中有警告[WARNING] 是需要安装一些i386 的包。查看log安装即可,不用管它。安装成功应有的输出提示:Successfully Setup Software.
[oracle@db
~]$ cd /u01/database/ ; ls
install readme.html
response rpm runInstaller
sshsetup stage welcome.html
[oracle@db
~]$ unset LANG LANGUAGE ;unset DISPLAY
[oracle@db
database]$ ./runInstaller -silent -force -ignoreSysPrereqs -ignorePrereq
-showProgress -responseFile /u01/database/response/db_install.rsp #由于oracle默认不支持CentOS,安装时加参数-ignoreSysPrereqs 忽略系统检查,,或者修改OS系统标识即把/etc/redhat-release内容修改为redhat-6(如果是centos6就改为redhat-6,centos7就改为redhat-7)
Starting
Oracle Universal Installer...
Checking
Temp space: must be greater than 120 MB.
Actual 8795 MB Passed
Checking
swap space: must be greater than 150 MB.
Actual 3071 MB Passed
Preparing
to launch Oracle Universal Installer from /tmp/OraInstall2017-08-22_11-35-43PM.
Please wait ...[oracle@db database]$ [WARNING] [INS-13014] Target environment
do not meet some optional requirements.
CAUSE: Some of the optional prerequisites
are not met. See logs for details.
/opt/app/oraInventory/logs/installActions2017-08-22_11-35-43PM.log
ACTION: Identify the list of failed
prerequisite checks from the log:
/opt/app/oraInventory/logs/installActions2017-08-22_11-35-43PM.log. Then either
from the log file or from installation manual find the appropriate
configuration to meet the prerequisites and fix it manually.
You can
find the log of this install session at:
/opt/app/oraInventory/logs/installActions2017-08-22_11-35-43PM.log
The
installation of Oracle Database 11g was successful.
Please
check '/opt/app/oraInventory/logs/silentInstall2017-08-22_11-35-43PM.log' for
more details.
As a root
user, execute the following script(s):
1.
/u01/app/oracle/product/11.2.0/dbhome_1/root.sh
Successfully
Setup Software.
##########################################################
Start
Database Upgrade Assistant to upgrade the database.
##########################################################
(root用户)执行root.sh脚本,至此11.2.0.4的软件就已经装完了,
[root@db
~]# sh /u01/app/oracle/product/11.2.0/dbhome_1/root.sh
Check
/u01/app/oracle/product/11.2.0/dbhome_1/install/root_db_2017-08-22_23-57-04.log
for the output of root script
回到上一步按回车
Successfully
Setup Software.
##########################################################
Start
Database Upgrade Assistant to upgrade the database.
##########################################################
回车
8.5 配置新环境变量,拷贝参数文件和监听文件
1.(root, oracle用户)开始配置新的ORACLEHOME环境变量,修改.bashprofile和/etc/oratab,
root用户,
[root@db
u01]# vim /root/.bash_profile #只更改/opt/为/u01即可,其它不变
export
ORACLE_BASE=/u01/app/oracle
export
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:$GGS_HOME
export
TNS_ADMIN=$ORACLE_HOME/network/admin/
[root@db
u01]# source /root/.bash_profile
oracle用户,
[root@db
~]# su – oracle
[oracle@db
~]$ vim /home/oracle/.bash_profile #更改1项新增加2项,如下,
export
ORACLE_BASE=/u01/app/oracle #更改/opt/为/u01即可
export
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export
TNS_ADMIN=$ORACLE_HOME/network/admin/ #此项为新增项
export
CLASSPATH=$ORACLE_HOME/jre:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib #此项为新增项
export
ORACLE_SID=orcl
export
ORALCE_OWNER=oracle
PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin
export PATH
export
LANG="en_US.UTF-8"
export
NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export
NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
export
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:$GGS_HOME
alias
sqlplus='rlwrap sqlplus' #注意:前面没有export
alias
rman='rlwrap rman' #注意:前面没有export
[oracle@db
~]$ vim /home/oracle/.bash_profile
#PATH=$PATH:$HOME/bin #注意这里要把原有的PATH=$PATH:$HOME/bin注释掉。
[oracle@db
~]$ source /home/oracle/.bash_profile
在10g以后,一般情况下环境变量中没有必要设置LD_LIBRARY_PATH,但是一旦将ORACLE_HOME迁移到其他目录,则环境变量中还需要添加这个变量。
完成后执行:
$ env |
grep ORA #查看环境变量是否完成
[oracle@db
~]$ env | grep ORA
ORALCE_OWNER=oracle
ORACLE_SID=orcl
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
oracle用户,
[oracle@db
~]$ vim /etc/oratab #只更改/opt/为/u01即可,其它不变
[oracle@db
~]$ egrep -v '^#|^$' /etc/oratab
orcl:/u01/app/oracle/product/11.2.0/dbhome_1:N
2.(oracle用户)将参数文件copy到新的目录下
[oracle@db
~]$ cd /opt/app/oracle/product/11.2.0/dbhome_1/dbs/ ; ll
total 24
-rw-rw----
1 oracle oinstall 1544 Aug 17 19:15 hc_DBUA0.dat
-rw-rw----
1 oracle oinstall 1544 Aug 22 22:09 hc_orcl.dat
-rw-r--r--
1 oracle oinstall 2851 May 15 2009
init.ora
-rw-r-----
1 oracle oinstall 24 Aug 17 19:19
lkORCL
-rw-r-----
1 oracle oinstall 1536 Aug 17 19:20 orapworcl
-rw-r-----
1 oracle oinstall 2560 Aug 22 21:26 spfileorcl.ora
[oracle@db
dbs]$ cp * /u01/app/oracle/product/11.2.0/dbhome_1/dbs/
3.(oracle用户)拷贝监听TNS配置文件
[oracle@db
~]$ cd /opt/app/oracle/product/11.2.0/dbhome_1/network/admin ; ll
total 20
-rw-r--r--
1 oracle oinstall 526 Aug 18 14:16
listener.ora
drwxr-xr-x
2 oracle oinstall 4096 Aug 18 14:09 samples
-rw-r--r--
1 oracle oinstall 187 May 7 2007
shrept.lst
-rw-r--r--
1 oracle oinstall 223 Aug 17 16:25
sqlnet.ora
-rw-r-----
1 oracle oinstall 321 Aug 17 19:20 s.ora
[oracle@db
admin]$ cp -R * /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/
8.6
执行升级
1.执行预升级脚本检查
[oracle@db
~]$ sqlplus /nolog
SQL*Plus:
Release 11.2.0.4.0 Production on Wed Aug 23 00:31:12 2017
Copyright
(c) 1982, 2013, Oracle. All rights
reserved.
SQL>
CONN / AS SYSDBA
Connected
to an idle instance.
SQL>
startup upgrade
ORACLE
instance started.
Total
System Global Area 1603411968 bytes
Fixed Size
2253664 bytes
Variable
Size 1006636192 bytes
Database
Buffers
587202560 bytes
Redo
Buffers 7319552 bytes
Database
mounted.
Database
opened.
SQL>
@?/rdbms/admin/utlu112i.sql ---执行升级前检查
Oracle
Database 11.2 Pre-Upgrade Information Tool 08-23-2017 01:04:17
Script
Version: 11.2.0.4.0 Build: 001
.
**********************************************************************
Database:
**********************************************************************
-->
name:
ORCL
-->
version: 11.2.0.1.0
-->
compatible: 11.2.0.0.0
-->
blocksize: 8192
-->
platform: Linux x86 64-bit
-->
timezone file: V11
.
**********************************************************************
Tablespaces:
[make adjustments in the current environment]
**********************************************************************
-->
SYSTEM tablespace is adequate for the upgrade.
....
minimum required size: 892 MB
-->
SYSAUX tablespace is adequate for the upgrade.
....
minimum required size: 641 MB
-->
UNDOTBS1 tablespace is adequate for the upgrade.
....
minimum required size: 400 MB
--> TEMP
tablespace is adequate for the upgrade.
....
minimum required size: 60 MB
.
**********************************************************************
Flashback:
ON
**********************************************************************
FlashbackInfo:
-->
name:
/opt/app/oracle/flash_recovery_area
-->
limit:
3882 MB
-->
used:
459 MB
-->
size:
3882 MB
-->
reclaim: 136.828125 MB
-->
files:
20
WARNING:
--> Flashback Recovery Area Set.
Please ensure adequate disk space in recover
y areas
before performing an upgrade.
.
**********************************************************************
Update
Parameters: [Update Oracle Database 11.2 init.ora or spfile]
Note:
Pre-upgrade tool was run on a lower version 64-bit database.
**********************************************************************
--> If
Target Oracle is 32-Bit, refer here for Update Parameters:
-- No
update parameter changes are required.
.
--> If
Target Oracle is 64-Bit, refer here for Update Parameters:
-- No
update parameter changes are required.
.
**********************************************************************
Renamed
Parameters: [Update Oracle Database 11.2 init.ora or spfile]
**********************************************************************
-- No renamed
parameters found. No changes are required.
.
**********************************************************************
Obsolete/Deprecated
Parameters: [Update Oracle Database 11.2 init.ora or spfile]
**********************************************************************
-- No
obsolete parameters found. No changes are required
.
**********************************************************************
Components:
[The following database components will be upgraded or installed]
**********************************************************************
-->
Oracle Catalog Views [upgrade] VALID
-->
Oracle Packages and Types
[upgrade] VALID
-->
JServer JAVA Virtual Machine [upgrade]
VALID
-->
Oracle XDK for Java [upgrade]
VALID
-->
Oracle Workspace Manager [upgrade] VALID
--> OLAP
Analytic Workspace [upgrade] VALID
--> OLAP
Catalog [upgrade] VALID
--> EM
Repository [upgrade] VALID
-->
Oracle Text [upgrade]
VALID
-->
Oracle XML Database [upgrade]
VALID
-->
Oracle Java Packages [upgrade] VALID
-->
Oracle interMedia [upgrade] VALID
-->
Spatial [upgrade] VALID
-->
Expression Filter [upgrade] VALID
--> Rule
Manager [upgrade] VALID
-->
Oracle Application Express
[upgrade] VALID
... APEX
will only be upgraded if the version of APEX in
... the
target Oracle home is higher than the current one.
-->
Oracle OLAP API [upgrade] VALID
.
**********************************************************************
Miscellaneous
Warnings
**********************************************************************
WARNING:
--> Database is using a timezone file older than version 14.
.... After
the release migration, it is recommended that DBMS_DST package
.... be
used to upgrade the 11.2.0.1.0 database timezone version
.... to the
latest version which comes with the new release.
WARNING:
--> Database contains INVALID objects prior to upgrade.
.... The
list of invalid SYS/SYSTEM objects was written to
....
registry$sys_inv_objs.
.... The
list of non-SYS/SYSTEM objects was written to
....
registry$nonsys_inv_objs.
.... Use
utluiobj.sql after the upgrade to identify any new invalid
....
objects due to the upgrade.
.... USER
SYS has 2 INVALID objects.
WARNING:
--> Database contains schemas with objects dependent on DBMS_LDAP package.
.... Refer
to the 11g Upgrade Guide for instructions to configure Network ACLs.
.... USER
APEX_030200 has dependent objects.
.
**********************************************************************
Recommendations
**********************************************************************
Oracle
recommends gathering dictionary statistics prior to
upgrading
the database.
To gather
dictionary statistics execute the following command
while
connected as SYSDBA:
EXECUTE dbms_stats.gather_dictionary_stats;
**********************************************************************
Oracle
recommends removing all hidden parameters prior to upgrading.
To view
existing hidden parameters execute the following command
while
connected AS SYSDBA:
SELECT name,description from
SYS.V$PARAMETER WHERE name
LIKE '\_%' ESCAPE '\'
Changes
will need to be made in the init.ora or spfile.
**********************************************************************
Oracle
recommends reviewing any defined events prior to upgrading.
To view
existing non-default events execute the following commands
while
connected AS SYSDBA:
Events:
SELECT (translate(value,chr(13)||chr(10),'
')) FROM sys.v$parameter2
WHERE
UPPER(name) ='EVENT' AND
isdefault='FALSE'
Trace Events:
SELECT (translate(value,chr(13)||chr(10),' '))
from sys.v$parameter2
WHERE UPPER(name) = '_TRACE_EVENTS' AND
isdefault='FALSE'
Changes
will need to be made in the init.ora or spfile.
**********************************************************************
2.连接数据库执行手动升级
[oracle@db
~]$ exit
logout
[root@db
~]# vim /root/.bash_profile
[root@db
~]# source /root/.bash_profile
[root@db
~]# su - oracle
[oracle@db
~]$ sqlplus /nolog
SQL*Plus:
Release 11.2.0.4.0 Production on Wed Aug 23 00:31:12 2017
Copyright
(c) 1982, 2013, Oracle. All rights
reserved.
SQL>
CONN / AS SYSDBA
Connected
to an idle instance.
SQL>
shutdown immediate
Database
closed.
Database
dismounted.
ORACLE
instance shut down.
执行:若集群则SQL> alter system set
cluster_DATABASE=false scope=spfile;
SQL>
startup upgrade
ORACLE
instance started.
Total
System Global Area 1603411968 bytes
Fixed Size
2253664 bytes
Variable
Size 1006636192 bytes
Database
Buffers
587202560 bytes
Redo
Buffers 7319552 bytes
Database
mounted.
Database
opened.
SQL> set
echo on
SQL>
spool /home/oracle/upgrade.log
SQL> set
time on;
01:19:21
SQL> @?/rdbms/admin/catupgrd.sql
01:19:36
SQL> Rem
01:19:36
SQL> Rem $Header: rdbms/admin/catupgrd.sql /st_rdbms_11.2.0/3 2011/05/18
15:07:25 cmlim Exp $
01:19:36
SQL> Rem
01:19:36
SQL> Rem catupgrd.sql
01:19:36
SQL> Rem
01:19:36
SQL> Rem Copyright (c) 1999, 2011, Oracle and/or its affiliates.
01:19:36
SQL> Rem All rights reserved.
01:19:36
SQL> Rem
01:19:36
DOC>######################################################################
01:19:36
DOC>######################################################################
01:19:36
DOC>#
01:19:36
SQL>
01:19:36
SQL> SELECT TO_NUMBER('MUST_BE_11_2_0_4') FROM v$instance
01:19:36 2
WHERE substr(version,1,8) != '11.2.0.4';
01:19:36
SQL>
01:19:36
SQL> DOC
01:19:36
DOC>#######################################################################
01:19:36
DOC>#######################################################################
01:19:36
DOC> The following statement will cause
an "ORA-01722: invalid number"
01:19:36
DOC> error if the database has not been
opened for UPGRADE.
01:19:36
DOC>
01:19:36
DOC> Perform "ALTER SYSTEM
CHECKPOINT" prior to "SHUTDOWN ABORT", and
01:19:36
DOC> restart using UPGRADE.
01:19:36
DOC>#######################################################################
01:19:36
DOC>#######################################################################
01:19:36
DOC>#
01:19:36
SQL>
01:19:36
SQL> SELECT TO_NUMBER('MUST_BE_OPEN_UPGRADE') FROM v$instance
01:19:36 2
WHERE status != 'OPEN MIGRATE';
01:19:36
SQL>
01:19:36
SQL> DOC
01:19:36
DOC>#######################################################################
01:19:36
DOC>#######################################################################
01:19:36
DOC>
The following statement will cause an "ORA-01722: invalid
number"
01:19:36
DOC>
error if the Oracle Database Vault option is TRUE. Upgrades cannot
01:19:36
DOC>
be run with the Oracle Database Vault option set to TRUE since
01:19:36
DOC>
AS SYSDBA connections are restricted.
01:19:36
DOC>
01:19:36
DOC>
Perform "ALTER SYSTEM CHECKPOINT" prior to "SHUTDOWN
ABORT", relink
01:19:36
DOC>
the server without the Database Vault option, and restart the server
01:19:36
DOC>
using UPGRADE mode.
01:19:36
DOC>
01:19:36
DOC>
01:19:36
DOC>#######################################################################
01:19:36
DOC>#######################################################################
01:19:36
DOC>#
01:19:36
SQL>
01:19:36
SQL> SELECT TO_NUMBER('DATA_VAULT_OPTION_ON') FROM v$option
01:19:36 2
WHERE
01:19:36 3 value = 'TRUE' and parameter = 'Oracle Database
Vault';
SELECT
TO_NUMBER('DATA_VAULT_OPTION_ON') FROM v$option
*
ERROR at
line 1:
ORA-01722:
invalid number
Disconnected
from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit
Production
With the
Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle
Database Vault and Real Application Testing options
【报错原因】
该数据库实例配置了Oracle Database Vault功能。
什么是Oralce Database Vault:
OracleDatabase
Vault 可帮助用户解决现有的极为棘手的安全问题,即防止内部的威胁,满足合规性要求以及实现职责划分。Oracle
Database Vault 能防止
DBA 查看应用程序数据,解决了必须保护涉及合作伙伴、员工和顾客的敏感业务信息或隐私数据的客户最为担心的问题。Oracle
Database Vault 可防止高权限的应用程序
DBA 访问其他的应用程序、执行其权限之外的任务。Oracle
Database Vault 可以轻松快捷地保护现有应用程序,且不影响应用程序的功能。
【解决方法】
关闭Oracle Database Vault功能后,重新执行升级操作。
关闭Oracle Database Vault功能:什么是Oralce Database
Vault:
OracleDatabase Vault 可帮助用户解决现有的极为棘手的安全问题,即防止内部的威胁,满足合规性要求以及实现职责划分。Oracle Database Vault 能防止 DBA 查看应用程序数据,解决了必须保护涉及合作伙伴、员工和顾客的敏感业务信息或隐私数据的客户最为担心的问题。Oracle Database Vault 可防止高权限的应用程序 DBA 访问其他的应用程序、执行其权限之外的任务。Oracle Database Vault 可以轻松快捷地保护现有应用程序,且不影响应用程序的功能。
[oracle@db
~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Wed Aug 23 01:28:00 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition
Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> col parameter for a30
SQL> col value for a20
SQL> SELECT * FROM V$OPTION WHERE PARAMETER = 'Oracle Database Vault';
PARAMETER
VALUE
------------------------------
--------------------
Oracle Database Vault TRUE
# 关闭数据库实例
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
[oracle@db ~]$ emctl stop dbconsole
Environment variable
ORACLE_UNQNAME not defined. Please set ORACLE_UNQNAME to database unique name.
[oracle@db ~]$ lsnrctl stop
SQL> alter system checkpoint;
SQL> shutdown abort;
SQL> exit
[oracle@db ~]$ cd
$ORACLE_HOME/rdbms/lib/
[oracle@db lib]$ pwd
/u01/app/oracle/product/11.2.0/dbhome_1/rdbms/lib
[oracle@db lib]$ chopt disable dv
Writing to /u01/app/oracle/product/11.2.0/dbhome_1/install/disable_dv.log...
/usr/bin/make -f
/u01/app/oracle/product/11.2.0/dbhome_1/rdbms/lib/ins_rdbms.mk dv_off
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
/usr/bin/make -f
/u01/app/oracle/product/11.2.0/dbhome_1/rdbms/lib/ins_rdbms.mk ioracle
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
[oracle@db lib]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Wed Aug 23 01:45:46 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> spool
/home/oracle/upgrade.log
SQL> startup upgrade;
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size 2253664 bytes
Variable Size 1006636192 bytes
Database Buffers 587202560 bytes
Redo Buffers 7319552 bytes
Database mounted.
Database opened.
SQL> SELECT * FROM V$OPTION WHERE PARAMETER = 'Oracle Database Vault';
PARAMETER
----------------------------------------------------------------
VALUE
----------------------------------------------------------------
Oracle Database Vault
FALSE
接着再次执行升级OK,
SQL> set echo on
SQL> spool
/home/oracle/upgrade.log
SQL> set time on;
02:09:05 SQL>
@?/rdbms/admin/catupgrd.sql ---该脚本会运行30分钟左右
Commit complete.
02:40:05 SQL>
02:40:05 SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
02:40:29 SQL>
02:40:29 SQL>
02:40:29 SQL> DOC
02:40:29
DOC>#######################################################################
02:40:29
DOC>#######################################################################
02:40:29 DOC>
02:40:29 DOC> The above sql script is the final step of the upgrade. Please
02:40:29 DOC> review any errors in the spool log file. If there are any errors in
02:40:29 DOC> the spool file, consult the Oracle Database Upgrade Guide for
02:40:29 DOC> troubleshooting recommendations.
02:40:29 DOC>
02:40:29 DOC> Next restart for normal operation, and then run utlrp.sql to
02:40:29 DOC> recompile any invalid application objects.
02:40:29 DOC>
02:40:29 DOC> If the source database had an older time zone version prior to
02:40:29 DOC> upgrade, then please run the DBMS_DST package. DBMS_DST will upgrade
02:40:29 DOC> TIMESTAMP WITH TIME ZONE data to use the latest time zone file shipped
02:40:29 DOC> with Oracle.
02:40:29 DOC>
02:40:29 DOC>#######################################################################
02:40:29
DOC>#######################################################################
02:40:29 DOC>#
02:40:29 SQL>
02:40:29 SQL> Rem Set errorlogging off
02:40:29 SQL> SET ERRORLOGGING OFF;
02:40:29 SQL>
02:40:29 SQL> REM END OF CATUPGRD.SQL
02:40:29 SQL>
02:40:29 SQL> REM bug 12337546 - Exit current sqlplus session at end of catupgrd.sql.
02:40:29 SQL> REM This forces user to start a new sqlplus session in order
02:40:29 SQL> REM to connect to the upgraded db.
02:40:29 SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition
Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
以上catupgrd.sql脚本整整运行了31分钟,执行完之后会shutdown immediate数据库。这个时候我们将要重启数据库运行utlrp.sql脚本编译失效对象:
3.运行utlrp.sql编译失效对象
[oracle@db
~]$ sqlplus / AS SYSDBA
SQL*Plus: Release 11.2.0.4.0 Production on Wed Aug 23 03:07:50 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size 2253664 bytes
Variable Size 1140853920 bytes
Database Buffers 452984832 bytes
Redo Buffers 7319552 bytes
Database mounted.
Database opened.
SQL> @?/rdbms/admin/utlrp
TIMESTAMP
--------------------------------------------------------------------------------
COMP_TIMESTAMP UTLRP_BGN 2017-08-23 03:09:23
DOC> The following PL/SQL block invokes UTL_RECOMP to recompile invalid
DOC> objects in the database. Recompilation time is proportional to the
DOC> number of invalid objects in the database, so this command may take
DOC> a long time to execute on a database with a large number of invalid
DOC> objects.
DOC>
DOC> Use the following queries to track recompilation progress:
DOC>
DOC> 1. Query returning the number of invalid objects remaining. This
DOC> number should decrease with time.
DOC> SELECT COUNT(*) FROM obj$ WHERE status IN (4, 5, 6);
DOC>
DOC> 2. Query returning the number of objects compiled so far. This number
DOC>
should increase with time.
DOC> SELECT COUNT(*) FROM UTL_RECOMP_COMPILED;
DOC>
DOC> This script automatically chooses serial or parallel recompilation
DOC> based on the number of CPUs available (parameter cpu_count) multiplied
DOC> by the number of threads per CPU (parameter
parallel_threads_per_cpu).
DOC> On RAC, this number is added across all RAC nodes.
DOC>
DOC> UTL_RECOMP uses DBMS_SCHEDULER to create jobs for parallel
DOC> recompilation. Jobs are created without instance affinity so that they
DOC> can migrate across RAC nodes. Use the following queries to verify
DOC> whether UTL_RECOMP jobs are being created and run correctly:
DOC>
DOC> 1. Query showing jobs created by UTL_RECOMP
DOC> SELECT job_name FROM dba_scheduler_jobs
DOC> WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>
DOC> 2. Query showing UTL_RECOMP jobs that are running
DOC> SELECT job_name FROM dba_scheduler_running_jobs
DOC> WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>#
PL/SQL procedure successfully completed.
TIMESTAMP
--------------------------------------------------------------------------------
COMP_TIMESTAMP UTLRP_END 2017-08-23 03:11:07
DOC> The following query reports the number of objects that have compiled
DOC> with errors.
DOC>
DOC> If the number is higher than expected, please examine the error
DOC> messages reported with each object (using SHOW ERRORS) to see if they
DOC> point to system misconfiguration or resource constraints that must be
DOC> fixed before attempting to recompile these objects.
DOC>#
OBJECTS WITH ERRORS
-------------------
0
DOC> The following query reports the number of errors caught during
DOC> recompilation. If this number is non-zero, please query the error
DOC> messages in the table UTL_RECOMP_ERRORS to see if any of these errors
DOC> are due to misconfiguration or resource constraints that must be
DOC> fixed before objects can compile successfully.
DOC>#
ERRORS DURING RECOMPILATION
---------------------------
0
Function created.
PL/SQL procedure successfully completed.
Function dropped.
PL/SQL procedure successfully completed.
该脚本耗时约为3分钟左右。
至此数据库已经升级完成,
七、升级后的检查确认
1.查看各组件版本号:
测试是否成功:
[oracle@db response]$ sqlplus
/ AS SYSDBA
SQL*Plus: Release 11.2.0.4.0 Production on Wed Aug 23 18:56:23 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition
Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL> select name from v$database; #确认数据库的SID是否正确。
SQL> show user; #确认当前是否为sys用户。
SQL> select tablespace_name, bytes/1024/1024 from dba_data_files; #确认表空间大小是否正确.
SQL>
@$ORACLE_HOME/rdbms/admin/utlu112i.sql
Oracle Database 11.2 Pre-Upgrade Information Tool
08-23-2017 18:58:39
Script Version: 11.2.0.4.0 Build: 001
.
**********************************************************************
Database:
**********************************************************************
-->
name:
ORCL
-->
version: 11.2.0.4.0
-->
compatible: 11.2.0.0.0
-->
blocksize: 8192
-->
timezone file: V11
.
Database already upgraded; to rerun upgrade use rdbms/admin/catupgrd.sql.
SQL> select * from v$version;或者select * from dba_registry; 或 select comp_name,status,version from dba_server_registry;
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition
Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
#下面这个步骤网文中没有,这是尚观视频中提到的,作用不明.
SQL>
@$ORACLE_HOME/rdbms/admin/catalog.sql
#最后,重启数据库没有问题就是升级成功了。
SQL> select status from v$instance;
STATUS
------------
OPEN #注意,成功打开数据库后,这里将是OPEN,而非OPEN MIGRATE
Shutdown and Enable Oracle database Vault option and START the database
打开Oracle Database Vault功能,
SQL> shutdown immediate;
[oracle@db ~]$ chopt enable dv
[oracle@db ~]$ . oraenv
[oracle@db ~]$ dev
[oracle@db ~]$ sqlplus / as sysdba
SQL> startup
SQL> SELECT * FROM V$OPTION WHERE PARAMETER = 'Oracle Database Vault';
PARAMETER VALUE
----------------------------------------------------------------
--------------------------------------
Oracle Database Vault TRUE
[oracle@db response]$ sqlplus
trade02/oracle #测试也可正常登录普通用户
SQL*Plus: Release 11.2.0.4.0 Production on Wed Aug 23 18:55:15 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition
Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL>
2.检查无效对象
SQL> select * from dba_objects where status !='VALID';
no rows selected
SQL> SELECT count(*) FROM dba_objects WHERE status='INVALID';
0
3.升级成功后删除原来的目录,通过EMCA重建EM
此EM本来就没有故这一步可忽略,
[oracle@db01
/]$ rm -rf /opt/app/oracle
手工创建EM资料库:
####emca
-repos drop
[oracle@db01
/]$ emca -reposdrop
####emca
-repos create
[oracle@db01
/]$ emca -reposcreate
###emca
-config dbcontrol db
[oracle@db01
/]$ emca-config dbcontrol db
4.开启集群(只限集群用户)
单实例不用执行此语句,恢复数据库为集群数据库,非集群数据库不用执行,
SQL> alter system set cluster_DATABASE=true
scope=spfile;
5.打开监听,然后用PL/SQL developer连接和查询没有问题,
[oracle@db
~]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 23-AUG-2017 03:46:09
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Starting
/u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Log messages written to
/opt/app/oracle/diag/tnslsnr/db/listener/alert/log.xml
Listening on:
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Listening on:
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db)(PORT=1521)))
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 23-AUG-2017 03:46:10
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File
/opt/app/oracle/diag/tnslsnr/db/listener/alert/log.xml
Listening Endpoints
Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed
successfully
PL/SQL developer用普通用户trade02登录执行下面的语句,正常,
select * from wang where id=1 or id=2 or id=6;
select comp_name,status,version from dba_server_registry;