Table of Contents
Toggle一、安装Oracle
之前因工作企业性质没过多接触Oracle,今天项目需要手动迁移数据,调整参数的时候干崩了测试环境Oracle,因祸得福,自我救赎,卸掉重新搭建了一遍,也算一口气熟悉了Oracle。
环境:
CentOS7非图形操作系统
Oracle11g
安装依赖
rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel expat gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make pdksh sysstat unixODBC unixODBC-devel | grep “not installed”
过一遍服务器环境,缺哪个下哪个。其中pdksh不常用,yum没有找到资源,手动安装
wget -O /tmp/pdksh-5.2.14-37.el5_8.1.x86_64.rpm http://vault.centos.org/5.11/os/x86_64/CentOS/pdksh-5.2.14-37.el5_8.1.x86_64.rpm
rpm -ivh pdksh-5.2.14-37.el5_8.1.x86_64.rpm
添加Linux用户组
groupadd oinstall
groupadd dba
groupadd asmadmin
groupadd asmdba
useradd -g oinstall -G dba,asmdba oracle -d /home/oracle
passwd oracle
操作系统参数优化
vim /etc/sysctl.conf
fs.aio-max-nr=1048576
fs.file-max=6815744
kernel.shmall=2097152
kernel.shmmni=4096
kernel.shmmax = 1073741824
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
出来刷新sysctl -p
限制用户权限
vim /etc/security/limits.conf
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
配置环境变量
su – oracle
vim .bash_profile
umask 022
export ORACLE_HOSTNAME=centos-orcl
export ORACLE_BASE=/usr/local/oracle export
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/
export ORACLE_SID=ORCL
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”
环境准备结束,重启开始安装
reboot
解压缩安装包到指定目录
unzip linux.x64_11gR2_database_1of2.zip -d /usr/local
unzip linux.x64_11gR2_database_2of2.zip -d /usr/local
cp /usr/local/database/response/* /usr/local/etc/
修改安装参数
vim /usr/local/etc/db_install.rsp
oracle.install.option=INSTALL_DB_SWONLY
DECLINE_SECURITY_UPDATES=true
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/usr/local/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOSTNAME=centos-oracle
ORACLE_HOME=/usr/local/oracle/product/11.2.0
ORACLE_BASE=/usr/local/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=true
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
执行安装
su – oracle
./usr/local/database/runInstaller -silent -ignorePrereq -responseFile /usr/local/etc/db_install.rsp
一直等看到1-4选项敲回车即可
su root
sh /usr/local/oracle/inventory/orainstRoot.sh
sh /usr/local/oracle/product/11.2.0/root.sh
配置静默监听
su – oracle
netca /silent /responsefile /usr/local/etc/netca.rsp
修改数据库创建参数
vi /usr/local/etc/dbca.rsp
GDBNAME = “orcl”
SID = “orcl”
SYSPASSWORD = “oracle”
SYSTEMPASSWORD = “oracle”
SYSMANPASSWORD = “oracle”
DBSNMPPASSWORD = “oracle”
DATAFILEDESTINATION =/usr/local/oracle/oradata
RECOVERYAREADESTINATION=/usr/local/oracle/fast_recovery_area
CHARACTERSET = “AL32UTF8”
TOTALMEMORY = “1638”
静默创建数据库
dbca -silent -createDatabase -cloneTemplate -responseFile /usr/local/etc/dbca.rsp
看到【Instance/Database】都创建成功,进度条跑完100%为止
查看Oracle实例,没有结果有问题需要检查一下以上步骤
ps -ef | grep ora_ | grep -v grep
查看监听状态
lsnrctl status
注意倒数几行是否有【The listener supports no services】提示,如果有需要添加设置
vim /usr/local/oracle/product/11.2.0/network/admin/listener.ora
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
#BEQUEATH CONFIG
(GLOBAL_DBNAME=orcl)
(SID_NAME=orcl)
(ORACLE_HOME=/u01/app/oracle/product/11.2)
#PRESPAWN CONFIG
(PRESPAWN_MAX=20)
(PRESPAWN_LIST=
(PRESPAWN_DESC=(PROTOCOL=tcp)(POOL_SIZE=2)(TIMEOUT=1)
) ) ) )
改完重启监听
lsnrctl reload
登录命令行启动
sqlplus / as sysdba
startup
二、卸载Oracle
相比复杂的安装,卸载会很爽
关闭Oracle服务
sqlplus / as sysdba
shutdown immediate
exit
停掉监听
lsnrctl stop
直接删除根目录
rm -rf /usr/local/oracle
删除用户
userdel oracle
删除用户邮箱和home文件夹
rm -f /var/mail/oracle
rm -rf /home/oracle
删除bin目录文件
rm -f /usr/local/bin/dbhome
rm -f /usr/local/bin/oraenv
rm -f /usr/local/bin/oraenv
删除oratab
rm -f /etc/oratab
删除oraInst
rm -f /etc/oraInst.loc
删除用户组
groupdel oinstall
groupdel dba
groupdel asmadmin
groupdel asmdba
删除启动服务器
chkconfig –del dbora
结束
三、常用指令
命令行登录
sqlplus /nolog
启动服务
startup
连接其他用户
conn me/me123
conn / as sysdba
查看实例名称
select instance_name from V$instance;
查看服务名称,用以ServerName连接方式
show parameter service_names;
select service_name from v$session where sid=(select distinct(sid) from v$mystat);
修改服务名称
alter system set serviece_names=’orcl’ scope=both;
查看和修改编码格式
select * from v$nls_parameters where parameter = ‘NLS_LENGTH_SEMANTICS’;
ALTER SYSTEM SET NLS_LENGTH_SEMANTICS=CHAR scope=BOTH;
Update props$ set VALUE$=’char’ Where name=’NLS_LENGTH_SEMANTICS’;
【第三句慎用,我打错一个字母才有的这篇文章】
创建表空间
mkdir -p /usr/local/oracle/database/Db_Name
CREATE TABLESPACE Db_Name LOGGING DATAFILE ‘/usr/local/oracle/database/Db_Name/Db_Name.dbf’ SIZE 5000M AUTOEXTEND ON NEXT 500M MAXSIZE unlimited;
初始5G,每次增加500M,增加没有上限
创建用户
CREATE USER gld IDENTIFIED BY gld123 DEFAULT TABLESPACE Db_Name;
这里设置了一个用户的默认schema,非必选
修改用户密码
alter user monitor identified by 123456;
修改密码会锁定用户,解锁
alter user monitor account unlock;
删除用户
drop user gld
用户权限赋予
grant connect,resource,dba to gld;
grant create session to gld;
【必须有创建会话权限才能远程访问和备份恢复】
撤销权限
revoke connect, resource from gld;
恢复备份数据泵
imp gld/gld123 file=/home/oracle/2021.11.19/kj-2021.11.19.dmp ignore=y full=y
imp gld/gld123 file=/home/oracle/2021.11.19/app-2021.11.19.dmp ignore=y full=y
imp gld/gld123 file=/home/oracle/2021.11.19/sys-2021.11.19.dmp ignore=y full=y
删除表空间
drop tablespace GLODON including contents and datafiles;
修改表空间大小
ALTER TABLESPACE demo RESIZE 5G;
修改用户默认数据库
alter user glodon default tablespace demo;
修改表空间最大空间
alter database GLODON ‘D:\DataBase\Test.DBF’ autoextend on maxsize unlimited;
四、报错处理
LRM-00109: could not open parameter file ‘/usr/local/oracle/product/11.2.0/dbs/initORCL.ora’
cp /usr/local/oracle/admin/test/pfile/init.ora.xxxxxxx
/usr/local/oracle/product/11.2.0/dbs/initORCL.ora
ORA-00205: error in identifying control file, check alert log for more info
需要查看/usr/local/oracle/product/11.2.0/rdbms/log最新的日志信息
大概率是少数据库控制文件,数据库创建有问题,往上翻重新做一个库试试
权限问题
确认/usr/local/oracle下所有文件夹必须是oracle:oinstall权限,不是root
Oracle数据同步长度报错,修改Oracle编码为GBK:
shutdown immediate
startup mount
ALTER SYSTEM ENABLE RESTRICTED SESSION;
ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
ALTER SYSTEM SET AQ_TM_PROCESSES=0;
alter database open;
ALTER DATABASE CHARACTER SET ZHS16GBK;
ALTER DATABASE character set INTERNAL_USE ZHS16GBK;
shutdown immediate
startup
TNS-01201: Listener cannot find executable /usr/local/oracle/product/11.2/bin/oracle
vim /usr/local/oracle/product/11.2.0/network/admin/listener.ora
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
#BEQUEATH CONFIG
(GLOBAL_DBNAME=orcl)
(SID_NAME=orcl)
(ORACLE_HOME=/usr/local/oracle/product/11.2.0)
#PRESPAWN CONFIG
(PRESPAWN_MAX=20)
(PRESPAWN_LIST=
(PRESPAWN_DESC=(PROTOCOL=tcp)(POOL_SIZE=2)(TIMEOUT=1)
) ) ) )