Oracle循序渐进

单机部署

二进制安装

1.环境准备
主机详情

主机名 ip 操作系统 内存 硬盘 备注
oracleDBA 192.168.175.121 centos7.6 2g 1T oracle数据库

oracle软件下载

2.关闭防火墙
操作用户:root

sed -i 's/enforcing/disabled/g' /etc/selinux/config
setenforce 0
systemctl stop firewalld.service
systemctl disable firewalld.service

3.安装依赖包
操作用户为:root。

执行如下命令安装依赖包。

yum install -y automake autotools-dev binutils bzip2 elfutils expat \
gawk gcc gcc-multilib g++-multilib lib32ncurses5 lib32z1 \
ksh less lib32z1 libaio1 libaio-dev libc6-dev libc6-dev-i386 \
libc6-i386 libelf-dev libltdl-dev libodbcinstq4-1 libodbcinstq4-1:i386 \
libpth-dev libpthread-stubs0-dev libstdc++5 make openssh-server rlwrap \
rpm sysstat unixodbc unixodbc-dev unzip x11-utils zlibc unzip cifs-utils \
libXext.x86_64  glibc.i686

如果上述命令报错,则使用如下命令安装

yum -y install xz wget gcc-c++ ncurses ncurses-devel \
cmake make perl openssl openssl-devel gcc* libxml2 \
libxml2-devel curl-devel libjpeg* libpng* freetype* \
make gcc-c++ cmake bison perl perl-devel  perl perl-devel \
glibc-devel.i686 glibc-devel libaio readline-devel \
zlib.x86_64 zlib-devel.x86_64 libcurl-* net-tool*  \
sysstat lrzsz dos2unix telnet.x86_64 iotop unzip \
ftp.x86_64 xfs* expect vim psmisc openssh-client* \
libaio bzip2  epel-release automake binutils bzip2 \
elfutils expat gawk gcc  ksh less make openssh-server \
rpm sysstat unzip unzip cifs-utils libXext.x86_64  \
glibc.i686 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 sysstat unixODBC unixODBC-devel libnsl

4.创建oracle用户
操作用户为:root

groupadd -g 502 oinstall
groupadd -g 503 dba
groupadd -g 504 oper
groupadd -g 505 asmadmin
useradd -u 502 -g oinstall -G oinstall,dba,asmadmin,oper -s /bin/bash -m oracle
passwd oracle

上述命令执行完毕后,为oracle用户设置密码,例如,我这里设置的密码为123456

5.解压Oracle数据库安装包
操作用户:oracle
操作目录:/home/oracle

将Oracle 11gR2安装文件上传(可以使用sftp上传)到该操作目录下面,然后顺序解压安装文件到该目录。

unzip linux.x64_11gR2_database_1of2.zip
unzip linux.x64_11gR2_database_2of2.zip

6.修改操作系统配置
操作用户:root
操作文件:/etc/security/limits.conf

vim /etc/security/limits.conf
#在文件的末尾添加如下配置项。
oracle          soft      nproc   2047
oracle          hard      nproc   16384
oracle          soft      nofile  1024
oracle          hard      nofile  65536
oracle          soft      stack   10240

7.修改环境变量
操作用户:oracle
操作目录:/home/oracle

vim ~/.bash_profile
#在文件末尾添加如下配置项
export ORACLE_BASE=/home/oracle/tools/oracle11g
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export ORACLE_UNQNAME=orcl
export NLS_LANG=.AL32UTF8
export PATH=${PATH}:${ORACLE_HOME}/bin/:$ORACLE_HOME/lib64

#使得环境变量生效。
source ~/.bash_profile

8.调整swap空间大小

su - root
# 查看swap大小
free -m
# 增加交换分区文件及大小,如果要增加2G大小的交换分区,则命令写法如下,其中的 count 等于想要的块大小。
dd if=/dev/zero of=/home/swap bs=1024 count=2048000
# 设置交换文件
mkswap /home/swap
# 立即启用交换分区文件
swapon /home/swap
# 如果要在引导时自动启用,则编辑 /etc/fstab 文件,添加行
/home/swap swap swap defaults 0 0

9.内核参数调整

kernel.shmall = xxx  #填入命令echo "`cat /proc/meminfo | grep "MemTotal" | awk '{print $2}'` / (`getconf PAGESIZE` / 1024)" | bc 的运行结果
kernel.shmmax = xxx  #填入命令echo "`cat /proc/meminfo | grep "MemTotal" | awk '{print $2}'` * 1024 * 0.8" | bc  | sed 's#\..*$##' 的运行结果

kernel.shmmni = 4096 
kernel.sem = 250 32000 100 128 

fs.file-max = 6815744
fs.aio-max-nr = 1048576

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 = 104857

vm.swappiness = 0
vm.dirty_background_ratio = 3
vm.dirty_ratio = 80
vm.dirty_expire_centisecs = 500
vm.dirty_writeback_centisecs = 100

sysctl -p   使参数生效

10.修改Oracle配置文件
操作用户:oracle
操作目录:/home/oracle

复制文件模板

su oracle
cd /home/oracle
cp /home/oracle/database/response/db_install.rsp .

对db_install.rsp文件进行编辑。

vim db_install.rsp
oracle.install.option=INSTALL_DB_AND_CONFIG
ORACLE_HOSTNAME=localhost #实际上可以修改成你自己的主机名或者域名(IP)
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/home/oracle/tools/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/home/oracle/tools/oracle11g/product/11.2.0/dbhome_1
ORACLE_BASE=/home/oracle/tools/oracle11g
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oper
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=1024
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.password.ALL=Oracle#123456
oracle.install.db.config.starterdb.control=DB_CONTROL
oracle.install.db.config.starterdb.dbcontrol.enableEmailNotification=false
oracle.install.db.config.starterdb.dbcontrol.emailAddress=test@qq.com #可以填写你自己的邮箱地址
oracle.install.db.config.starterdb.automatedBackup.enable=false
oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/home/oracle/tools/oracle11g/oradata
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/home/oracle/tools/oracle11g/fast_recovery_area
oracle.install.db.config.starterdb.automatedBackup.enable=false
DECLINE_SECURITY_UPDATES=true

11.静默安装Oracle 11gR2
操作用户:oracle
操作目录:/home/oracle/database

cd /home/oracle/database
./runInstaller -silent -ignoreSysPrereqs -responseFile /home/oracle/db_install.rsp -ignorePrereq
接下来,就是默默的等待Oracle自行安装了,等待一段时间后,如果输出如下信息,则表明Oracle数据库已经安装成功。
The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root scripts to run

/home/oracle/tools/oraInventory/orainstRoot.sh
/home/oracle/tools/oracle11g/product/11.2.0/dbhome_1/root.sh
To execute the configuration scripts:
	 1. Open a terminal window 
	 2. Log in as "root" 
	 3. Run the scripts 
	 4. Return to this window and hit "Enter" key to continue 

Successfully Setup Software.

12.安装完成
操作用户:root
根据上一步完成信息提示,执行以下两行命令,具体位置需要根据你的安装位置决定:

/home/oracle/tools/oraInventory/orainstRoot.sh
/home/oracle/tools/oracle11g/product/11.2.0/dbhome_1/root.sh

13.创建连接用户
操作用户:oracle

sqlplus /nolog
conn /as sysdba
startup

接下来,执行如下命令。

alter user system identified by system;
alter user sys identified by sys;

创建连接用户。

