环境说明
[root@testos ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 4G 0 part [SWAP]
└─sda3 8:3 0 95.8G 0 part /
sdb 8:16 0 200G 0 disk
[root@testos ~]#
[oracle@testos:/home/oracle]$df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 95G 18G 73G 20% /
tmpfs 2.0G 485M 1.5G 25% /dev/shm
/dev/sda1 190M 32M 149M 18% /boot
[oracle@testos:/home/oracle]$env|grep ORACLE
ORACLE_SID=testdb
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/12.2.0/db_1
[oracle@testos:/home/oracle]$sqlplus -s / as sysdba
select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/testdb/users01.dbf
/u01/app/oracle/oradata/testdb/undotbs01.dbf
/u01/app/oracle/oradata/testdb/system01.dbf
/u01/app/oracle/oradata/testdb/sysaux01.dbf
如上当前Oracle环境有几个问题
- 没有单独为oracle创建分区
- oracle数据文件也存放路径不规范
现在需要单独为oracle创建分区,把对应的文件移动过去
创建文件系统
pvcreate /dev/sdb
vgcreate oravg /dev/sdb
lvcreate -n oralv -L 200000M oravg
mkfs.ext4 /dev/oravg/oralv
echo "/dev/oravg/oralv /oracle ext4 defaults 0 0" >> /etc/fstab
mkdir /oracle
mount /oracle
[root@testos ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 95G 18G 73G 20% /
tmpfs 2.0G 485M 1.5G 25% /dev/shm
/dev/sda1 190M 32M 149M 18% /boot
/dev/mapper/oravg-oralv
193G 60M 183G 1% /oracle
创建目录和修改权限
mkdir -p /oracle/app/oracle/product/12.2.0/db_1
mkdir -p /oracle/app/oraInventory
mkdir -p /oracle/{oradata,backup,archive}
chown -R oracle:oinstall /oracle
chmod -R 775 /oracle
移动Oracle Home
关闭监听程序和数据库
[oracle@testos:/home/oracle]$lsnrctl status
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 19-SEP-2023 23:33:04
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=testos)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date 19-SEP-2023 23:06:24
Uptime 0 days 0 hr. 26 min. 39 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/testos/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=testos)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "testdb" has 1 instance(s).
Instance "testdb", status READY, has 1 handler(s) for this service...
Service "testdbXDB" has 1 instance(s).
Instance "testdb", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@testos:/home/oracle]$
[oracle@testos:/home/oracle]$lsnrctl stop
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 19-SEP-2023 23:33:41
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=testos)(PORT=1521)))
The command completed successfully
[oracle@testos:/home/oracle]$sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Tue Sep 19 23:33:43 2023
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
sys@testdb(50)> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@testdb(50)>
移动Oracle Home
#查看当前环境变量里记录的信息
[oracle@testos:/home/oracle]$env|grep ORACLE
ORACLE_SID=testdb
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/12.2.0/db_1
[oracle@testos:/home/oracle]$cd $ORACLE_HOME
[oracle@testos:/u01/app/oracle/product/12.2.0/db_1]$ll
total 316
drwxr-xr-x. 2 oracle oinstall 4096 Jul 31 2020 addnode
drwxr-xr-x. 6 oracle oinstall 4096 Jul 31 2020 apex
drwxr-xr-x. 10 oracle oinstall 4096 Jul 31 2020 assistants
drwxr-xr-x. 2 oracle oinstall 12288 Jul 31 2020 bin
drwxr-xr-x. 7 oracle oinstall 4096 Jul 31 2020 ccr
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 cdata
drwxr-xr-x. 5 oracle oinstall 4096 Jul 31 2020 cfgtoollogs
drwxr-xr-x. 4 oracle oinstall 4096 Jul 31 2020 clone
drwxr-xr-x. 6 oracle oinstall 4096 Jul 31 2020 crs
drwxr-xr-x. 6 oracle oinstall 4096 Jul 31 2020 css
drwxr-xr-x. 11 oracle oinstall 4096 Jul 31 2020 ctx
drwxr-xr-x. 7 oracle oinstall 4096 Jul 31 2020 cv
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 data
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 dbjava
drwxr-xr-x. 2 oracle oinstall 4096 Sep 19 23:34 dbs
drwxr-xr-x. 2 oracle oinstall 4096 Jul 31 2020 dc_ocm
drwxr-xr-x. 5 oracle oinstall 4096 Jul 31 2020 deinstall
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 demo
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 diagnostics
drwxr-xr-x. 8 oracle oinstall 4096 Jul 31 2020 dmu
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 dv
-rw-r--r--. 1 oracle oinstall 852 Aug 19 2015 env.ora
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 has
drwxr-xr-x. 5 oracle oinstall 4096 Jul 31 2020 hs
drwxr-xr-x. 9 oracle oinstall 4096 Jul 31 2020 install
drwxr-xr-x. 2 oracle oinstall 4096 Jul 31 2020 instantclient
drwxr-x---. 13 oracle oinstall 4096 Jul 31 2020 inventory
drwxr-xr-x. 8 oracle oinstall 4096 Jul 31 2020 javavm
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 jdbc
drwxr-xr-x. 7 oracle oinstall 4096 Jul 31 2020 jdk
drwxr-xr-x. 2 oracle oinstall 4096 Jul 31 2020 jlib
drwxr-xr-x. 12 oracle oinstall 4096 Jul 31 2020 ldap
drwxr-xr-x. 3 oracle oinstall 12288 Jul 31 2020 lib
drwxr-xr-x. 4 oracle oinstall 4096 Jul 31 2020 log
drwxr-xr-x. 7 oracle oinstall 4096 Jul 31 2020 md
drwxr-xr-x. 6 oracle oinstall 4096 Jul 31 2020 mgw
drwxr-xr-x. 10 oracle oinstall 4096 Jul 31 2020 network
drwxr-xr-x. 5 oracle oinstall 4096 Jul 31 2020 nls
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 oc4j
drwxr-xr-x. 7 oracle oinstall 4096 Jul 31 2020 odbc
drwxr-xr-x. 5 oracle oinstall 4096 Jul 31 2020 olap
drwxr-xr-x. 12 oracle oinstall 4096 Jul 31 2020 OPatch
drwxr-xr-x. 8 oracle oinstall 4096 Jul 31 2020 opmn
drwxr-xr-x. 4 oracle oinstall 4096 Jul 31 2020 oracore
-rw-r-----. 1 oracle oinstall 52 Jul 31 2020 oraInst.loc
drwxr-xr-x. 7 oracle oinstall 4096 Jul 31 2020 ord
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 ordim
drwxr-xr-x. 4 oracle oinstall 4096 Jul 31 2020 ords
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 oss
drwxr-xr-x. 8 oracle oinstall 4096 Jul 31 2020 oui
drwxr-xr-x. 4 oracle oinstall 4096 Jul 31 2020 owm
drwxr-xr-x. 5 oracle oinstall 4096 Jul 31 2020 perl
drwxr-xr-x. 6 oracle oinstall 4096 Jul 31 2020 plsql
drwxr-xr-x. 6 oracle oinstall 4096 Jul 31 2020 precomp
drwxr-xr-x. 2 oracle oinstall 4096 Jul 31 2020 QOpatch
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 R
drwxr-xr-x. 7 oracle oinstall 4096 Jul 31 2020 racg
drwxr-xr-x. 14 oracle oinstall 4096 Jul 31 2020 rdbms
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 relnotes
-rwx------. 1 oracle oinstall 610 Jul 31 2020 root.sh
-rw-r--r--. 1 oracle oinstall 2826 Mar 9 2016 schagent.conf
drwxr-xr-x. 4 oracle oinstall 4096 Jul 31 2020 scheduler
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 slax
drwxr-xr-x. 22 oracle oinstall 4096 Jul 31 2020 sqldeveloper
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 sqlj
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 sqlpatch
drwxr-xr-x. 7 oracle oinstall 4096 Jul 31 2020 sqlplus
drwxr-xr-x. 9 oracle oinstall 4096 Jul 31 2020 srvm
drwxr-xr-x. 5 oracle oinstall 4096 Jul 31 2020 suptools
drwxr-xr-x. 4 oracle oinstall 4096 Jul 31 2020 sysman
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 ucp
drwxr-xr-x. 4 oracle oinstall 4096 Jul 31 2020 usm
drwxr-xr-x. 2 oracle oinstall 4096 Jul 31 2020 utl
drwxr-xr-x. 3 oracle oinstall 4096 Jul 31 2020 wwg
drwxr-x---. 7 oracle oinstall 4096 Jul 31 2020 xdk
[oracle@testos:/u01/app/oracle/product/12.2.0/db_1]$
#移动以上文件和文件夹到创建的目录
[oracle@testos:/u01/app/oracle/product/12.2.0/db_1]$mv * /oracle/app/oracle/product/12.2.0/db_1/
修改环境变量
[oracle@testos:/home/oracle]$env|grep ORACLE
ORACLE_SID=testdb
ORACLE_BASE=/oracle/app/oracle
ORACLE_HOME=/oracle/app/oracle/product/12.2.0/db_1
[oracle@testos:/home/oracle]$
修改oraInst.loc和oratab文件
oraInst.loc文件里面路径不对会影响打补丁
oratab文件里面路径不对会影响自动启动(不常用)
#/etc/oratab修改后的信息
[root@testos ~]# egrep -v "^#|^$" /etc/oratab
testdb:/oracle/app/oracle/product/12.2.0/db_1:N
[root@testos ~]#
#查看oraInst.loc信息
[root@testos ~]# find / -name oraInst.loc
/u01/oraInventory/oraInst.loc
/oracle/app/oracle/product/12.2.0/db_1/oraInst.loc
/etc/oraInst.loc
[root@testos ~]# cat /etc/oraInst.loc
inventory_loc=/u01/oraInventory
inst_group=oinstall
[root@testos ~]# cat /oracle/app/oracle/product/12.2.0/db_1/oraInst.loc
inventory_loc=/u01/oraInventory
inst_group=oinstall
[root@testos ~]# cat /u01/oraInventory/oraInst.loc
inventory_loc=/u01/oraInventory
inst_group=oinstall
[root@testos ~]#
#如下查询报错
[oracle@testos:/home/oracle]$cd $ORACLE_HOME/OPatch
[oracle@testos:/oracle/app/oracle/product/12.2.0/db_1/OPatch]$./opatch lsinventory
Oracle Interim Patch Installer version 12.2.0.1.6
Copyright (c) 2023, Oracle Corporation. All rights reserved.
Oracle Home : /oracle/app/oracle/product/12.2.0/db_1
Central Inventory : /u01/oraInventory
from : /oracle/app/oracle/product/12.2.0/db_1/oraInst.loc
OPatch version : 12.2.0.1.6
OUI version : 12.2.0.1.4
Log file location : /oracle/app/oracle/product/12.2.0/db_1/cfgtoollogs/opatch/opatch2023-09-19_23-56-50PM_1.log
List of Homes on this system:
Home name= OraDB12Home1, Location= "/u01/app/oracle/product/12.2.0/db_1"
LsInventorySession failed: RawInventory gets null OracleHomeInfo
OPatch failed with error code 73
[oracle@testos:/oracle/app/oracle/product/12.2.0/db_1/OPatch]$
#oraInst.loc文件信息不能手动修改,使用以下命令修复
[oracle@testos:/home/oracle]$cd $ORACLE_HOME/oui/bin
[oracle@testos:/oracle/app/oracle/product/12.2.0/db_1/oui/bin]$./runInstaller -silent -ignoreSysPrereqs -attachHome ORACLE_HOME="/oracle/app/oracle/product/12.2.0/db_1" ORACLE_HOME_NAME="OraDB12Home"
Starting Oracle Universal Installer...
Checking swap space: must be greater than 500 MB. Actual 4095 MB Passed
The inventory pointer is located at /etc/oraInst.loc
'AttachHome' was successful.
[oracle@testos:/oracle/app/oracle/product/12.2.0/db_1/oui/bin]$
#查询
[oracle@testos:/home/oracle]$cd $ORACLE_HOME/OPatch
[oracle@testos:/oracle/app/oracle/product/12.2.0/db_1/OPatch]$./opatch lsinventory
Oracle Interim Patch Installer version 12.2.0.1.6
Copyright (c) 2023, Oracle Corporation. All rights reserved.
Oracle Home : /oracle/app/oracle/product/12.2.0/db_1
Central Inventory : /u01/oraInventory
from : /oracle/app/oracle/product/12.2.0/db_1/oraInst.loc
OPatch version : 12.2.0.1.6
OUI version : 12.2.0.1.4
Log file location : /oracle/app/oracle/product/12.2.0/db_1/cfgtoollogs/opatch/opatch2023-10-04_19-29-11PM_1.log
Lsinventory Output file location : /oracle/app/oracle/product/12.2.0/db_1/cfgtoollogs/opatch/lsinv/lsinventory2023-10-04_19-29-11PM.txt
--------------------------------------------------------------------------------
Local Machine Information::
Hostname: testos
ARU platform id: 226
ARU platform description:: Linux x86-64
Installed Top-level Products (1):
Oracle Database 12c 12.2.0.1.0
There are 1 products installed in this Oracle Home.
There are no Interim patches installed in this Oracle Home.
--------------------------------------------------------------------------------
OPatch succeeded.
[oracle@testos:/oracle/app/oracle/product/12.2.0/db_1/OPatch]$
启动监听程序和数据库
[oracle@testos:/home/oracle]$lsnrctl start
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 04-OCT-2023 19:34:06
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Starting /oracle/app/oracle/product/12.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 12.2.0.1.0 - Production
System parameter file is /oracle/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
Log messages written to /oracle/app/oracle/diag/tnslsnr/testos/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=testos)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=testos)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date 04-OCT-2023 19:34:06
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /oracle/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
Listener Log File /oracle/app/oracle/diag/tnslsnr/testos/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=testos)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully
[oracle@testos:/home/oracle]$
[oracle@testos:/home/oracle]$
[oracle@testos:/home/oracle]$sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Wed Oct 4 19:34:17 2023
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 838860800 bytes
Fixed Size 8626240 bytes
Variable Size 629149632 bytes
Database Buffers 197132288 bytes
Redo Buffers 3952640 bytes
Database mounted.
Database opened.
SQL>
恢复方式:移动数据文件、控制文件、redo、temp
原文件位置
[oracle@testos:/u01/app/oracle/oradata/testdb]$ll
total 1998192
-rw-r-----. 1 oracle oinstall 10600448 Oct 4 20:25 control01.ctl
-rw-r-----. 1 oracle oinstall 10600448 Oct 4 20:25 control02.ctl
-rw-r-----. 1 oracle oinstall 209715712 Oct 4 20:25 redo01.log
-rw-r-----. 1 oracle oinstall 209715712 Oct 4 20:18 redo02.log
-rw-r-----. 1 oracle oinstall 209715712 Oct 4 20:18 redo03.log
-rw-r-----. 1 oracle oinstall 482353152 Oct 4 20:19 sysaux01.dbf
-rw-r-----. 1 oracle oinstall 838868992 Oct 4 20:19 system01.dbf
-rw-r-----. 1 oracle oinstall 33562624 Jul 31 2020 temp01.dbf
-rw-r-----. 1 oracle oinstall 68165632 Oct 4 20:19 undotbs01.dbf
-rw-r-----. 1 oracle oinstall 5251072 Oct 4 20:19 users01.dbf
[oracle@testos:/u01/app/oracle/oradata/testdb]$
# 数据库查询
#控制文件
SQL> show parameter control_files;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_files string /u01/app/oracle/oradata/testdb
/control01.ctl, /u01/app/oracl
e/oradata/testdb/control02.ctl
#数据文件
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/testdb/system01.dbf
/u01/app/oracle/oradata/testdb/sysaux01.dbf
/u01/app/oracle/oradata/testdb/undotbs01.dbf
/u01/app/oracle/oradata/testdb/users01.dbf
#临时文件
SQL> select file_name from dba_temp_files;
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/testdb/temp01.dbf
#redo日志文件
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/testdb/redo03.log
/u01/app/oracle/oradata/testdb/redo02.log
/u01/app/oracle/oradata/testdb/redo01.log
如上可以看出数据文件、控制文件、临时文件和redo日志文件都在/u01/app/oracle/oradata/testdb目录下
先做备份
先打开归档
alter system set db_recovery_file_dest_size=10g;
alter system set db_recovery_file_dest='/oracle/archive';
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1
Next log sequence to archive 1
Current log sequence 1
SQL>
使用rman备份数据库
[oracle@testos:/home/oracle]$rman target /
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Oct 4 20:13:14 2023
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: TESTDB (DBID=2830538764)
RMAN> backup tag testdb_full format '/oracle/backup/full_testdb_%s_%p_%t' (database);
Starting backup at 2023-10-04 20:19:34
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=60 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/testdb/system01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/testdb/sysaux01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/testdb/undotbs01.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/testdb/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2023-10-04 20:19:35
channel ORA_DISK_1: finished piece 1 at 2023-10-04 20:19:50
piece handle=/oracle/backup/full_testdb_1_1_1149365975 tag=TESTDB_FULL comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 2023-10-04 20:19:50
Starting Control File and SPFILE Autobackup at 2023-10-04 20:19:50
piece handle=/oracle/archive/TESTDB/autobackup/2023_10_04/o1_mf_s_1149365990_lktp36os_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2023-10-04 20:19:51
RMAN>
RMAN>
RMAN> backup tag testdb_ctl format '/oracle/backup/testdb_ctl_%s_%p_%t' (current controlfile);
Starting backup at 2023-10-04 20:19:59
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 2023-10-04 20:20:00
channel ORA_DISK_1: finished piece 1 at 2023-10-04 20:20:01
piece handle=/oracle/backup/testdb_ctl_3_1_1149365999 tag=TESTDB_CTL comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2023-10-04 20:20:01
Starting Control File and SPFILE Autobackup at 2023-10-04 20:20:01
piece handle=/oracle/archive/TESTDB/autobackup/2023_10_04/o1_mf_s_1149366001_lktp3kt3_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2023-10-04 20:20:02
RMAN>
RMAN>
RMAN> backup tag testdb_spfile format '/oracle/backup/testdb_spfile_%s_%p_%t' (spfile);
Starting backup at 2023-10-04 20:20:07
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 2023-10-04 20:20:07
channel ORA_DISK_1: finished piece 1 at 2023-10-04 20:20:08
piece handle=/oracle/backup/testdb_spfile_5_1_1149366007 tag=TESTDB_SPFILE comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2023-10-04 20:20:08
Starting Control File and SPFILE Autobackup at 2023-10-04 20:20:08
piece handle=/oracle/archive/TESTDB/autobackup/2023_10_04/o1_mf_s_1149366008_lktp3rbv_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2023-10-04 20:20:09
RMAN>
参数文件
SQL> show parameter pfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /oracle/app/oracle/product/12.
2.0/db_1/dbs/spfiletestdb.ora
SQL>
如上参数文件在移动Oracle Home的时候已经移动过去了,参数文件这里可以不动
控制文件
重启数据库至nomount状态
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 838860800 bytes
Fixed Size 8626240 bytes
Variable Size 629149632 bytes
Database Buffers 197132288 bytes
Redo Buffers 3952640 bytes
SQL>
使用rman恢复控制文件
[oracle@testos:/home/oracle]$rman target /
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Oct 4 20:37:49 2023
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: TESTDB (not mounted)
RMAN> set dbid=2830538764
executing command: SET DBID
#从自动备份恢复控制文件到指定路径
RMAN> restore controlfile to '/oracle/oradata/control01.ctl' from autobackup;
Starting restore at 2023-10-04 20:38:55
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=36 device type=DISK
recovery area destination: /oracle/archive
database name (or database unique name) used for search: TESTDB
channel ORA_DISK_1: AUTOBACKUP /oracle/archive/TESTDB/autobackup/2023_10_04/o1_mf_s_1149366008_lktp3rbv_.bkp found in the recovery area
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20231004
channel ORA_DISK_1: restoring control file from AUTOBACKUP /oracle/archive/TESTDB/autobackup/2023_10_04/o1_mf_s_1149366008_lktp3rbv_.bkp
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
Finished restore at 2023-10-04 20:38:58
RMAN> restore controlfile to '/oracle/oradata/control02.ctl' from autobackup;
Starting restore at 2023-10-04 20:39:05
using channel ORA_DISK_1
recovery area destination: /oracle/archive
database name (or database unique name) used for search: TESTDB
channel ORA_DISK_1: AUTOBACKUP /oracle/archive/TESTDB/autobackup/2023_10_04/o1_mf_s_1149366008_lktp3rbv_.bkp found in the recovery area
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20231004
channel ORA_DISK_1: restoring control file from AUTOBACKUP /oracle/archive/TESTDB/autobackup/2023_10_04/o1_mf_s_1149366008_lktp3rbv_.bkp
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
Finished restore at 2023-10-04 20:39:06
RMAN>
如下新路径生成了控制文件:
[oracle@testos:/oracle/oradata]$ll
total 20704
-rw-r----- 1 oracle oinstall 10600448 Oct 4 20:38 control01.ctl
-rw-r----- 1 oracle oinstall 10600448 Oct 4 20:39 control02.ctl
[oracle@testos:/oracle/oradata]$
修改控制文件路径信息:
SQL> alter system set control_files='/oracle/oradata/control01.ctl','/oracle/oradata/control02.ctl' scope=spfile;
System altered.
SQL>
重启数据库至mount状态
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL>
SQL> startup mount
ORACLE instance started.
Total System Global Area 838860800 bytes
Fixed Size 8626240 bytes
Variable Size 629149632 bytes
Database Buffers 197132288 bytes
Redo Buffers 3952640 bytes
Database mounted.
SQL>
-- 如下现在mount使用的是新的控制文件
SQL> show parameter control_files;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_files string /oracle/oradata/control01.ctl,
/oracle/oradata/control02.ctl
数据文件
查看rman之前的备份信息
[oracle@testos:/home/oracle]$rman target /
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Oct 4 20:43:29 2023
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: TESTDB (DBID=2830538764, not open)
RMAN> list backupset;
......
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
1 Full 1.00G DISK 00:00:07 2023-10-04 20:19:42
BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TESTDB_FULL
Piece Name: /oracle/backup/full_testdb_1_1_1149365975
List of Datafiles in backup set 1
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- ------------------- ----------- ------ ----
1 Full 1434437 2023-10-04 20:19:35 NO /u01/app/oracle/oradata/testdb/system01.dbf
3 Full 1434437 2023-10-04 20:19:35 NO /u01/app/oracle/oradata/testdb/sysaux01.dbf
4 Full 1434437 2023-10-04 20:19:35 NO /u01/app/oracle/oradata/testdb/undotbs01.dbf
7 Full 1434437 2023-10-04 20:19:35 NO /u01/app/oracle/oradata/testdb/users01.dbf
如上找到最近的一次全备记录,正常restore的话,会恢复到之前的路径下,但是我们现在要做的是恢复到新的路径下
使用以下脚本进行恢复:
run{
set newname for datafile '/u01/app/oracle/oradata/testdb/system01.dbf' to '/oracle/oradata/system01.dbf';
set newname for datafile '/u01/app/oracle/oradata/testdb/sysaux01.dbf' to '/oracle/oradata/sysaux01.dbf';
set newname for datafile '/u01/app/oracle/oradata/testdb/undotbs01.dbf' to '/oracle/oradata/undotbs01.dbf';
set newname for datafile '/u01/app/oracle/oradata/testdb/users01.dbf' to '/oracle/oradata/users01.dbf';
restore database;
switch datafile all;
}
执行过程如下
RMAN> run{
2> set newname for datafile '/u01/app/oracle/oradata/testdb/system01.dbf' to '/oracle/oradata/system01.dbf';
3> set newname for datafile '/u01/app/oracle/oradata/testdb/sysaux01.dbf' to '/oracle/oradata/sysaux01.dbf';
4> set newname for datafile '/u01/app/oracle/oradata/testdb/undotbs01.dbf' to '/oracle/oradata/undotbs01.dbf';
5> set newname for datafile '/u01/app/oracle/oradata/testdb/users01.dbf' to '/oracle/oradata/users01.dbf';
6> restore database;
7> switch datafile all;
8> }
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 2023-10-04 20:49:42
Starting implicit crosscheck backup at 2023-10-04 20:49:42
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=42 device type=DISK
Crosschecked 5 objects
Finished implicit crosscheck backup at 2023-10-04 20:49:43
Starting implicit crosscheck copy at 2023-10-04 20:49:43
using channel ORA_DISK_1
Finished implicit crosscheck copy at 2023-10-04 20:49:43
searching for all files in the recovery area
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /oracle/archive/TESTDB/autobackup/2023_10_04/o1_mf_s_1149366008_lktp3rbv_.bkp
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /oracle/oradata/system01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /oracle/oradata/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /oracle/oradata/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00007 to /oracle/oradata/users01.dbf
channel ORA_DISK_1: reading from backup piece /oracle/backup/full_testdb_1_1_1149365975
channel ORA_DISK_1: piece handle=/oracle/backup/full_testdb_1_1_1149365975 tag=TESTDB_FULL
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 2023-10-04 20:49:50
datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=1149367790 file name=/oracle/oradata/system01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=1149367790 file name=/oracle/oradata/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=7 STAMP=1149367790 file name=/oracle/oradata/undotbs01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=8 STAMP=1149367790 file name=/oracle/oradata/users01.dbf
RMAN>
restore之后新的目录下就生成了对应的文件:
[oracle@testos:/oracle/oradata]$ll
total 1382664
-rw-r----- 1 oracle oinstall 10600448 Oct 4 20:50 control01.ctl
-rw-r----- 1 oracle oinstall 10600448 Oct 4 20:50 control02.ctl
-rw-r----- 1 oracle oinstall 482353152 Oct 4 20:49 sysaux01.dbf
-rw-r----- 1 oracle oinstall 838868992 Oct 4 20:49 system01.dbf
-rw-r----- 1 oracle oinstall 68165632 Oct 4 20:49 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 Oct 4 20:49 users01.dbf
[oracle@testos:/oracle/oradata]$
现在还不能做recover,因为我们控制文件的信息都是不对的(存放的是之前文件的路径信息),控制文件需要重建
[oracle@testos:/oracle/oradata]$strings control01.ctl|grep oradata|sort|uniq
/oracle/oradata/sysaux01.dbf
oracle/oradata/sysaux01.dbf
/oracle/oradata/system01.dbf
oracle/oradata/system01.dbf
/oracle/oradata/undotbs01.dbf
oracle/oradata/undotbs01.dbf
/oracle/oradata/users01.dbf
oracle/oradata/users01.dbf
/u01/app/oracle/oradata/testdb/redo01.log
/u01/app/oracle/oradata/testdb/redo02.log
/u01/app/oracle/oradata/testdb/redo03.log
/u01/app/oracle/oradata/testdb/sysaux01.dbf
/u01/app/oracle/oradata/testdb/system01.dbf
/u01/app/oracle/oradata/testdb/temp01.dbf
/u01/app/oracle/oradata/testdb/undotbs01.dbf
/u01/app/oracle/oradata/testdb/users01.dbf
[oracle@testos:/oracle/oradata]$
重建控制文件
dump出控制文件trace
SQL> alter database backup controlfile to trace as '/oracle/1.txt';
Database altered.
trace出的信息如下
[oracle@testos:/oracle]$egrep -v "^--|^$" 1.txt
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "TESTDB" NORESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/testdb/redo01.log' SIZE 200M BLOCKSIZE 512,
GROUP 2 '/u01/app/oracle/oradata/testdb/redo02.log' SIZE 200M BLOCKSIZE 512,
GROUP 3 '/u01/app/oracle/oradata/testdb/redo03.log' SIZE 200M BLOCKSIZE 512
DATAFILE
'/oracle/oradata/system01.dbf',
'/oracle/oradata/sysaux01.dbf',
'/oracle/oradata/undotbs01.dbf',
'/oracle/oradata/users01.dbf'
CHARACTER SET AL32UTF8;
RECOVER DATABASE
ALTER SYSTEM ARCHIVE LOG ALL;
ALTER DATABASE OPEN;
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/testdb/temp01.dbf' REUSE;
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "TESTDB" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/testdb/redo01.log' SIZE 200M BLOCKSIZE 512,
GROUP 2 '/u01/app/oracle/oradata/testdb/redo02.log' SIZE 200M BLOCKSIZE 512,
GROUP 3 '/u01/app/oracle/oradata/testdb/redo03.log' SIZE 200M BLOCKSIZE 512
DATAFILE
'/oracle/oradata/system01.dbf',
'/oracle/oradata/sysaux01.dbf',
'/oracle/oradata/undotbs01.dbf',
'/oracle/oradata/users01.dbf'
CHARACTER SET AL32UTF8;
RECOVER DATABASE USING BACKUP CONTROLFILE
ALTER DATABASE OPEN RESETLOGS;
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/testdb/temp01.dbf' REUSE;
[oracle@testos:/oracle]$
整理重建控制文件的命令如下:
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "TESTDB" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/oracle/oradata/redo01.log' SIZE 200M BLOCKSIZE 512,
GROUP 2 '/oracle/oradata/redo02.log' SIZE 200M BLOCKSIZE 512,
GROUP 3 '/oracle/oradata/redo03.log' SIZE 200M BLOCKSIZE 512
DATAFILE
'/oracle/oradata/system01.dbf',
'/oracle/oradata/sysaux01.dbf',
'/oracle/oradata/undotbs01.dbf',
'/oracle/oradata/users01.dbf';
重启数据库至nomount状态
SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL>
SQL>
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 838860800 bytes
Fixed Size 8626240 bytes
Variable Size 629149632 bytes
Database Buffers 197132288 bytes
Redo Buffers 3952640 bytes
SQL>
执行重建控制文件的命令
SQL> CREATE CONTROLFILE REUSE DATABASE "TESTDB" RESETLOGS ARCHIVELOG
2 MAXLOGFILES 16
3 MAXLOGMEMBERS 3
4 MAXDATAFILES 100
MAXINSTANCES 8
GROUP 1 '/oracle/oradata/redo01.log' SIZE 200M BLOCKSIZE 512,
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/oracle/oradata/redo01.log' SIZE 200M BLOCKSIZE 512,
DATAFILE
GROUP 2 '/oracle/oradata/redo02.log' SIZE 200M BLOCKSIZE 512,
'/oracle/oradata/sysaux01.dbf',
GROUP 3 '/oracle/oradata/redo03.log' SIZE 200M BLOCKSIZE 512
DATAFILE
'/oracle/oradata/system01.dbf',
'/oracle/oradata/sysaux01.dbf',
'/oracle/oradata/undotbs01.dbf',
15 '/oracle/oradata/users01.dbf';
Control file created.
SQL>
-- 控制文件重建后数据库自动mount起来了
SQL> select NAME,OPEN_MODE from v$database;
NAME OPEN_MODE
--------- --------------------
TESTDB MOUNTED
SQL>
使用resetlogs模式open数据库
SQL> alter database open resetlogs;
Database altered.
SQL>
如下系统重建了redo日志
[oracle@testos:/oracle]$cd /oracle/oradata/
[oracle@testos:/oracle/oradata]$ll
total 1997720
-rw-r----- 1 oracle oinstall 10928128 Oct 4 21:00 control01.ctl
-rw-r----- 1 oracle oinstall 10928128 Oct 4 21:00 control02.ctl
-rw-r----- 1 oracle oinstall 209715712 Oct 4 21:00 redo01.log
-rw-r----- 1 oracle oinstall 209715712 Oct 4 21:00 redo02.log
-rw-r----- 1 oracle oinstall 209715712 Oct 4 21:00 redo03.log
-rw-r----- 1 oracle oinstall 482353152 Oct 4 21:00 sysaux01.dbf
-rw-r----- 1 oracle oinstall 838868992 Oct 4 21:00 system01.dbf
-rw-r----- 1 oracle oinstall 68165632 Oct 4 21:00 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 Oct 4 21:00 users01.dbf
[oracle@testos:/oracle/oradata]$
临时文件
SQL> select * from dba_temp_files;
no rows selected
-- 添加临时文件
SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '/oracle/oradata/temp01.dbf' size 50m;
Tablespace altered.
SQL>
如下临时文件也有了
[oracle@testos:/oracle/oradata]$ll
total 1998744
-rw-r----- 1 oracle oinstall 10928128 Oct 4 21:02 control01.ctl
-rw-r----- 1 oracle oinstall 10928128 Oct 4 21:02 control02.ctl
-rw-r----- 1 oracle oinstall 209715712 Oct 4 21:01 redo01.log
-rw-r----- 1 oracle oinstall 209715712 Oct 4 21:00 redo02.log
-rw-r----- 1 oracle oinstall 209715712 Oct 4 21:00 redo03.log
-rw-r----- 1 oracle oinstall 482353152 Oct 4 21:00 sysaux01.dbf
-rw-r----- 1 oracle oinstall 838868992 Oct 4 21:00 system01.dbf
-rw-r----- 1 oracle oinstall 52436992 Oct 4 21:01 temp01.dbf
-rw-r----- 1 oracle oinstall 68165632 Oct 4 21:00 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 Oct 4 21:00 users01.dbf
[oracle@testos:/oracle/oradata]$
查看日志状态
set line 100
col GROUP# for 9
col MEMBER for a45
col SIZE for a4
col STATUS for a10
GROUP# MEMBERS MEMBER SIZE/MB ARC STATUS TYPE
------ ---------- --------------------------------------------- ---------- --- ---------- -------
3 1 /oracle/oradata/redo03.log 200 YES UNUSED ONLINE
2 1 /oracle/oradata/redo02.log 200 YES UNUSED ONLINE
1 1 /oracle/oradata/redo01.log 200 NO CURRENT ONLINE
-- 切换日志
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
-- 再次查询日志
GROUP# MEMBERS MEMBER SIZE/MB ARC STATUS TYPE
------ ---------- --------------------------------------------- ---------- --- ---------- -------
3 1 /oracle/oradata/redo03.log 200 NO CURRENT ONLINE
2 1 /oracle/oradata/redo02.log 200 YES ACTIVE ONLINE
1 1 /oracle/oradata/redo01.log 200 YES ACTIVE ONLINE
警告日志
SQL> show parameter diagnostic_dest;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
diagnostic_dest string /u01/app/oracle
SQL> alter system set diagnostic_dest = '/oracle/app/oracle';
System altered.
查询验证
-- 控制文件
SQL> show parameter control_files;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_files string /oracle/oradata/control01.ctl,
/oracle/oradata/control02.ctl
SQL>
-- 数据文件
SQL> select name from v$datafile;
NAME
----------------------------------------------------------------------------------------------------
/oracle/oradata/system01.dbf
/oracle/oradata/sysaux01.dbf
/oracle/oradata/undotbs01.dbf
/oracle/oradata/users01.dbf
SQL>
-- 临时文件
SQL> select file_name from dba_temp_files;
FILE_NAME
----------------------------------------------------------------------------------------------------
/oracle/oradata/temp01.dbf
SQL>
-- redo日志文件
SQL> select member from v$logfile;
MEMBER
---------------------------------------------
/oracle/oradata/redo03.log
/oracle/oradata/redo02.log
/oracle/oradata/redo01.log
SQL>
-- 查询实例状态
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ----------
testdb OPEN
移动方式:数据文件移动到其他盘
redo日志文件
--查看redo文件情况
set line 200
col member for a40
select group#, lf.member, lg.status, lg.bytes / 1024 / 1024 as "size/mb"
from v$log lg
join v$logfile lf
using (group#);
sys@orclcdb(873)> /
GROUP# MEMBER STATUS size/mb
---------- ---------------------------------------- ---------------- ----------
3 /opt/oracle/oradata/ORCLCDB/redo03.log INACTIVE 200
2 /opt/oracle/oradata/ORCLCDB/redo02.log CURRENT 200
1 /opt/oracle/oradata/ORCLCDB/redo01.log INACTIVE 200
--如上可以看出当前有3组日志文件,每组里面有一个日志文件,每个文件200mb
--为日志组添加新的redo日志文件
alter database add logfile member '/data1/oracle/oradata/redo01.log' to group 1;
alter database add logfile member '/data1/oracle/oradata/redo02.log' to group 2;
alter database add logfile member '/data1/oracle/oradata/redo03.log' to group 3;
--查询此时的redo日志文件信息
set line 200
col member for a40
select group#, lf.member, lg.status, lg.bytes / 1024 / 1024 as "size/mb"
from v$log lg
join v$logfile lf
using (group#);
GROUP# MEMBER STATUS size/mb
---------- ---------------------------------------- ---------------- ----------
3 /opt/oracle/oradata/ORCLCDB/redo03.log INACTIVE 200
2 /opt/oracle/oradata/ORCLCDB/redo02.log CURRENT 200
1 /opt/oracle/oradata/ORCLCDB/redo01.log INACTIVE 200
1 /data1/oracle/oradata/redo01.log INACTIVE 200
2 /data1/oracle/oradata/redo02.log CURRENT 200
3 /data1/oracle/oradata/redo03.log INACTIVE 200
--切换日志直到原日志文件的状态全部为INACTIVE
alter system switch logfile;
alter system checkpoint;
--查询redo日志文件状态
GROUP# MEMBER STATUS size/mb
---------- ---------------------------------------- ---------------- ----------
3 /opt/oracle/oradata/ORCLCDB/redo03.log INACTIVE 200
2 /opt/oracle/oradata/ORCLCDB/redo02.log INACTIVE 200
1 /opt/oracle/oradata/ORCLCDB/redo01.log INACTIVE 200
1 /data1/oracle/oradata/redo01.log CURRENT 200
2 /data1/oracle/oradata/redo02.log INACTIVE 200
3 /data1/oracle/oradata/redo03.log CURRENT 200
--删除原日志文件
alter database drop logfile member '/opt/oracle/oradata/ORCLCDB/redo01.log';
alter database drop logfile member '/opt/oracle/oradata/ORCLCDB/redo02.log';
alter database drop logfile member '/opt/oracle/oradata/ORCLCDB/redo03.log';
--进到文件系统删除原日志文件
cd /opt/oracle/oradata/ORCLCDB
rm -rf redo01.log redo02.log redo03.log
非系统表空间文件
--将表空间offline
alter tablespace USERS offline;
alter tablespace XSTREAM_TBS offline;
alter tablespace XSTREAM_ADM_TBS offline;
alter tablespace XSTREAM_ADMIN_TBS offline;
--创建新存放表空间文件的路径,将文件移动过去
mv /opt/oracle/oradata/ORCLCDB/xstream_adm_tbs.dbf /data1/oracle/oradata/
mv /opt/oracle/oradata/ORCLCDB/xstream_tbs.dbf /data1/oracle/oradata/
mv /opt/oracle/oradata/ORCLCDB/users01.dbf /data1/oracle/oradata/
mv /opt/oracle/oradata/ORCLCDB/xstream_admin_tbs.dbf /data1/oracle/oradata/
--修改表空间的路径
alter tablespace USERS rename datafile '/opt/oracle/oradata/ORCLCDB//users01.dbf' to '/data1/oracle/oradata/users01.dbf';
alter tablespace XSTREAM_ADM_TBS rename datafile '/opt/oracle/oradata/ORCLCDB/xstream_adm_tbs.dbf' to '/data1/oracle/oradata/xstream_adm_tbs.dbf';
alter tablespace XSTREAM_TBS rename datafile '/opt/oracle/oradata/ORCLCDB/xstream_tbs.dbf' to '/data1/oracle/oradata/xstream_tbs.dbf';
alter tablespace XSTREAM_ADMIN_TBS rename datafile '/opt/oracle/oradata/ORCLCDB/xstream_admin_tbs.dbf' to '/data1/oracle/oradata/xstream_admin_tbs.dbf';
--将相关表空间online
alter tablespace USERS online;
alter tablespace XSTREAM_TBS online;
alter tablespace XSTREAM_ADM_TBS online;
alter tablespace XSTREAM_ADMIN_TBS online;
使用RMAN COPY 移动 Datafile 位置
1.查看datafile位置
SQL> select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
/oracle/app/oracle/oradata/LORCL19/system01.dbf
/oracle/app/oracle/oradata/LORCL19/sysaux01.dbf
/oracle/app/oracle/oradata/LORCL19/undotbs01.dbf
/oracle/app/oracle/oradata/LORCL19/users01.dbf
#创建一个新目录
mkdir -p /data/oradata
2.编写RMAN 脚本Rcopy.sh
export LANG=en_US
RMAN_LOG_FILE=${0}.out
ORACLE_HOME=/oracle/app/oracle/product/19.3.0/db
export ORACLE_HOME
RMAN=$ORACLE_HOME/bin/rman
export RMAN
ORACLE_SID=lorcl19
export ORACLE_SID
ORACLE_USER=oracle
export ORACLE_USER
echo "ORACLE_SID:$ORACLE_SID">>$RMAN_LOG_FILE
echo"ORACLE_HOME:$ORACLE_HOME">>$RMAN_LOG_FILE
echo"ORACLE_USER:$ORACLE_USER">>$RMAN_LOG_FILE
echo"==========================">>$RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
$RMAN nocatalog TARGET / msglog$RMAN_LOG_FILE append <<EOF
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
copy datafile '/oracle/app/oracle/oradata/LORCL19/system01.dbf' to '/data/oradata/system01.dbf';
copy datafile '/oracle/app/oracle/oradata/LORCL19/sysaux01.dbf' to '/data/oradata/sysaux01.dbf';
copy datafile '/oracle/app/oracle/oradata/LORCL19/undotbs01.dbf' to '/data/oradata/undotbs01.dbf';
copy datafile '/oracle/app/oracle/oradata/LORCL19/users01.dbf' to '/data/oradata/users01.dbf';
release channel c2;
release channel c1;
}
EOF
echo >> $RMAN_LOG_FILE
exit
3.将DB 启动到mount 状态
shutdown immediate
startup mount
4. 执行Rmancopy 脚本
crontab -l
00 11 * * * /u01/Rcopy.sh &
#检查拷贝情况
ls
5. 对数据文件进行Rename
这里的Rename 操作更新datafile 在控制文件里的记录。注意的一点,控制文件不记录临时文件的信息,所以,临时文件rename不能rename。如果要对临时文件进行转移,可以对临时文件进行重建。 这块内容具体参考:
alter database rename file '/oracle/app/oracle/oradata/LORCL19/system01.dbf' to '/data/oradata/system01.dbf';
alter database rename file '/oracle/app/oracle/oradata/LORCL19/sysaux01.dbf' to '/data/oradata/sysaux01.dbf';
alter database rename file '/oracle/app/oracle/oradata/LORCL19/undotbs01.dbf' to '/data/oradata/undotbs01.dbf';
alter database rename file '/oracle/app/oracle/oradata/LORCL19/users01.dbf' to '/data/oradata/users01.dbf';
6.打开DB并验证
alter database open;
#报错和处理
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/data/oradata/system01.dbf'
recovery datafile '/data/oradata/system01.dbf';
recover tablespace system;
recover database;
alter database open;
#查看数据文件
SQL> select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
/data/oradata/system01.dbf
/data/oradata/sysaux01.dbf
/data/oradata/undotbs01.dbf
/data/oradata/users01.dbf