create user SYNC identified by SYNC;
grant connect,resource,dba to SYNC;

14.验证安装结果
1.启动数据库
启动已经安装的数据库orcl。

操作用户oracle

启动监听

lsnrctl  start
启动数据库过程如下:

sqlplus /nolog
使用dba权限连接Oralce

connect / as sysdba
启动数据库

startup
确认启动结果:

ORACLE instance started.

Total System Global Area  534462464 bytes
Fixed Size                  2215064 bytes
Variable Size            373293928 bytes
Database Buffers          150994944 bytes
Redo Buffers                7958528 bytes
Database mounted.
Database opened.

15.验证数据库
这里,我们使用Navicat连接Oracle数据库,如下所示

这里,输入的用户名为SYNC,密码为SYNC。

接下来,点击“连接测试”,如下所示。

可以看到,Oracle数据库连接成功。

docker安装oracle

安装docker

yum install -y yum-utils
yum-config-manager \
    --add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 
yum makecache fast
yum install docker-ce docker-ce-cli containerd.io -y
systemctl start docker
systemctl enable docker
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://z8wfi803.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker

安装oracle
开始拉取oracle镜像

docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

创建容器

mkdir /oracle/mydata
docker run -d -p 1521:1521 --name oracle11g -v /oracle/mydata:/mydata registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

进入镜像进行配置

docker exec -it oracle11g bash
su root
输入密码:helowin

vi /etc/profile
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2
export ORACLE_SID=helowin
export PATH=$ORACLE_HOME/bin:$PATH

source /etc/profile
ln -s $ORACLE_HOME/bin/sqlplus /usr/bin

su - oracle
sqlplus / as sysdba
alter user system identified by system;--修改system用户账号密码;
alter user sys identified by system;--修改sys用户账号密码;
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED; --修改密码规则策略为密码永不过期;
alter system set processes=2000 scope=spfile; --修改数据库最大连接数据;
shutdown immediate; --关闭数据库
startup; --启动数据库

docker-compose安装oracle

1、编写docker-compose.yml

mkdir /data/app/oracle
mkidr /data/app/oracle/{data,mydata} -p
vi docker-compose.yml
version: '3.1'
services:
  master:
    image: registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g:latest
    container_name: oracle
    privileged: true
    ports:
      - 1521:1521
    volumes:
      - ./mydata:/home/oracle/mydata:rw

2、启动容器,并进入容器

docker-compose up -d
docker exec -it oracle bash

3、配置环境,并创建一个用户,实现外部连接

cd /home/oracle                                           # 进入到 oracle 用户目录
source .bash_profile                                      # 加载 oracle 环境变量
$PATH                                                     # 查看 oracle 环境变量是否生效
sqlplus / as sysdba                                       # 连接 oracle 数据库
alter user system identified by oracle;                   # 修改 DBA 账号的密码
alter user sys identified by oracle;                      # 修改 DBA 账号的密码
alter profile default limit password_life_time unlimited; # 设置密码为永不过期
create user test identified by oracle;                    # 创建一个 test 用户,密码 oracle
select * from dba_users t where t.username = 'TEST';      # 查询用户是否创建成功
grant connect, resource to test;                          # 给用户授予连接和数据权限

4、相关配置(可省略)

grant select on V_$session to test;
grant select on V_$sesstat to test;
grant select on V_$statname to test;
show parameter deferred_segment_creation;          -- 查看是否启用 true 为启动
alter system set deferred_segment_creation=false;  -- 修改为不启用
show parameter deferred_segment_creation;          -- 查看是否修改成功 false 未启用

5、数据持久化

docker cp oracle:/home/oracle/app/oracle/oradata/helowin /data/app/oracle/data/helowin
chown -R 500.500 /data/app/oracle/data/helowin
docker-compose down
vi docker-composr.yml
version: '3.1'
services:
  master:
    image: registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g:latest
    container_name: oracle
    privileged: true
    ports:
      - 1521:1521
    volumes:
      - ./data/helowin:/home/oracle/app/oracle/oradata/helowin:rw
      - ./mydata:/home/oracle/mydata:rw
docker-compose up -d

docker logs -f oracle

6、进入容器内,解决错误

docker exec -it oracle bash
cd /home/oracle              # 进入到 oracle 用户目录
source .bash_profile         # 加载 oracle 环境变量(每次进入容器都要加载配置文件)

# 删除新生成的版本控制文件,将数据卷中的版本控制文件复制为新生成的版本控制文件
rm -rf /home/oracle/app/oracle/flash_recovery_area/helowin/control02.ctl
cp /home/oracle/app/oracle/oradata/helowin/control01.ctl /home/oracle/app/oracle/flash_recovery_area/helowin/control02.ctl

sqlplus / as sysdba          # 以 dba 身份连接 oracle 数据库
shutdown immediate           # 关闭数据库实例(这里会报错,不用管)
startup                      # 启动实例

集群部署

常见命令

sql

查看表空空间

  SELECT A.TABLESPACE_NAME "表空间名",
         A.TOTAL_SPACE "总空间(G)",
         NVL(B.FREE_SPACE, 0) "剩余空间(G)",
         A.TOTAL_SPACE - NVL(B.FREE_SPACE, 0) "使用空间(G)",
         CASE WHEN A.TOTAL_SPACE=0 THEN 0 ELSE trunc(NVL(B.FREE_SPACE, 0) / A.TOTAL_SPACE * 100, 2) END "剩余百分比%" --避免分母为0
     FROM (SELECT TABLESPACE_NAME, trunc(SUM(BYTES) / 1024 / 1024/1024 ,2) TOTAL_SPACE
            FROM DBA_DATA_FILES
           GROUP BY TABLESPACE_NAME) A,
         (SELECT TABLESPACE_NAME, trunc(SUM(BYTES / 1024 / 1024/1024  ),2) FREE_SPACE
          FROM DBA_FREE_SPACE
          GROUP BY TABLESPACE_NAME) B
   WHERE A.TABLESPACE_NAME = B.TABLESPACE_NAME(+)
   ORDER BY 5; 

删除用户/删除对应表空间

drop user hyyf1 cascade;
drop tablespace hyyf1 including contents and datafiles cascade constraint;

创建表空间

create bigfile tablespace hyyf1 logging datafile '/home/oracle/tools/oracle11g/oradata/orcl/hyyf1.dbf' size 100m autoextend on next 50m maxsize 40960m extent management local;

创建用户并指定表空间

create user hyyf1 identified by hyyf12345678 default tablespace hyyf1 temporary tablespace temp profile default;
//给用户授予权限
grant connect,resource to hyyf1;
grant dba to hyyf1;

修改用户的默认表空间

查看临时表空间

SELECT 
    TABLESPACE_NAME, FILE_NAME, BYTES/1024/1024 "CURR_SIZE(MB)", MAXBYTES/1024/1024 "MAX_SIZE(MB)",AUTOEXTENSIBLE 
FROM 
    DBA_TEMP_FILES;

查看临时表空间使用率

SELECT 
    TABLESPACE_NAME, TABLESPACE_SIZE/1024/1024 AS "TABLESPACE_SIZE(MB)", 
    ALLOCATED_SPACE/1024/1024 AS "ALLOCATED_SIZE(MB)", FREE_SPACE/1024/1024 AS "FREE_SIZE(MB)", 
    round(((TABLESPACE_SIZE - FREE_SPACE)/TABLESPACE_SIZE)*100,2) AS "USED_RATE(%)"
FROM 
    DBA_TEMP_FREE_SPACE;

查看各用户的表空间位置

    select s.name, d.name from v$datafile d, v$tablespace s where d.ts# = s.ts# order by 1;

查看用户和默认表空间的关系。

select   username,default_tablespace   from   dba_users;

查看表结构

desc 表名

查看当前用户的表:

select  table_name from user_tables;

查看所有用户的表名:

select   table_name  from all_tables;

查看所有表名(其中包括系统表)

select  table_name  from all_tables;

查看所有的表:

select  *  from  tab/dba_tables/dba_objects/cat;

Oracle查询用户表空间:

select * from user_all_tables

Oracle查询所有函数和储存过程:

select * from user_source

Oracle查询所有用户:

select * from all_users.select * from dba_users

Oracle查看当前用户连接:

select count(*) from v$Session

Oracle查看当前用户权限:

select * from session_privs

Oracle查看用户表空间使用情况:

select a.file_id "FileNo",a.tablespace_name

"Tablespace_name",

a.bytes "Bytes",a.bytes-sum(nvl(b.bytes,0)) "Used",

sum(nvl(b.bytes,0)) "Free",

sum(nvl(b.bytes,0))/a.bytes*100 "%free"

from dba_data_files a, dba_free_space b

where  a.file_id  = b  .file_id(+)

group by a.tablespace_name ,

a.file_id,a.bytes order by a.tablespace_name;

select

b.file_name 物理文件名,

b.tablespace_name 表空间,

b.bytes/1024/1024 大小M,

(b.bytes-sum(nvl(a.bytes,0)))/1024/1024 已使用M,

substr((b.bytes-sum(nvl(a.bytes,0)))/(b.bytes)*100,1,5) 利用率

from dba_free_space a,dba_data_files b

where a.file_id=b.file_id and b.tablespace_name='HRSM'

group by b.tablespace_name,b.file_name,b.bytes

order by b.tablespace_name

查看所有用户:

select * from dba_user;

select * from all_users;

select * from user_users;

查看用户系统权限:

select * from dba_sys_privs;

select * from all_sys_privs;

select * from user_sys_privs;

查看用户对象权限:

select * from dba_tab_privs;

select * from all_tab_privs;

select * from user_tab_privs;

查看所有角色:

select * from dba_roles;

查看用户所拥有的角色:

select * from dba_role_privs;

select * from user_role_privs;

查看角色所拥有的权限:

select * from role_sys_privs;

select * from role_tab_privs;

查看所有系统权限

select * from system_privilege_map;

查看所有对象权限

select * from table_privilege_map;

查看临时表空间

select tablespace_name,file_name,bytes/1024/1024 file_size,autoextensible from dba_temp_files;

创建用户、表空间

/*第1步:创建ODPS数据表空间 */

create tablespace dbuser logging datafile '/home/oracle/app/oracle/oradata/helowin/dbuser.dbf' size 100m autoextend on next 50m maxsize 30960m extent management local;

并不是100g的表空间,是100g的数据文件。一般情况下,单个数据文件的最大为32g。
解决方法:
1、创建多个数据文件,都不能超过32g
2、创建大表空间。create bigfile tablespace 他的上限是32t,不过,oracle10及以后版本才能用。

/*第2步:创建global用户并指定表空间 */

create user dbuser identified by 12345678 default tablespace dbuser temporary tablespace temp profile default;

/*第3步:给global用户授予权限 */

grant connect,resource to dbuser;
grant dba to dbuser;

或者

grant create session to test;
这样test用户就能成功登录进去
 
赋予用户创建表的权限
grant create table to test;
 
赋予相应的权限
grant unlimited tablespace to test;
这个时候用户就拥有了创建表的权限 由于表是用户test的,相应的他就拥有了对创建的表的增删查改的权限了

ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED; --修改密码规则策略为密码永不过期;
alter system set processes=1000 scope=spfile; --修改数据库最大连接数据;

查看数据文件位置
select file_name from sys.dba_data_files;

查看表空间

语法一:

select f.tablespace_name,
       a.total,
       u.used,
       f.free,
       round((u.used / a.total) * 100) "% USED",
       round((f.free / a.total) * 100) "% FREE"
  from (select tablespace_name, sum(bytes / (1024 * 1024)) total
          from dba_data_files
         group by tablespace_name) a,
       (select tablespace_name, round(sum(bytes / (1024 * 1024))) used
          from dba_extents
         group by tablespace_name) u,
       (select tablespace_name, round(sum(bytes / (1024 * 1024))) free
          from dba_free_space
         group by tablespace_name) f
 where a.tablespace_name = f.tablespace_name
   and a.tablespace_name = u.tablespace_name;

下面这种方法更快:
语法二:

select a.tablespace_name,
       a.bytes / 1024 / 1024 "Sum MB",
       (a.bytes - b.bytes) / 1024 / 1024 "used MB",
       b.bytes / 1024 / 1024 "free MB",
       round(((a.bytes - b.bytes) / a.bytes) * 100, 2) "percent_used"
  from (select tablespace_name, sum(bytes) bytes
          from dba_data_files
         group by tablespace_name) a,
       (select tablespace_name, sum(bytes) bytes, max(bytes) largest
          from dba_free_space
         group by tablespace_name) b
 where a.tablespace_name = b.tablespace_name
 order by ((a.bytes - b.bytes) / a.bytes) desc;

备份恢复

创建逻辑目录

#创建逻辑目录
create directory mydata as '/home/oracle/mydata';
grant read, write on directory mydata to testdba;
#查看逻辑目录的对应信息
select * from dba_directories;

1、备份

#全库导出testdba
expdp testdba/12345678@orcl directory=mydata dumpfile=mydump.DMP logfile=mydump.log schemas=testdba

#如需要排除不导出某些表,则需加参数  
#; exclude=table:\"in\(\'SCORE_DETAILS_INFO\',\'T_SYS_LOG\'\)
expdp testdba/12345678@orcl directory=mydata dumpfile=mydump.DMP logfile=mydump.log schemas=testdba exclude=table:\"in\(\'LEADSEC_DATA\'\)\"

2、恢复
提示如果从windows拷贝过来的,要先设置字符集

su - oracle
export NLS_LANG='SIMPLIFIED CHINESE_CHINA.ZHS16GBK' --先临时改变下字符编码集

把备份文件减压放在逻辑目录下

ls /home/oracle/mydata
testdba_2020_04_16_04_00_01_full.dmp

 source /home/oracle/.bash_profile -- 让环境变量生效(即让oracle数据库用户下的环境变量生效)
nohup impdp testdba/12345678 directory=mydata dumpfile=testdba_2020_04_16_04_00_01_full.dmp logfile=testdba_2021_07_06_full.log  &

导入指定裤(从裤testdb导入到testdb2)

impdp testdba2/12345678@localhost/orcl directory=mydata dumpfile=testdba_2020_04_16_04_00_01_full.dmp logfile=testdba_2021_07_06_full.log remap_schema=testdba:testdba2 remap_tablespace=testdba:testdba2 table_exists_action=replace

导入不同数据库
impdp gzsjjd1/12345678@localhost/orcl directory=mydata dumpfile=hyyf1_2021_03_30_full.dmp logfile=hyyf1_2021_03_30_full.log remap_schema=hyyf1:gzsjjd1 remap_tablespace=HYYF1:GZSJJD1 table_exists_action=replace

remap_schema=hyyf1:gzsjjd1 --hyyf1用户导出的数据导入到 gzsjjd1 中
remap_tablespace=HYYF1:GZSJJD1 --HYYF1:导出时的表空间,GZSJJD1:将要导入的表空空间
table_exists_action=replace --处理已经存在的表。(replace:先drop表,然后创建表,最后插入数据)

--查看逻辑目录
select * from dba_directories;

--查找工作空间的路径(即查询表空间位置)
select * from dba_data_files;

--查询用户所对应的表空间
select username,default_tablespace,temporary_tablespace from dba_users;

调整表空间

表空间不足添加表空间数据库文件

alter  tablespace  USERS  add datafile  '/oracle/app/oradata/shpog/user02.dbf' size 16G autoextend on;

alter  tablespace SYSTEM   add datafile  '/oracle/app/oradata/shpog/undotbs01.dbf' size 5G;

表空间不足在原文件增加文件尺寸大小

alter  database  datafile  '/oracle/app/oradata/orcl/system01.dbf' resize 5G;  

alter  database  datafile    '/oracle/app/oradata/orcl/sysaux01.dbf'  resize  5G;

Linux启动oracle

Linux系统下关闭与启动Oracle11g的顺序与命令
关闭:

  • 1、关EM:[oracle@localhost ~] emctl stop dbconsole //本次不用执行,未安装

  • 2、关监听:[oracle@localhost ~] lsnrctl stop

  • 3、关数据库:SQL> shutdown immediate

启动:

  • 1、开监听:[oracle@localhost ~] lsnrctl start

  • 2、启动数据库:SQL> startup

  • 3、开EM:[oracle@localhost ~] emctl start dbconsole //本次不用执行,未安装

一、启动数据库服务

1.先切换至oracle用户,并使环境变量生效

[root@localhost ~]# su oracle
[oracle@localhost ~]$ source /home/oracle/.bash_profile 
# .bash_profile 是oracle的环境变量配置文件

2.用sqlplus登录数据库,并启动

[oracle@localhost ~]$ sqlplus  /nolog  #用sqlplus登录数据库
- -使用DBA用户登录到源数据库中
SQL>conn system/system@orcl as sysdba
或者
     SQL> connect  /as sysdba  #用sysdba连接数据库
     SQL> startup  #启动数据库(一般不需要加参数,只要设置好环境变量)
       SQL> shutdwon  abort; #关闭数据库
     SQL> exit     #退出sqlplus


二、启动监听程序

1.先切换至oracle用户,并使环境变量生效

[root@localhost ~]# su oracle
[oracle@localhost ~]$ source /home/oracle/.bash_profile  #使环境变量生效
[oracle@localhost ~]$ lsnrctl  status  #查看监听状态
[oracle@localhost ~]$ lsnrctl  start   #启动监听
[oracle@localhost ~]$ lsnrctl  stop   #停止监听



三、测试连接
tnsping 127.0.0.1/orcl

ps -ef | grep -v grep| grep ora_ //测试oracle进程

netstat -tnpl | grep 1521 
四、Oracle环境变量配置
[root@localhost ~]# vim /home/oracle/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs
# 添加如下内容
# ORACLE_BASE:
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_2
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=orcl

------百度上的方法-------------------------------------------------
export ORACLE_BASE=/data/app/oracle;  #数据库安装的更目录
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/dbhome_1; 
export ORACLE_SID=orcl;  #ORACLE_SID实列ID
export PATH=$ORACLE_HOME/bin:$PATH;   #:$PATH 加入原来的环境变量值

注意:
PATH后边必须加$PATH这样是把原来的PATH变量的值加进来,防止拿了芝麻,丢了西瓜

Linux 下设置oracle环境变量

https://blog.csdn.net/yk10010/article/details/88976346?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.nonecase

注意:
LD_LIBRARY_PATH是Linux环境变量名,该环境变量主要用于指定查找共享库(动态链接库)时除了默认路径之外的其他路径。

1.修改用户目录下环境变量
在用户目录下的.bash_profile文件中增加变量,改变量仅会对当前用户有效,并且是“永久的”

[oracle@eis_db ~]$ pwd
/home/oracle
[oracle@eis_db ~]$ vim .bash_profile

在文件末尾添加
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=orcl
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib

如下:

# .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

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=orcl
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib


2.修改所有用户有效环境变量
在/etc/profile文件中添加变量,该变量将会对Linux下所有用户有效,并且是“永久的”

在 /etc/profile文件末尾添加一下内容

[oracle@eis_db ~]$ less /etc/profile

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=orcl
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib

使配置立刻生效

[oracle@eis_db ~]$ source /etc/profile

导入导出数据

导出整个库

expdp testdb/12345678@orcl directory=mydata dumpfile=mydump.DMP logfile=mydump.log schemas=testdb

导出排除不导出某些表

expdp testdb/12345678@orcl directory=mydata dumpfile=mydump.DMP logfile=mydump.log schemas=hyyf1 exclude=table:\"in\(\'table1\'\)\"
如需要排除不导出某些表,则需加参数  ; exclude=table:\"in\(\'table1\',\'table2\'\)

导出某个指定的表

expdp testdb/12345678@orcl directory=mydata dumpfile=table1.DMP logfile=table1.log  tables=table1

导出某个指定的多个表

expdp testdb/12345678@orcl directory=mydata dumpfile=table1.DMP logfile=table1.log  tables=(table1,table2,table3)

导出某个或者某几个用户

expdp system/a directory=mydata dumpfile=aexp%U.dmp schemas=(hr,scott)

导入整个库

nohup impdp testdb/12345678@orcl directory=mydata dumpfile=mydump.DMP logfile=mydump.log &

导入单个库

impdp xkj/xkj directory=my_dir dumpfile=full_exp.dmp tables=(table1)

/不同库
impdp xkj/xkj directory=my_dir dumpfile=full_exp.dmp tables=(hr.employees) remap_schema=hr:xkj

删除 rac过期日志

1.在归档日志服务器上,使用 rman target / 进入归档目录。

[oracle@rac1 mydata]$ rman target /

2。使用report obsolete;命令查看过期归档日志。

RMAN> report obsolete;

3。使用delete obsolete;命令删除过期归档日志。

RMAN> delete obsolete;

4。如果要删除特定时间段的归档日志,则可以使用下述命令:

rman>delete archivelog all completed before 'SYSDATE-7';

意思是删除系统时间7天前的归档日志;
这样做只能删除归档日志的一半,要删除另一半,得进入asmcmd.
5.asmcmd>rm -rf 2007*
意思是删除2007年的全部归档日志。

其他

响应文件


oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0

oracle.install.option=INSTALL_DB_AND_CONFIG

ORACLE_HOSTNAME=localhost

UNIX_GROUP_NAME=oinstall

INVENTORY_LOCATION=/home/oracle/tools/oraInventory


SELECTED_LANGUAGES=en,zh_CN

ORACLE_HOME=/home/oracle/tools/oracle11g/product/11.2.0/dbhome_1

ORACLE_BASE=/home/oracle/tools/oracle11g

oracle.install.db.InstallEdition=EE

oracle.install.db.isCustomInstall=false

oracle.install.db.customComponents=oracle.server:11.2.0.1.0,oracle.sysman.ccr:10.2.7.0.0,oracle.xdk:11.2.0.1.0,oracle.rdbms.oci:11.2.0.1.0,oracle.network:11.2.0.1.0,oracle.network.listener:11.2.0.1.0,oracle.rdbms:11.2.0.1.0,oracle.options:11.2.0.1.0,oracle.rdbms.partitioning:11.2.0.1.0,oracle.oraolap:11.2.0.1.0,oracle.rdbms.dm:11.2.0.1.0,oracle.rdbms.dv:11.2.0.1.0,orcle.rdbms.lbac:11.2.0.1.0,oracle.rdbms.rat:11.2.0.1.0

oracle.install.db.DBA_GROUP=dba

oracle.install.db.OPER_GROUP=oinstall

oracle.install.db.CLUSTER_NODES=

oracle.install.db.config.starterdb.type=GENERAL_PURPOSE

oracle.install.db.config.starterdb.globalDBName=pri

oracle.install.db.config.starterdb.SID=pri

oracle.install.db.config.starterdb.characterSet=ZHS16GBK

oracle.install.db.config.starterdb.memoryOption=true

oracle.install.db.config.starterdb.memoryLimit=1024

oracle.install.db.config.starterdb.installExampleSchemas=false

oracle.install.db.config.starterdb.enableSecuritySettings=true


oracle.install.db.config.starterdb.password.ALL=12345678

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

oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=

oracle.install.db.config.starterdb.dbcontrol.enableEmailNotification=false

oracle.install.db.config.starterdb.dbcontrol.emailAddress=

oracle.install.db.config.starterdb.dbcontrol.SMTPServer=


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=FILE_SYSTEM_STORAGE

oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/home/oracle/tools/oracle11g/oradata

oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/home/oracle/tools/oracle11g/fast_recovery_area

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=

FAQ

Oracle Net Services 配置失败。退出代码是1

Oracle 安装时在配置监听时报错
报错信息如下:
[oracle@bogon database]$ netca /silent /responsefile /home/oracle/app/database/response/netca.rsp

正在对命令行参数进行语法分析:
参数"silent" = true
参数"responsefile" = /home/oracle/app/database/response/netca.rsp
Oracle Net Configuration Assistant 在给定位置找不到响应文件。
Oracle Net Services 配置失败。退出代码是1

很显然:
参数"responsefile" = /home/oracle/app/database/response/netca.rsp
这里是路径不存在的,因此需要写正确的路径,
我的正确的为:
netca /silent /responsefile /data/database/response/netca.rsp
image

解决 oracle IO占用率很高的问题

突然user io占用率很很高,看了一个AWR报告,发现direct path read temp,direct path write temp的的数率很高,后来怀疑是临时表空间不够了,就试着设了一下让临时表自动增长,问题就解决了。可爽!

具体如下,用红色字休就方法就行了:

1、查看临时表空间

select tablespace_name,file_name,bytes/1024/1024 file_size,autoextensible from dba_temp_files;

2、缩小临时表空间大小

alter database tempfile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\TELEMT\TEMP01.DBF' resize 100M;

3、扩展临时表空间:
方法一、增大临时文件大小:

SQL> alter database tempfile ‘/u01/app/oracle/oradata/orcl/temp01.dbf’ resize 100m;

方法二、将临时数据文件设为自动扩展:

SQL> alter database tempfile ‘/u01/app/oracle/oradata/orcl/temp01.dbf’ autoextend on next 5m maxsize unlimited;

方法三、向临时表空间中添加数据文件:

SQL> alter tablespace temp add tempfile ‘/u01/app/oracle/oradata/orcl/temp02.dbf’ size 100m;

4、创建临时表空间:

SQL> create temporary tablespace temp1 tempfile ‘/u01/app/oracle/oradata/orcl/temp11.dbf’ size 10M;

5、更改系统的默认临时表空间:
--查询默认临时表空间

select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE';

--修改默认临时表空间

alter database default temporary tablespace temp1;

所有用户的默认临时表空间都将切换为新的临时表空间:

select username,temporary_tablespace,default_ from dba_users;

--更改某一用户的临时表空间:

alter user scott temporary tablespace temp;

6、删除临时表空间
删除临时表空间的一个数据文件:

SQL> alter database tempfile ‘/u01/app/oracle/oradata/orcl/temp02.dbf’ drop;

删除临时表空间(彻底删除):

SQL> drop tablespace temp1 including contents and datafiles cascade constraints;

ORA-00257:archiver error解决办法

出现ORA-00257错误(空间不足错误),通过查找资料,绝大部分说这是由于归档日志太多,占用了全部的硬盘剩余空间导致的,通过简单删除日志或加大存储空间就能够解决。

(一)、oralce 11g更改归档模式、目录、日志大小(本人采用的这种做法)

一、更改Oracle为归档模式
1.关闭oracle

SQL> shutdown immediate;
   Database closed.
   Database dismounted.
   ORACLE instance shut down.

2.启动为mount状态

SQL> startup mount

ORACLE instance started.

Total System Global Area 2572144640 bytes
Fixed Size                  2283984 bytes
Variable Size             738199088 bytes
Database Buffers         1828716544 bytes
Redo Buffers                2945024 bytes
Database mounted.

3.更改为归档模式

SQL>   alter database archivelog
  Database altered.

备注:‘archivelog’为 归档模式;‘noarchivelog’为非归档模式。

4.更改数据库为‘打开’状态

SQL>  alter database open

5.查看归档模式信息

SQL>   archvie log list
它会提示归档的模式、是否启用、参数
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     88
Next log sequence to archive   90
Current log sequence           90

二、更改归档目录
1.查看参数db_recovery_file_dest

(1)“db_recovery_file_dest”是用于定义存储归档日志的目录。通过show parameter命令,显示参数的值为(默认为)fast_recovery_area。示例如下:


SQL> show parameter db_recovery

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /usr/local/oracle/flash_recovery_area
db_recovery_file_dest_size           big integer 4182M
 

(2)查看v$recovery_file_dest视图,可得知fast_recovery_area的空间限制、已使用的空间、文件数等。


SQL> select * from v$recovery_file_dest;

NAME     SPACE_LIMIT      SPACE_USED     SPACE_RECLAIMABLE     NUMBER_OF_FILES
----------- ---------- ----------------- ---------------
D:\oracle\fast_recovery_area  4385144832    4346230272           2741248             102

2.更改归档日志目录
语法:alter system set 参数=值 scope=spfile;(设置成比较大的空间的目录,我这里是设置成了home下面)

   示例:SQL> alter system set db_recovery_file_dest='/home/oracle/flash_recovery_area' scope=spfile;

                System altered.

三、更改归档日志大小

1.查看参数'db_recovery_file_dest_size'值

SQL> show parameter db_recov

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /usr/local/oracle/flash_recovery_area
db_recovery_file_dest_size           big integer 4182M

2.更改参数'db_recovery_file_dest_size'值大小

SQL> alter system set db_recovery_file_dest_size=41820M scope=spfile;

System altered.

3.关闭数据库,重启数据库

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup open;
ORACLE instance started.

Total System Global Area 2572144640 bytes
Fixed Size                  2283984 bytes
Variable Size             738199088 bytes
Database Buffers         1828716544 bytes
Redo Buffers                2945024 bytes
Database mounted.
Database opened.

4.再次查看参数'db_recovery_file_dest_size'值

SQL> show parameter db_reco
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /home/oracle/flash_recovery_area
db_recovery_file_dest_size           big integer 41820M

此时重启之后,就可以了。

=========================================================================

(以下仅供参考)

(二)、百度经验的解决方案:如下(本人采用的这种做法)

解决:

1、SecureCRT登录服务器,切换用户oracle,连接oracle

[root@userbeta~]# su - oracle

[oracle@userbeta~]$ sqlplus /nolog

SQL> connect /as sysdba

2、检查flash recovery area的使用情况,可以看见archivelog已经很大了,达到99.94

SQL> select * from V$FLASH_RECOVERY_AREA_USAGE;

3、计算flash recovery area已经占用的空间

SQL> select sum(percent_space_used)*3/100 from v$flash_recovery_area_usage;

4、修改FLASH_RECOVERY_AREA的空间修改为6GB,修改前确认磁盘有足够空间

SQL> ALTER SYSTEM SET DB_RECOVERY_FILE_DEST_SIZE=8g;

参考文档:https://www.cnblogs.com/gmq-sh/p/5980127.html

ORA-12899: value too large for column (actual: 27,

oracle11g导入数据时报以下错误,这是因为原来数据库的编码是GBK的,每个汉字两个字节,但新数据库是UTF-8的,每个汉字是三个字节的,导致超过长度了。

  解决方法:s

  打开cmd命令窗口,输入“sqlplus /nolog”,进入“SQL>”的输入符下,按照下面给出的命令一次执行就可以了。

SQL>connect username/password as SYSDBA;
SQL>SHUTDOWN IMMEDIATE;
SQL>STARTUP MOUNT;
SQL>ALTER SYSTEM ENABLE RESTRICTED SESSION;
SQL>ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
SQL>ALTER SYSTEM SET AQ_TM_PROCESSES=0;
SQL>ALTER DATABASE OPEN;
SQL> ALTER DATABASE CHARACTER SET ZHS16GBK ;
ALTER DATABASE CHARACTER SET ZHS16GBK;
*ERROR at line 1:
ORA-12712: new character set must be a superset of old character set

此时报错,不必慌张。提示新字符集必须是超集,此时INTRENAL_USE指令不对字符集超集进行检查。输入以下命令即可:

SQL>ALTER DATABASE CHARACTER SET INTERNAL_USE ZHS16GBK;
SQL>SHUTDOWN IMMEDIATE;
SQL>STARTUP;

此时完成字符集转换。

oracle导入数据出现临时表空间不足

数据泵导入数据库时,DMP文件是3G,在oracle自以为建了10G的表空间应该足够,结果导入过程中提示下图。明显是表空间不够了,此时不用停止数据导入过程,只需要在plsql里执行增加表空间的语句进行扩容:

alter tablespace ASSETS add datafile ‘D:\app\Administrator\oradata\orcl\ASSETS_1.dbf’ size 10000m autoextend on next 200M;

继续扩容10G后,数据库可以导入。
image

ORA-01109: database not open

SQL> alter database open;

Database altered.

在grid安装过程执行root.sh报错crsconfig_lib.pm line 9379

环境CentOS 7.5 Oracle 11.2.0.4 RAC

故障:
在grid安装过程执行root.sh脚本时报错

firstnode configuration failed at /u01/app/11.2.0/grid/crs/install/crsconfig_lib.pm line 9379
firstnode configuration failed at /u01/app/11.2.0/grid/crs/install/crsconfig_lib.pm line 7599

image

处理方法:

查看每个节点的hostname是否与/etc/hosts中public host主机名一致

RHEL7安装oracle rac执行root.sh报错ohasd faile

报错信息:

[root@rac1 ~]# /u01/app/oraInventory/orainstRoot.sh 
Changing permissions of /u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.


Changing groupname of /u01/app/oraInventory to oinstall.
The execution of the script is complete.
[root@zjdb1 ~]# /u01/app/11.2.0/grid/root.sh 
Performing root user operation for Oracle 11g 


The following environment variables are set as:
    ORACLE_OWNER= grid
    ORACLE_HOME=  /u01/app/11.2.0/grid


Enter the full pathname of the local bin directory: [/usr/local/bin]: 
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...

Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Using configuration parameter file: /u01/app/11.2.0/grid/crs/install/crsconfig_params
Creating trace directory
User ignored Prerequisites during installation
Installing Trace File Analyzer
OLR initialization - successful
  root wallet
  root wallet cert
  root cert export
  peer wallet
  profile reader wallet
  pa wallet
  peer wallet keys
  pa wallet keys
  peer cert request
  pa cert request
  peer cert
  pa cert
  peer root cert TP
  profile reader root cert TP
  pa root cert TP
  peer pa cert TP
  pa peer cert TP
  profile reader pa cert TP
  profile reader peer cert TP
  peer user cert
  pa user cert
Adding Clusterware entries to inittab
ohasd failed to start
Failed to start the Clusterware. Last 20 lines of the alert log follow: 
2015-05-23 23:37:45.460: 
[client(13782)]CRS-2101:The OLR was formatted using version 3.

报错原因:

因为RHEL 7使用systemd而不是initd运行进程和重启进程,而root.sh通过传统的initd运行ohasd进程。

解决方法:

在RHEL 7中ohasd需要被设置为一个服务,在运行脚本root.sh之前。

步骤如下:

  1. 以root用户创建服务文件
#vim /usr/lib/systemd/system/ohas.service

#chmod 777 /usr/lib/systemd/system/ohas.service
  1. 将以下内容添加到新创建的ohas.service文件中
[root@rac1 init.d]# cat /usr/lib/systemd/system/ohas.service
[Unit]
Description=Oracle High Availability Services
After=syslog.target

[Service]
ExecStart=/etc/init.d/init.ohasd run >/dev/null 2>&1 Type=simple
Restart=always

[Install]
WantedBy=multi-user.target
  1. 以root用户运行下面的命令
systemctl daemon-reload
systemctl enable ohas.service
systemctl start ohas.service
  1. 查看运行状态
[root@rac1 init.d]# systemctl status ohas.service
ohas.service - Oracle High Availability Services
   Loaded: loaded (/usr/lib/systemd/system/ohas.service; enabled)
   Active: failed (Result: start-limit) since Fri 2015-09-11 16:07:32 CST; 1s ago
  Process: 5734 ExecStart=/etc/init.d/init.ohasd run >/dev/null 2>&1 Type=simple (code=exited, status=203/EXEC)
 Main PID: 5734 (code=exited, status=203/EXEC)


Sep 11 16:07:32 rac1 systemd[1]: Starting Oracle High Availability Services...
Sep 11 16:07:32 rac1 systemd[1]: Started Oracle High Availability Services.
Sep 11 16:07:32 rac1 systemd[1]: ohas.service: main process exited, code=exited, status=203/EXEC
Sep 11 16:07:32 rac1 systemd[1]: Unit ohas.service entered failed state.
Sep 11 16:07:32 rac1 systemd[1]: ohas.service holdoff time over, scheduling restart.
Sep 11 16:07:32 rac1 systemd[1]: Stopping Oracle High Availability Services...
Sep 11 16:07:32 rac1 systemd[1]: Starting Oracle High Availability Services...
Sep 11 16:07:32 rac1 systemd[1]: ohas.service start request repeated too quickly, refusing to start.
Sep 11 16:07:32 rac1 systemd[1]: Failed to start Oracle High Availability Services.
Sep 11 16:07:32 rac1 systemd[1]: Unit ohas.service entered failed state.

此时状态为失败,原因是现在还没有/etc/init.d/init.ohasd文件。

下面可以运行脚本root.sh 不会再报ohasd failed to start错误了。

如果还是报ohasd failed to start错误,可能是root.sh脚本创建了init.ohasd之后,ohas.service没有马上启动,解决方法参考以下:

当运行root.sh时,一直刷新/etc/init.d ,直到出现 init.ohasd 文件,马上手动启动ohas.service服务 命令:systemctl start ohas.service

[root@rac1 init.d]# systemctl status ohas.service
ohas.service - Oracle High Availability Services
   Loaded: loaded (/usr/lib/systemd/system/ohas.service; enabled)
   Active: active (running) since Fri 2015-09-11 16:09:05 CST; 3s ago
 Main PID: 6000 (init.ohasd)
   CGroup: /system.slice/ohas.service
           6000 /bin/sh /etc/init.d/init.ohasd run >/dev/null 2>&1 Type=simple
           6026 /bin/sleep 10


Sep 11 16:09:05 rac1 systemd[1]: Starting Oracle High Availability Services...
Sep 11 16:09:05 rac1 systemd[1]: Started Oracle High Availability Services.
Sep 11 16:09:05 rac1 su[6020]: (to grid) root on none

linux下oracle监听日志的正确删除步骤

linux下oracle日志目录
通常都在:/u01/oracle/diag/tnslsnr/oracle/listener目录
find / -name listener.log

删除步骤
进入$ORACLE_HOME/network/log,查看日志大小 du -a

把 listen log 关闭.
lsnrctl set log_status off;

把日志改名,mv listener.log listener.log_bak

启动listen log
lsnrctl set log_status on;此时检查log目录下,会自动生成一个新的log文件,rm掉之前的监听文件即可

Exception in thread “main” java.lang.NoClassD

原来是系统中设置了DISPLAY环境变量,执行:

[oracle@qa26 database]$ ./runInstaller  -silent -responseFile /usr/local/oracle/response/db_install.rsp  -ignorePrereq

正在启动 Oracle Universal Installer...

检查临时空间: 必须大于 120 MB。   实际为 34078 MB    通过
检查交换空间: 必须大于 150 MB。   实际为 3951 MB    通过
准备从以下地址启动 Oracle Universal Installer /tmp/OraInstall2017-04-20_03-14-19PM. 请稍候...

[oracle@qa26 database]$ Exception in thread "main" java.lang.NoClassDefFoundError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at java.awt.Toolkit$2.run(Toolkit.java:821)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:804)
at javax.swing.UIManager.initialize(UIManager.java:1262)
at javax.swing.UIManager.maybeInitialize(UIManager.java:1245)
at javax.swing.UIManager.getUI(UIManager.java:851)
at javax.swing.JPanel.updateUI(JPanel.java:104)
at javax.swing.JPanel.<init>(JPanel.java:64)
at javax.swing.JPanel.<init>(JPanel.java:87)
at javax.swing.JPanel.<init>(JPanel.java:95)
at oracle.sysman.oii.oiif.oiifo.OiifoOCMUI.<init>(OiifoOCMUI.java:125)
at oracle.sysman.oii.oiif.oiifo.OiifoOCMInterfaceManager.<init>(OiifoOCMInterfaceManager.java:79)
at oracle.sysman.oii.oiif.oiifo.OiifoOCMInterfaceManager.getInstance(OiifoOCMInterfaceManager.java:124)
at oracle.install.ivw.db.driver.DBInstaller.run(DBInstaller.java:123)
at oracle.install.commons.util.Application.startup(Application.java:869)
at oracle.install.commons.flow.FlowApplication.startup(FlowApplication.java:164)
at oracle.install.commons.flow.FlowApplication.startup(FlowApplication.java:181)
at oracle.install.commons.base.driver.common.Installer.startup(Installer.java:265)
at oracle.install.ivw.db.driver.DBInstaller.startup(DBInstaller.java:114)
at oracle.install.ivw.db.driver.DBInstaller.main(DBInstaller.java:132)

原来是系统中设置了DISPLAY环境变量

执行:

unset DISPLAY

然后再执行runInstaller.sh,执行成功

原文链接:https://blog.csdn.net/u011391839/article/details/70260109

linux下清空oracle的listener.log的几种方法

方法一:不需要停掉监听

# ls -l
total 3744573
-rw-r--r--   1 oracle   dba      123287468 Apr 26 16:37 listener.log
-rw-r--r--   1 oracle   dba        6463 Apr 23 09:02 sqlnet.log
# echo '' >listener.log
# ls -l
total 96
-rw-r--r--   1 oracle   dba            1 Apr 26 16:37 listener.log
-rw-r--r--   1 oracle   dba        6463 Apr 23 09:02 sqlnet.log
# ls -l
total 96
-rw-r--r--   1 oracle   dba          725 Apr 26 16:38 listener.log
-rw-r--r--   1 oracle   dba        6463 Apr 23 09:02 sqlnet.log
#

方法二:需要停掉监听,再重启

lsnrctl stop; 
rm listener.log 再touch listener.log; 
lsnrctl start

详细步骤:
1.rm -rf listener.log->ls->lsnrctl
2.lsnrctl>set log_status off --关闭写日志的功能
  lsnrctl>save_config
  lsnrctl>set log_status on  --打开监听写日志的功能
  lsnrctl>save_config

监听日志太大,正确的删除步骤
1.查看日志大小 du -a (或du -h )
2.关闭监听日志 set log_status off
3.把日志改名   mv listener.log listener.log_bak
4.启动监听日志 set log_status on (检查是否自动生成listener.log)

重新定位一个日志文件,解决监听器日志问题
两个比较有用的命令:

lsnrctl>set current_listener <listner name>
lsnrctl>set log_file <sid name>.log

以下是解决步骤:

1.$lsnrctl
2.lsnrctl>set current_listner LISTNER1
3.lsnrctl>set log_file
4.lsnrctl>status

5.lsnrctl>save_config

附加:在windows下清空oracle的listener.log
1.在dos下切换到log的目录下
  如:D:\oracle\product\10.2.0\db_1\NETWORK\log>copy /y sqlnet.log listener.log(将sqlnet.log覆盖到listener.log里面)

原文链接:https://blog.csdn.net/u011844399/article/details/12453489

oracle安装数据库中文乱码解决办法

解决办法1:
Linux下安装Oracle11g中文乱码

Linux下安装Oracle11g,安装界面乱码问题解决方法:

解决安装时中文是"囗囗囗囗囗囗囗囗"

1.进入刚解压的

database/stage/Components/oracle.jdk/1.5.0.17.0/1/DataFiles/all.jar

2.在桌面新建一个文件夹命名为fallback,下载中文字体(zysong.ttf)放入里面去。

3.用归档管理器打开all.jar它进入/jdk/jre/lib/fonts/把在桌面建好的fallback文件夹拖放进来,完成后的目录结构应该是/jdk/jre/lib/fonts/fallback/zysong.ttf。

解决办法2:

设置 export LANG=en-US

解决办法3:

切换界面

现在LINUX环境是英文的

[root@localhost root]# locale

LANG=en_US.UTF-8

LC_CTYPE="en_US.UTF-8"

LC_NUMERIC="en_US.UTF-8"

LC_TIME="en_US.UTF-8"

LC_COLLATE="en_US.UTF-8"

LC_MONETARY="en_US.UTF-8"

LC_MESSAGES="en_US.UTF-8"

LC_PAPER="en_US.UTF-8"

LC_NAME="en_US.UTF-8"

LC_ADDRESS="en_US.UTF-8"

LC_TELEPHONE="en_US.UTF-8"

LC_MEASUREMENT="en_US.UTF-8"

LC_IDENTIFICATION="en_US.UTF-8"

LC_ALL=

需要修改为:

LANG="zh_CN.GB2312"

LC_CTYPE="zh_CN.GB2312"

LC_NUMERIC="zh_CN.GB2312"

LC_TIME="zh_CN.GB2312"

LC_COLLATE="zh_CN.GB2312"

LC_MONETARY="zh_CN.GB2312"

LC_MESSAGES="zh_CN.GB2312"

LC_PAPER="zh_CN.GB2312"

LC_NAME="zh_CN.GB2312"

LC_ADDRESS="zh_CN.GB2312"

LC_TELEPHONE="zh_CN.GB2312"

LC_MEASUREMENT="zh_CN.GB2312"

LC_IDENTIFICATION="zh_CN.GB2312"

LC_ALL=

oracle11.2.0.4执行root.sh ohasd failed to start

报错信息:

[root@rac1 ~]# /u01/app/oraInventory/orainstRoot.sh 
Changing permissions of /u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.


Changing groupname of /u01/app/oraInventory to oinstall.
The execution of the script is complete.
[root@zjdb1 ~]# /u01/app/11.2.0/grid/root.sh 
Performing root user operation for Oracle 11g 


The following environment variables are set as:
    ORACLE_OWNER= grid
    ORACLE_HOME=  /u01/app/11.2.0/grid


Enter the full pathname of the local bin directory: [/usr/local/bin]: 
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...

Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Using configuration parameter file: /u01/app/11.2.0/grid/crs/install/crsconfig_params
Creating trace directory
User ignored Prerequisites during installation
Installing Trace File Analyzer
OLR initialization - successful
  root wallet
  root wallet cert
  root cert export
  peer wallet
  profile reader wallet
  pa wallet
  peer wallet keys
  pa wallet keys
  peer cert request
  pa cert request
  peer cert
  pa cert
  peer root cert TP
  profile reader root cert TP
  pa root cert TP
  peer pa cert TP
  pa peer cert TP
  profile reader pa cert TP
  profile reader peer cert TP
  peer user cert
  pa user cert
Adding Clusterware entries to inittab
ohasd failed to start
Failed to start the Clusterware. Last 20 lines of the alert log follow: 
2015-05-23 23:37:45.460: 
[client(13782)]CRS-2101:The OLR was formatted using version 3.

报错原因:

因为RHEL 7使用systemd而不是initd运行进程和重启进程,而root.sh通过传统的initd运行ohasd进程。

解决方法:

在RHEL 7中ohasd需要被设置为一个服务,在运行脚本root.sh之前。

步骤如下:

  1. 以root用户创建服务文件
#touch /usr/lib/systemd/system/ohas.service

#chmod 777 /usr/lib/systemd/system/ohas.service
  1. 将以下内容添加到新创建的ohas.service文件中
[root@rac1 init.d]# cat /usr/lib/systemd/system/ohas.service
[Unit]
Description=Oracle High Availability Services
After=syslog.target

[Service]
ExecStart=/etc/init.d/init.ohasd run >/dev/null 2>&1 Type=simple
Restart=always

[Install]
WantedBy=multi-user.target
  1. 以root用户运行下面的命令
systemctl daemon-reload
systemctl enable ohas.service
systemctl start ohas.service
  1. 查看运行状态
[root@rac1 init.d]# systemctl status ohas.service
ohas.service - Oracle High Availability Services
   Loaded: loaded (/usr/lib/systemd/system/ohas.service; enabled)
   Active: failed (Result: start-limit) since Fri 2015-09-11 16:07:32 CST; 1s ago
  Process: 5734 ExecStart=/etc/init.d/init.ohasd run >/dev/null 2>&1 Type=simple (code=exited, status=203/EXEC)
 Main PID: 5734 (code=exited, status=203/EXEC)


Sep 11 16:07:32 rac1 systemd[1]: Starting Oracle High Availability Services...
Sep 11 16:07:32 rac1 systemd[1]: Started Oracle High Availability Services.
Sep 11 16:07:32 rac1 systemd[1]: ohas.service: main process exited, code=exited, status=203/EXEC
Sep 11 16:07:32 rac1 systemd[1]: Unit ohas.service entered failed state.
Sep 11 16:07:32 rac1 systemd[1]: ohas.service holdoff time over, scheduling restart.
Sep 11 16:07:32 rac1 systemd[1]: Stopping Oracle High Availability Services...
Sep 11 16:07:32 rac1 systemd[1]: Starting Oracle High Availability Services...
Sep 11 16:07:32 rac1 systemd[1]: ohas.service start request repeated too quickly, refusing to start.
Sep 11 16:07:32 rac1 systemd[1]: Failed to start Oracle High Availability Services.
Sep 11 16:07:32 rac1 systemd[1]: Unit ohas.service entered failed state.

此时状态为失败,原因是现在还没有/etc/init.d/init.ohasd文件。

下面可以运行脚本root.sh 不会再报ohasd failed to start错误了。

如果还是报ohasd failed to start错误,可能是root.sh脚本创建了init.ohasd之后,ohas.service没有马上启动,解决方法参考以下:

当运行root.sh时,一直刷新/etc/init.d ,直到出现 init.ohasd 文件,马上手动启动ohas.service服务
命令:systemctl start ohas.service

[root@rac1 init.d]# systemctl status ohas.service
ohas.service - Oracle High Availability Services
   Loaded: loaded (/usr/lib/systemd/system/ohas.service; enabled)
   Active: active (running) since Fri 2015-09-11 16:09:05 CST; 3s ago
 Main PID: 6000 (init.ohasd)
   CGroup: /system.slice/ohas.service
           6000 /bin/sh /etc/init.d/init.ohasd run >/dev/null 2>&1 Type=simple
           6026 /bin/sleep 10


Sep 11 16:09:05 rac1 systemd[1]: Starting Oracle High Availability Services...
Sep 11 16:09:05 rac1 systemd[1]: Started Oracle High Availability Services.
Sep 11 16:09:05 rac1 su[6020]: (to grid) root on none

oracle rac识别不出节点

现象:
image

解决办法:
我在目录//u01/app/oraInventory/ContentsXML/inventory.xml找到打开如下:添加CRS="true"

[root@rac1 ~]# vi /u01/app/oraInventory/ContentsXML/inventory.xml
<?xml version="1.0" standalone="yes" ?>
<!-- Copyright (c) 1999, 2013, Oracle and/or its affiliates.
All rights reserved. -->
<!-- Do not modify the contents of this file by hand. -->
<INVENTORY>
<VERSION_INFO>
   <SAVED_WITH>11.2.0.4.0</SAVED_WITH>
   <MINIMUM_VER>2.1.0.6.0</MINIMUM_VER>
</VERSION_INFO>
<HOME_LIST>
<HOME NAME="Ora11g_gridinfrahome1" LOC="/u01/app/11.2.0/grid_1" TYPE="O" IDX="1" CRS="true">
   <NODE_LIST>
      <NODE NAME="rac1"></NODE>
      <NODE NAME="rac2"></NODE>
   </NODE_LIST>
</HOME>
</HOME_LIST>
<COMPOSITEHOME_LIST>
</COMPOSITEHOME_LIST>
</INVENTORY>

CRS="true"部分为要添加的内容

再次运行下过如下
image

posted @ 2023-05-08 14:42  jluo123  阅读(52)  评论(0编辑  收藏  举报