保命法则:先备份再操作,磁盘空间紧张无法备份就让满足,给自己留退路。
场景说明:
1.本文档的环境为同平台、不同版本(操作系统版本可以不同,数据库小版本不同),源机器和目标机器部分控制文件和ORACLE_BASE目录不一样。
2.目标机器只需要安装oracle只安装oracle数据库软件,不创建数据库(no netca dbca)。
3.第一次利用备份恢复测试环境,之后从源机器拷贝备份到目标机器并在控制文件中注册,再进行恢复测试。
主要过程:
将切换归档,执行rman全库备份以及密码文件拷贝到目标主机进行rman恢复、升级。
注意事项:
当使用rman nocatalog恢复时,数据库必须是处于“mount”状态的。而Oracle startup mount的前提条件是control必须存在。因此,你必须在恢复datafile之前先恢复controlfile。
特别说明:
源数据库和新数据库控制文件目录和ORACLE_BASE目录不同,其他目录相同。解决办法:更改参数文件中控制文件目录和ORACLE_BASE目录为新数据库位置。
源数据库和新数据库控制文件目录和ORACLE_BASE目录不同,其他目录不相同。解决办法:更改参数文件中控制文件目录和ORACLE_BASE目录为新数据库位置、更改控制文件中数据文件位置。
环境描述
源数据库环境
操作系统版本 : CentOS Linux release 7.9 内存:4G cpu:1核 磁盘:40G
数据库版本 : Oracle 11.2.0.3 x64
数据库架构:单点
数据库名 : dxj
数据库SID : dxj
db_unique_name : dxj
instance_name : dxj
归档模式:已开启
IP : 192.168.40.53
目标数据库环境
操作系统版本 : CentOS Linux release 7.9 内存:4G cpu:1核 磁盘:40G
数据库版本 : Oracle 11.2.0.4 x64 (只安装grid、oracle数据库软件,no dbca)
数据库架构:RAC
OS | 规格 | 主机名 | IP | VIP | private IP | scanip |
redhat 7.9 | 1C2G | orcl01 | 192.168.40.200 | 192.168.40.202 | 192.168.183.200 | 192.168.40.205 |
redhat 7.9 | 1C2G | orcl02 | 192.168.40.201 | 192.168.40.203 | 192.168.183.201 |
迁移前源库准备
统计数据量
--查看数据文件总大小
select sum(bytes)/1024/1024/1024 as "size(G)" from dba_data_files;
size(G)
----------
1.328125
--查看总大小
select round(sum(bytes) / 1024 / 1024 / 1024, 2) || 'G'
from dba_segments;
ROUND(SUM(BYTES)/1024/1024/1024,2)||'G'
-----------------------------------------
1.21G
统计业务数据
--查看用户
set lin1000 pagesize 999
select username,default_tablespace,temporary_tablespace from dba_users where username not in ('SYS','SYSTEM','HR','OUTLN','MGMT_VIEW','FLOWS_FILES','MDSYS','ORDSYS','EXFSYS','DBSNMP','WMSYS','APPQOSSYS','APEX_030200','OWBSYS_AUDIT','ORDDATA','CTXSYS','ANONYMOUS','SYSMAN','XDB','ORDPLUGINS','OWBSYS','SI_INFORMTN_SCHEMA','OLAPSYS','SCOTT','ORACLE_OCM','XS$NULL','BI','PM','MDDATA','IX','SH','DIP','OE','APEX_PUBLIC_USER','SPATIAL_CSW_ADMIN_USR','SPATIAL_WFS_ADMIN_USR');
USERNAME DEFAULT_TABLESPACE TEMPORARY_TABLESPACE
------------------------------ ------------------------------ ------------------------------
FUWA USERS TEMP
--查看用户使用了哪些表空间
select distinct tablespace_name from dba_segments where owner in ('FUWA');
--每个业务用户下的总对象数量校验
SELECT D.OWNER,COUNT(1)
FROM dba_objects d
WHERE d.OWNER in ('FUWA')
AND NOT EXISTS (SELECT 1 FROM DBA_RECYCLEBIN B WHERE B.object_name=D.OBJECT_NAME AND D.OWNER=B.owner)
GROUP BY D.OWNER
ORDER BY D.OWNER ;
OWNER COUNT(1)
------------------------------ ----------
FUWA 1
--每个业务用户下的各个对象类别的数量校验
SQL> select OWNER,OBJECT_TYPE,status,count(OBJECT_NAME) from dba_objects where owner in ('FUWA') group by OBJECT_TYPE,owner,status order by 1,3,2;
OWNER OBJECT_TYPE STATUS COUNT(OBJECT_NAME)
------------------------------ ------------------- ------- ------------------
FUWA TABLE VALID 1
清理业务数据
需和开发 直属领导同意。对于占用空间大的表采用方案如下:
1、删除表数据。
2、备份时加参数排除,即不备份对业务来说不重要的表。
--查看表大小超过10G的大表
col owner for a40
col TABLE_NAME for a60
set linesize 999 pagesize 999
select * from (SELECT OWNER,TABLE_NAME,SUM(tabsize) table_size from (
SELECT owner,SEGMENT_NAME as table_name,SUM(BYTES)/1024/1024/1024 as tabsize FROM DBA_SEGMENTS WHERE (OWNER,SEGMENT_NAME) IN (
SELECT OWNER,TABLE_NAME FROM DBA_TABLES WHERE OWNER NOT IN ('SYS','SYSTEM','DBSNMP'))
GROUP BY SEGMENT_NAME,owner
union ALL
select lob.owner,lob.table_name,sum(seg.bytes)/1024/1024/1024 as tabsize from dba_lobs lob,dba_segments seg
where lob.segment_name=seg.segment_name and lob.OWNER NOT IN ('SYS','SYSTEM','DBSNMP') group by lob.owner,lob.table_name
)
GROUP BY OWNER,TABLE_NAME ORDER BY 3 DESC)
where table_size>10 ;
--查询库中记录数大于2千万的所有表,当前用户拥有select any table权限
select table_name, num_rows from dba_tables t where t.owner = upper('hr') and num_rows > 20000000;
或
select table_name, num_rows from all_tables t where t.owner = upper('hr') and num_rows > 20000000;
停止监听
--停止监听
su - oracle
[oracle@dxj ~]$ lsnrctl status
[oracle@dxj ~]$ lsnrctl stop
[oracle@dxj ~]$ lsnrctl status
开启防火墙
--开启防火墙
systemctl start firewalld
systemctl status firewalld
firewall-cmd --list-ports
停止会话
查询会话,如果有业务会话给干掉
--查看不同用户的连接数
select username,count(username) from v$session where username is not null group by username;
--查询用户会话
select username,serial#, sid ,status from v$session where username is not null;
select username,status,schemaname,osuser,process,machine,port,program,serial#, sid from v$session where username is not null;
--删除相关用户会话
alter system kill session 'sid,serial#';
补充:
--源库杀用户连接 不建议 该步骤慎重 该文档未进行该操作 该方法迫不得已不用
ps -ef|grep LOCAL=NO|awk '{print $2}'|xargs kill -9
锁定业务用户
--查看用户 和现场负责人确定哪些是业务用户,哪些是需要迁的用户
set lin1000 pagesize 999
select username,default_tablespace,temporary_tablespace from dba_users where username not in ('SYS','SYSTEM','HR','OUTLN','MGMT_VIEW','FLOWS_FILES','MDSYS','ORDSYS','EXFSYS','DBSNMP','WMSYS','APPQOSSYS','APEX_030200','OWBSYS_AUDIT','ORDDATA','CTXSYS','ANONYMOUS','SYSMAN','XDB','ORDPLUGINS','OWBSYS','SI_INFORMTN_SCHEMA','OLAPSYS','SCOTT','ORACLE_OCM','XS$NULL','BI','PM','MDDATA','IX','SH','DIP','OE','APEX_PUBLIC_USER','SPATIAL_CSW_ADMIN_USR','SPATIAL_WFS_ADMIN_USR');
USERNAME DEFAULT_TABLESPACE TEMPORARY_TABLESPACE
------------------------------ ------------------------------ ------------------------------
FUWA USERS TEMP
--锁定业务用户
select username,account_status,lock_date from dba_users where username='FUWA';
alter user FUWA account lock;
或
select 'alter user '||username||' account lock;' from dba_users where username in ('FUWA') and ACCOUNT_STATU='OPEN';
执行以上输出结果
查看数据库信息
查看数据库参数
--数据库的创建日期和归档方式
SELECT to_char(created,'yyyy-mm-dd'), log_mode, log_mode FROM V$database;
TO_CHAR(CR LOG_MODE LOG_MODE
---------- ------------ ------------
2024-05-26 ARCHIVELOG ARCHIVELOG
--查数据库版本
SELECT version FROM product_component_version WHERE substr(product, 1, 6) = 'Oracle';
VERSION
--------------------------------------------------------------------------------
11.2.0.3.0
--查看实例名
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
dxj
-- 查看数据库字符集
set linesize 999
col value for a60
select * from nls_database_parameters where PARAMETER in ('NLS_CHARACTERSET','NLS_NCHAR_CHARACTERSET');
PARAMETER VALUE
------------------------------ ----------------------------------------------------------------------------
NLS_CHARACTERSET AL32UTF8
NLS_NCHAR_CHARACTERSET UTF8
select userenv('language') from dual;
USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.AL32UTF8
--查看当前数据库时区
select dbtimezone from dual;
补充:如果不是东八区 alter database set time_zone='+8:00';
-- 查看数据库配置参数
set lin 1000 pagesize 999
col NAME for a30
col value for a40
col DISPLAY_VALUE for a40
SELECT name,value,display_value FROM v$parameter
WHERE name IN(
'processes',
'sessions',
'memory_target',
'memory_max_target',
'sga_max_size',
'sga_target',
'pga_aggregate_target'
);
NAME VALUE DISPLAY_VALUE
------------------------------ ---------------------------------------- ----------------------------------------
processes 2000 2000
sessions 3022 3022
sga_max_size 2650800128 2528M
sga_target 2650800128 2528M
memory_target 0 0
memory_max_target 0 0
pga_aggregate_target 659554304 629M
7 rows selected.
查看源数据库DBID、控制文件、数据文件、redo日志文件的存储位置和归档:
--查看源数据库的DBID:
sys@DXJ 2024-01-25 17:21:58> select dbid from v$database;
DBID
----------
2712415422
--查看控制文件:
sys@DXJ 2024-01-25 17:22:01> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
/oradata/dxj/control01.ctl
/u01/app/oracle/fast_recovery_area/dxj/control02.ctl
--查看数据文件:
sys@DXJ 2024-01-25 17:22:52> set linesize 999
sys@DXJ 2024-01-25 17:22:52> col name for a69
sys@DXJ 2024-01-25 17:22:19> select status,name from v$datafile;
STATUS NAME
------- --------------------------------------------------------------------------------
SYSTEM /oradata/dxj/system01.dbf
ONLINE /oradata/dxj/sysaux01.dbf
ONLINE /oradata/dxj/undotbs01.dbf
ONLINE /oradata/dxj/users01.dbf
ONLINE /oradata/dxj/fuwa01.dbf
ONLINE /oradata/dxj/top01.dbf
6 rows selected.
--查看日志文件:
--查看redo log大小和位置
set linesize 999
col member for a60
select b.thread#,a.group#,a.member,bytes/1024/1024,b.members,b.status from v$logfile a,v$log b where a.group#=b.group#;
--查看归档模式
sys@DXJ 2024-05-27 10:14:02> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oradata/archivelog
Oldest online log sequence 5
Next log sequence to archive 7
Current log sequence 7
源数据库服务器
rman备份源数据库
文件多的场景加section size
大文件切片 多开并行,优化速度,前提是存储牛逼,不然加了也没啥作用
评估:备份时间,传输时间,恢复时间,遇到问题
[oracle@dxj:/data/rman_bak]$ cat /data/rman_bak.sh
#!/bin/bash
source /home/oracle/.bash_profile
export NLS_DATE_FORMAT='YYYYMMDD hh24:mi:ss'
rq=`date +%Y%m%d`
bakdir=/data/rman_bak/${rq}
autobak=/data/rman_bak/autobackup
if [ ! -d ${bakdir} ];
then mkdir -p ${bakdir}
fi
if [ ! -d ${autobak} ];
then mkdir -p ${autobak}
fi
cd $ORACLE_HOME/bin
./rman log $bakdir/rman${rq}.log target / <<EOF
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
backup incremental level 0 as compressed backupset section size 10g format='${autobak}/emrdb_full_%U_%d_%T_%s' database;
sql 'alter system switch logfile';
backup as compressed backupset section size 10g archivelog from time 'sysdate-1/12' format='${autobak}/emrdb_arc_%U_%d_%T_%s';
BACKUP CURRENT CONTROLFILE format '${autobak}/emrdb_ctl_bk_%U_%d_%T' ;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
exit;
EOF
chmod +x /data/rman_bak.sh
nohup sh /data/rman_bak.sh &
参数说明:
sysdate-1/12 :2小时之前的归档。
%U_%d_%T_%s
%U:默认是%u_%p_%c的简写形式,利用它可以为每一个备份片段(即磁盘文件)生成一个唯一名称,这是最常用的命名方式,执行不同备份操作时,生成的规则也不同,如下所示:
生成备份片段时,%U=%u_%p_%c;
%u:是一个由备份集编号和建立时间压缩后组成的8字符名称。利用%u可以为每个备份集生成一个唯一的名称。
%p:备份集中备份片段的编号,从1开始。
%c:备份片段的复制数(从1开始编号,最大不超过256)。
%d:Oracle数据库名称。
%T:当前时间的年月日格式(YYYYMMDD)。
%s:备份集号。
rman备份有时间点,和scn 记录一下,恢复的时候按时间点和scn恢复就行了
通过rman进行一次全备:
vi rman_bak_L0.sh
#************************************************************************
#*** rman_bak_L0.sh ***
#************************************************************************
#!/bin/bash
source /home/oracle/.bash_profile
rq=`date +%Y%m%d`
bakdir=/topsoft/rmanbak/${rq}
autobak=/topsoft/rmanbak/autobackup
if [ ! -d ${bakdir} ];
then mkdir -p ${bakdir}
fi
if [ ! -d ${autobak} ];
then mkdir -p ${autobak}
fi
cd $ORACLE_HOME/bin
./rman target / log=$bakdir/rmanfull_${rq}.log <<EOF
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '${autobak}/%F';
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
allocate channel c5 type disk;
allocate channel c6 type disk;
sql 'alter system archive log current';
backup as compressed backupset incremental level 0 database tag 'dbfull' format '${autobak}/backlv0_%d_%T_%t_%s_%p.bak';
sql 'alter system archive log current';
backup as compressed backupset archivelog all tag 'arch' format '${autobak}/arch_%d_%T_%t_%s_%p.bak';
backup current controlfile format '${autobak}/ctl_%d_%T_%t_%s_%p.bak';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
}
report obsolete;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt expired backup;
list backup summary;
exit;
EOF
【注意:控制文件一定要最后备份,由于没做归档目录数据库,rman备份信息都放在控制文件里面,要保证备份过程的信息内容都进入到控制文件,保证数据文件和控制文件是一致备份】
分别列出参数文件备份,控制文件备份,数据文件备份,以及归档备份的名字:
a.参数文件备份如下:
RMAN> list backup of spfile;
using target database control file instead of recovery catalog
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
51 Full 9.36M DISK 00:00:00 25-JAN-24
BP Key: 51 Status: AVAILABLE Compressed: NO Tag: TAG20240125T180503
Piece Name: /topsoft/rmanbak/autobackup/c-2492862311-20240125-06
SPFILE Included: Modification time: 25-JAN-24
SPFILE db_unique_name: dxj
b.控制文件备份如下:
RMAN> list backup of controlfile;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
51 Full 9.36M DISK 00:00:00 25-JAN-24
BP Key: 51 Status: AVAILABLE Compressed: NO Tag: TAG20240125T180503
Piece Name: /topsoft/rmanbak/autobackup/c-2492862311-20240125-06
Control File Included: Ckp SCN: 2895135 Ckp time: 25-JAN-24
c.数据文件备份如下:
RMAN> list backup of database;
d.列出归档备份如下:
RMAN> list backup of archivelog all;
备份参数文件
create pfile='/home/oracle/initdxj20240529.ora' from spfile;
备份密码文件
密码文件位置:$ORACLE_HOME/dbs
cp /u01/app/oracle/product/11.2.0/db/dbs/orapwdxj /home/oracle/
将rman备份文件、参数文件和密码文件copy至目标机器
如果端口不是默认的22,需加-P port_value
--拷贝rman备份文件
scp -r /data/rman_bak/autobackup oracle@192.168.40.200:/home/oracle/
--拷贝参数文件
scp /home/oracle/initdxj20240529.ora oracle@192.168.40.200:/home/oracle/
--拷贝密码文件
scp /home/oracle/orapwdxj oracle@192.168.40.200:/home/oracle/
目标数据库服务器
在RAC的orcl01机器上进行单机数据库的恢复
如果目标服务器已经新创建了dxj实例,需使用以下命令进行删除,删除后再进行如下恢复操作。
这里需要注意下,RAC和单点的静默删除实例命令是有区别的。
注意事项:
(1)RMAN 异机恢复的db_name 必须和备份的一致,如果说想改成其他名称,可以等还原之后,在用nid 命令修改。
(2)控制文件需要指定到共享设备上
(3)检查audit_file_dest,background_dump_dest, core_dump_dest,log_archive_dest_1,user_dump_dest等参数的位置。 如果2个节点和共享位置没有对应的目录,先把目录建好。
--RAC静默删除实例
dbca -silent -deleteDatabase -sourceDB dxj -nodeinfo orcl01,orcl02
--单点静默删除实例
dbca -silent -deleteDatabase -sourcedb dxj \
-sid dxj
修改参数文件
如果源服务器和目标服务器安装目录和数据目录都相同,该步骤可忽略。不然按如下步骤更改。
修改目录
参数文件中
.audit_file_dest为$ORACLE_BASE目录/admin/dxj/adump
.control_files中control01.ctl 和control02.ctl 路径为+DATA/dxj/
.db_recovery_file_dest为+DATA
.diagnostic_dest为$ORACLE_BASE目录
--备份已备份的参数文件,避免改的有问题重新从源库服务器传输到目标库服务器
cd /home/oracle
cp initdxj20240529.ora initdxj20240529.ora_bak
--更改参数文件中的oracle_base目录为目标库的oracle_base目录 控制文件路径等路径
vi /home/oracle/initdxj20240529.ora
语法说明:
:%s#源目录#新目录#g
修改内存相关参数
如果源服务器和目标服务器配置都相同,该步骤可忽略。不然按如下步骤更改。
由于目标服务器32G和源服务器内存128G差异大,需要更改内存参数。
内存参数修改公式:
--sga和pga配置的最佳实践
对于OLTP系统来说,oracle建议是sga=系统内存*0.8*0.8 单位字节
pga=系统内存*0.8*0.2
对于DSS系统来说,oracle建议是sga=系统内存*0.8*0.5 单位字节
pga=系统内存*0.8*0.5
修改版本兼容性参数
*.compatible='11.2.0.0.0'
更改为
*.compatible='11.2.0.4.0'
pfile的参数文件中*.compatible='11.2.0.0.0'一定要更改为目标端数据库版本*.compatible='11.2.0.4.0',不然后面通过pfile生成spfile文件会提示磁盘不存在或未挂载。该步骤在单点11.2.0.3向单点11.2.0.4备份恢复场景中不执行也没事,单点11.2.0.3向集群11.2.0.4备份恢复场景中务必要执行该步骤。
去掉参数
dxj.__db_cache_size=2113929216
dxj.__java_pool_size=16777216
dxj.__large_pool_size=16777216
dxj.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
dxj.__pga_aggregate_target=671088640
dxj.__sga_target=2650800128
dxj.__shared_io_pool_size=0
dxj.__shared_pool_size=486539264
dxj.__streams_pool_size=0
*.undo_tablespace='UNDOTBS1'
增加参数
*.cluster_database=false
要先设置为flase,才能进行RMAN 恢复操作。恢复完成在改成true。
*.undo_management='AUTO'
*.cluster_database_instances=2
*.cluster_database=false
dxj2.thread=2
dxj1.thread=1
dxj2.undo_tablespace='UNDOTBS2'
dxj1.undo_tablespace='UNDOTBS1'
dxj2.instance_number=2
dxj1.instance_number=1
最终更改后的参数文件
[oracle@orcl01:/home/oracle]$ cat initdxj20240529.ora
*._b_tree_bitmap_plans=FALSE
*._cleanup_rollback_entries=2000
*._datafile_write_errors_crash_instance=FALSE
*._index_partition_large_extents='FALSE'
*._memory_imm_mode_without_autosga=FALSE
*._optimizer_adaptive_cursor_sharing=FALSE
*._optimizer_extended_cursor_sharing='NONE'
*._optimizer_extended_cursor_sharing_rel='NONE'
*._optimizer_null_aware_antijoin=FALSE
*._optimizer_use_feedback=FALSE
*._partition_large_extents='FALSE'
*._PX_use_large_pool=TRUE
*._undo_autotune=FALSE
*._use_adaptive_log_file_sync='FALSE'
*.audit_file_dest='/u01/app/oracle/admin/dxj/adump'
*.audit_trail='NONE'
*.compatible='11.2.0.4.0'
*.control_file_record_keep_time=31
*.control_files='+DATA/dxj/control01.ctl','+DATA/dxj/control02.ctl'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_files=5000
*.db_name='dxj'
*.db_recovery_file_dest='+DATA'
*.db_recovery_file_dest_size=4322230272
*.deferred_segment_creation=FALSE
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=dxjXDB)'
*.enable_ddl_logging=TRUE
*.event='28401 trace name context forever,level 1','10949 trace name context forever,level 1'
*.log_archive_dest_1='location=+ARCH/dxj'
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=1000
*.parallel_max_servers=64
*.pga_aggregate_target=659554304
*.processes=2000
*.remote_login_passwordfile='EXCLUSIVE'
*.resource_limit=TRUE
*.resource_manager_plan='force:'
*.sec_case_sensitive_logon=FALSE
*.session_cached_cursors=300
*.sga_max_size=2638217216
*.sga_target=2638217216
*.undo_retention=10800
*.undo_management='AUTO'
*.cluster_database_instances=2
*.cluster_database=false
dxj2.thread=2
dxj1.thread=1
dxj2.undo_tablespace='UNDOTBS2'
dxj1.undo_tablespace='UNDOTBS1'
dxj2.instance_number=2
dxj1.instance_number=1
目标服务器上创建相应的目录
ORACLE_BASE目录不要创建,因为数据库软件已安装。源库和目标库ORACLE_BASE目录不同采用更改目标库参数文件中ORACLE_BASE目录的方法。
窗口1:在ASM共享磁盘DATA盘中建立+DATA/dxj目录
--在ASM中建立+DATA/DXJ目录
su - grid
asmcmd
cd DATA
mkdir DXJ
--在ASM中建立+ARCH/DXJ目录
su - grid
asmcmd
cd ARCH
mkdir DXJ
窗口2:查看参数文件
cat /home/oracle/initdxj20240529.ora
窗口3:创建参数文件中的目录
--所有节点都操作
mkdir -p /u01/app/oracle/admin/dxj/adump
通过pfile文件将数据库启动到nomount状态
[oracle@orcl01:/home/oracle]$ export ORACLE_SID=dxj1
[oracle@orcl01:/home/oracle]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Fri Dec 12 20:39:56 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount pfile='/home/oracle/initdxj20240529.ora';
用pfile生成spfile文件(勿忘记)
用修改的pfile 来创建spfile,注意放在共享设备上
数据库中用pfile生成spfile文件
--数据库中用pfile生成spfile文件
SQL> create spfile='+DATA/DXJ/spfiledxj.ora' from pfile='/home/oracle/initdxj20240529.ora';
所有节点本地生成spfilesid.ora文件的映射文件initsid.ora
本地生成spfilesid.ora文件的映射文件initsid.ora 该步骤必须操作不然再次启库还是pfile方式启库的
--节点1
[oracle@orcl01:/home/oracle]$ cd $ORACLE_HOME/dbs
[oracle@orcl01:/u01/app/oracle/product/11.2.0/db/dbs]$
echo "SPFILE='+DATA/DXJ/spfiledxj.ora'" > initdxj1.ora
--节点2
[oracle@orcl02:/home/oracle]$ cd $ORACLE_HOME/dbs
[oracle@orcl02:/u01/app/oracle/product/11.2.0/db/dbs]$ cat initdxj2.ora
echo "SPFILE='+DATA/DXJ/spfiledxj.ora'" > initdxj2.ora
重启库至nomount
--重启库至nomount
SQL> shutdown abort;
SQL> startup nomount; --启动到nomount状态
ORACLE instance started.
Total System Global Area 2638954496 bytes
Fixed Size 2256152 bytes
Variable Size 1258291944 bytes
Database Buffers 1375731712 bytes
Redo Buffers 2674688 bytes
验证启库是通过spfile文件方式
--验证启库是通过spfile文件方式
SQL> set linesize 999
SQL> show parameter pfile;
NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
spfile string +DATA/dxj/spfiledxj.ora
问题处理
通过pfile生成spfile失败,提示DATA磁盘不存在ORA-15204&ORA-15001&ORA-17502
--问题描述
通过pfile生成spfile失败,提示DATA磁盘不存在
SQL> create spfile='+DATA/DXJ/spfiledxj.ora' from pfile='/home/oracle/initdxj20240529.ora';
create spfile='+DATA/DXJ/spfiledxj.ora' from pfile='/home/oracle/initdxj20240529.ora'
*
ERROR at line 1:
ORA-17502: ksfdcre:4 Failed to create file +DATA/DXJ/spfiledxj.ora
ORA-15001: diskgroup "DATA" does not exist or is not mounted
ORA-15204: database version 11.2.0.0.0 is incompatible with diskgroup DATA
--分析过程
查看磁盘状态 data磁盘状态时mounted,说明没问题
su - grid
sqlplus / as sysdba
SQL> col name for a30
SQL> select name,state from v$asm_diskgroup;
NAME STATE
------------------------------ ---------------------------------
ARCH MOUNTED
DATA MOUNTED
OCR MOUNTED
查看集群状态
[grid@orcl01:/home/grid]$ crsctl stat res -t
--------------------------------------------------------------------------------
NAME TARGET STATE SERVER STATE_DETAILS
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.ARCH.dg
ONLINE ONLINE orcl01
ONLINE ONLINE orcl02
ora.DATA.dg
ONLINE ONLINE orcl01
ONLINE ONLINE orcl02
ora.LISTENER.lsnr
ONLINE ONLINE orcl01
ONLINE ONLINE orcl02
ora.OCR.dg
ONLINE ONLINE orcl01
ONLINE ONLINE orcl02
ora.asm
ONLINE ONLINE orcl01 Started
ONLINE ONLINE orcl02 Started
......
查看oracle文件权限 权限也对
[grid@orcl01:/u01/app/11.2.0/grid/bin]$ ls -l $ORACLE_HOME/bin/oracle
-rwsr-s--x. 1 grid oinstall 209840352 Aug 18 2023 /u01/app/11.2.0/grid/bin/oracle
查看oracle用户信息 oracle用户组也对
[oracle@orcl01:/home/oracle]$ id oracle
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper),54324(backupdba),54325(dgdba),54326(kmdba),54330(racdba),54327(asmdba),54328(asmoper),54329(asmadmin)
查看参数文件
[oracle@orcl01:/home/oracle]$ cat initdxj20240529.ora
......
*.compatible='11.2.0.0.0'
......
--解决办法
将参数文件/home/oracle/initdxj20240529.ora中*.compatible='11.2.0.0.0'改成*.compatible='11.2.0.4.0'
重启库解决
su - oracle
sqlplus / as sysdba
shutdown abort
startup nomount pfile='/home/oracle/initdxj20240529.ora';
create spfile='+DATA/DXJ/spfiledxj.ora' from pfile='/home/oracle/initdxj20240529.ora';
成功
创建密码文件
在所有节点执行,注意密码要和原库一样
--节点1
[oracle@orcl01:/home/oracle]$ orapwd file=?/dbs/orapwdxj1 password=oracle
--节点2
[oracle@orcl02:/home/oracle]$ orapwd file=?/dbs/orapwdxj2 password=oracle
恢复控制文件
源库和目标库的控制文件路径虽然不一样,但是在更改参数文件的参数文件位置后,恢复控制文件过程中会把控制文件恢复到已更改的参数文件指定的控制文件路径。
[oracle@orcl01:/home/oracle]$ export ORACLE_SID=dxj1
[oracle@orcl01:/home/oracle]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Wed May 29 15:47:04 2024
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: DXJ (not mounted)
RMAN> restore controlfile from '/home/oracle/autobackup/emrdb_ctl_bk_092rrir9_1_1_DXJ_20240527';
Starting restore at 29-MAY-24
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=30 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=+DATA/dxj/control01.ctl
output file name=+DATA/dxj/control02.ctl
Finished restore at 29-MAY-24
--启库到mount状态
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
恢复数据文件
由于RAC下使用的是OMF路径,所以先用脚本查询出源库中的数据文件名以及路径
sqlplus 执行
数据文件的转换,由于目标 rac 库是 asm 存储的,所以到新环境需要采用 set newname 来转换一下
可通过RMAN重命名数据文件、临时文件、日志文件,进行还原
补充:catalog的原理是查文件头,里面 文件号 相对文件号 scn,目的就是把信息取出来,写到ctl的rman那一部分,就是建个档 不明白
生成数据文件转换脚本
源库中执行
--数据文件转换脚本
set pagesize 200 linesize 200
select 'set newname for datafile ' || a.FILE# || ' to "' || '+DATA' || '";'
from v$datafile a
union all
select 'set newname for tempfile ' || a.FILE# || ' to "' || '+DATA' || '";'
from v$tempfile a
union all
SELECT 'SQL "ALTER DATABASE RENAME FILE ''''' || a.MEMBER || ''''' to ''''' ||
'+DATA' || ''''' ";'
FROM v$logfile a;
--输出结果
'SETNEWNAMEFORDATAFILE'||FILE_ID||'TO'''||'+DATA'||''';'
-----------------------------------------------------------------------------
set newname for datafile 4 to '+DATA';
set newname for datafile 3 to '+DATA';
set newname for datafile 2 to '+DATA';
set newname for datafile 1 to '+DATA';
set newname for datafile 5 to '+DATA';
set newname for datafile 6 to '+DATA';
6 rows selected.
--日志文件转换脚本
select 'set newname for tempfile '||file_id||' to '''||'+DATA'||''';' from dba_temp_files;
输出结果
'SETNEWNAMEFORTEMPFILE'||FILE_ID||'TO'''||'+DATA'||''';'
-----------------------------------------------------------------------------
set newname for tempfile 1 to '+DATA';
还原数据文件
加载备份目录下的备份集
--加载备份目录下的备份集
[oracle@orcl01:/home/oracle]$ export ORACLE_SID=dxj1
[oracle@orcl01:/home/oracle]$ rman target /
RMAN> catalog start with '/home/oracle/autobackup/';
searching for all files that match the pattern /home/oracle/autobackup/
List of Files Unknown to the Database
=====================================
File Name: /home/oracle/autobackup/emrdb_full_022rripo_1_1_DXJ_20240527_2
File Name: /home/oracle/autobackup/emrdb_full_012rripo_1_1_DXJ_20240527_1
File Name: /home/oracle/autobackup/emrdb_full_032rripo_1_1_DXJ_20240527_3
File Name: /home/oracle/autobackup/emrdb_full_042rripo_1_1_DXJ_20240527_4
File Name: /home/oracle/autobackup/emrdb_full_052rripr_1_1_DXJ_20240527_5
File Name: /home/oracle/autobackup/emrdb_arc_062rrir8_1_1_DXJ_20240527_6
File Name: /home/oracle/autobackup/emrdb_arc_072rrir8_1_1_DXJ_20240527_7
File Name: /home/oracle/autobackup/emrdb_arc_082rrir8_1_1_DXJ_20240527_8
File Name: /home/oracle/autobackup/emrdb_ctl_bk_092rrir9_1_1_DXJ_20240527
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /home/oracle/autobackup/emrdb_full_022rripo_1_1_DXJ_20240527_2
File Name: /home/oracle/autobackup/emrdb_full_012rripo_1_1_DXJ_20240527_1
File Name: /home/oracle/autobackup/emrdb_full_032rripo_1_1_DXJ_20240527_3
File Name: /home/oracle/autobackup/emrdb_full_042rripo_1_1_DXJ_20240527_4
File Name: /home/oracle/autobackup/emrdb_full_052rripr_1_1_DXJ_20240527_5
File Name: /home/oracle/autobackup/emrdb_arc_062rrir8_1_1_DXJ_20240527_6
File Name: /home/oracle/autobackup/emrdb_arc_072rrir8_1_1_DXJ_20240527_7
File Name: /home/oracle/autobackup/emrdb_arc_082rrir8_1_1_DXJ_20240527_8
File Name: /home/oracle/autobackup/emrdb_ctl_bk_092rrir9_1_1_DXJ_20240527
更改控制文件中数据文件和临时文件的名称并还原数据库
注意,对switch的说明:
对于nocatalog 模式下,rman备份的信息是保存在控制文件里的,包括文件的路径信息。 这里的switch的作用,就是更新控制文件里的信息。
restore 的时候不会对temp 表空间进行restore。所以等restore 之后,我们需要手工创建temp表空间。
不过在这个测试里,我们还是对tempfile 进行了指定。 但是这个操作只更新控制文件,不恢复数据文件。
--更改控制文件中数据文件和临时文件的名称,还原数据库
RMAN>
run {
set newname for datafile 4 to '+DATA';
set newname for datafile 3 to '+DATA';
set newname for datafile 2 to '+DATA';
set newname for datafile 1 to '+DATA';
set newname for datafile 5 to '+DATA';
set newname for datafile 6 to '+DATA';
set newname for tempfile 1 to '+DATA';
restore database;
switch datafile all;
switch tempfile all;
}
详细过程如下:
RMAN>
run {
set newname for datafile 4 to '+DATA';
set newname for datafile 3 to '+DATA';
set newname for datafile 2 to '+DATA';
set newname for datafile 1 to '+DATA';
set newname for datafile 5 to '+DATA';
set newname for datafile 6 to '+DATA';
set newname for tempfile 1 to '+DATA';
restore database;
switch datafile all;
switch tempfile all;
10> 11> 12> }
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 29-MAY-24
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 00003 to +DATA
channel ORA_DISK_1: restoring datafile 00005 to +DATA
channel ORA_DISK_1: reading from backup piece /home/oracle/autobackup/emrdb_full_032rripo_1_1_DXJ_20240527_3
channel ORA_DISK_1: piece handle=/home/oracle/autobackup/emrdb_full_032rripo_1_1_DXJ_20240527_3 tag=TAG20240527T102352
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
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 00002 to +DATA
channel ORA_DISK_1: restoring datafile 00006 to +DATA
channel ORA_DISK_1: reading from backup piece /home/oracle/autobackup/emrdb_full_022rripo_1_1_DXJ_20240527_2
channel ORA_DISK_1: piece handle=/home/oracle/autobackup/emrdb_full_022rripo_1_1_DXJ_20240527_2 tag=TAG20240527T102352
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
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 +DATA
channel ORA_DISK_1: restoring datafile 00004 to +DATA
channel ORA_DISK_1: reading from backup piece /home/oracle/autobackup/emrdb_full_012rripo_1_1_DXJ_20240527_1
channel ORA_DISK_1: piece handle=/home/oracle/autobackup/emrdb_full_012rripo_1_1_DXJ_20240527_1 tag=TAG20240527T102352
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 29-MAY-24
datafile 1 switched to datafile copy
input datafile copy RECID=7 STAMP=1170261654 file name=+DATA/dxj/datafile/system.266.1170261619
datafile 2 switched to datafile copy
input datafile copy RECID=8 STAMP=1170261654 file name=+DATA/dxj/datafile/sysaux.270.1170261603
datafile 3 switched to datafile copy
input datafile copy RECID=9 STAMP=1170261654 file name=+DATA/dxj/datafile/undotbs1.272.1170261601
datafile 4 switched to datafile copy
input datafile copy RECID=10 STAMP=1170261654 file name=+DATA/dxj/datafile/users.265.1170261619
datafile 5 switched to datafile copy
input datafile copy RECID=11 STAMP=1170261654 file name=+DATA/dxj/datafile/fuwa.274.1170261601
datafile 6 switched to datafile copy
input datafile copy RECID=12 STAMP=1170261654 file name=+DATA/dxj/datafile/top.263.1170261605
renamed tempfile 1 to +DATA in control file
recover 数据库
在执行restore的节点执行,因为备份文件在该节点上。
RMAN> recover database;
详细过程如下:
RMAN> recover database;
Starting recover at 29-MAY-24
using channel ORA_DISK_1
starting media recovery
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=7
channel ORA_DISK_1: reading from backup piece /home/oracle/autobackup/emrdb_arc_072rrir8_1_1_DXJ_20240527_7
channel ORA_DISK_1: piece handle=/home/oracle/autobackup/emrdb_arc_072rrir8_1_1_DXJ_20240527_7 tag=TAG20240527T102440
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=+ARCH/dxj/1_7_1170009408.dbf thread=1 sequence=7
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=8
channel ORA_DISK_1: reading from backup piece /home/oracle/autobackup/emrdb_arc_082rrir8_1_1_DXJ_20240527_8
channel ORA_DISK_1: piece handle=/home/oracle/autobackup/emrdb_arc_082rrir8_1_1_DXJ_20240527_8 tag=TAG20240527T102440
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=+ARCH/dxj/1_8_1170009408.dbf thread=1 sequence=8
unable to find archived log
archived log thread=1 sequence=9
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 05/29/2024 16:48:36
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 9 and starting SCN of 1079971
这里是提醒恢复到一个未知的scn号。 因为这部分SCN 还在online redo里,可以在alter database mount之后,通过set until scn或者set until time命令设置恢复到的scn号或时间,
--在RAC的orcl01机器上recover数据库到最后一个归档日志的sequence+1
RMAN> recover database until sequence 9;
或者把源库的这些文件在copy过来,在应用一下。就可以避免这个错误。
--将源库剩下的归档拷贝到新集群节点1上
[oracle@dxj:/home/oracle]$ scp -r /oradata/archivelog oracle@192.168.40.200:/home/oracle/
--将源库的online redo 拷贝到新集群节点1上
[oracle@dxj:/oradata/dxj]$ scp /oradata/dxj/redo* oracle@192.168.40.200:/home/oracle/
重新注册归档文件和online redo log,并同步数据
注册归档文件
如果有归档,需要从单机复制到RAC 节点上,但RAC节点的数据库并没有相关记录。所以需要先将归档文件注册到控制文件里。 然后才能使用。
RMAN> catalog archivelog '/home/oracle/archivelog/1_10_1170009408.dbf' ,'/home/oracle/archivelog/1_11_1170009408.dbf' ,'/home/oracle/archivelog/1_12_1170009408.dbf' ,'/home/oracle/archivelog/1_13_1170009408.dbf' ,'/home/oracle/archivelog/1_5_1170009408.dbf' ,'/home/oracle/archivelog/1_6_1170009408.dbf' ,'/home/oracle/archivelog/1_7_1170009408.dbf' ,'/home/oracle/archivelog/1_8_1170009408.dbf' ,'/home/oracle/archivelog/1_9_1170009408.dbf','/home/oracle/archivelog/1_14_1170009408.dbf';
详细过程如下:
RMAN> catalog archivelog '/home/oracle/archivelog/1_10_1170009408.dbf' ,'/home/oracle/archivelog/1_11_1170009408.dbf' ,'/home/oracle/archivelog/1_12_1170009408.dbf' ,'/home/oracle/archivelog/1_13_1170009408.dbf' ,'/home/oracle/archivelog/1_5_1170009408.dbf' ,'/home/oracle/archivelog/1_6_1170009408.dbf' ,'/home/oracle/archivelog/1_7_1170009408.dbf' ,'/home/oracle/archivelog/1_8_1170009408.dbf' ,'/home/oracle/archivelog/1_9_1170009408.dbf';
cataloged archived log
archived log file name=/home/oracle/archivelog/1_10_1170009408.dbf RECID=7 STAMP=1170263152
cataloged archived log
archived log file name=/home/oracle/archivelog/1_11_1170009408.dbf RECID=8 STAMP=1170263152
cataloged archived log
archived log file name=/home/oracle/archivelog/1_12_1170009408.dbf RECID=9 STAMP=1170263152
cataloged archived log
archived log file name=/home/oracle/archivelog/1_13_1170009408.dbf RECID=10 STAMP=1170263152
cataloged archived log
archived log file name=/home/oracle/archivelog/1_5_1170009408.dbf RECID=11 STAMP=1170263152
cataloged archived log
archived log file name=/home/oracle/archivelog/1_6_1170009408.dbf RECID=12 STAMP=1170263152
cataloged archived log
archived log file name=/home/oracle/archivelog/1_7_1170009408.dbf RECID=13 STAMP=1170263152
cataloged archived log
archived log file name=/home/oracle/archivelog/1_8_1170009408.dbf RECID=14 STAMP=1170263152
cataloged archived log
archived log file name=/home/oracle/archivelog/1_9_1170009408.dbf RECID=15 STAMP=1170263152
移动online redo log到对应位置
--源库切换日志
idle 29-MAY-24> alter system checkpoint;
idle 29-MAY-24> alter system switch logfile;
System altered.
--查看源库redo log位置
sys@DXJ 2024-01-25 17:22:52> set linesize 999
sys@DXJ 2024-01-25 17:23:55> col member for a70
sys@DXJ 2024-01-25 17:24:05> select * from v$logfile;
3 ONLINE /oradata/dxj/redo03.log NO
2 ONLINE /oradata/dxj/redo02.log NO
1 ONLINE /oradata/dxj/redo01.log NO
idle 29-MAY-24> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
--在RAC上把online redo log日志放入到对应的位置(目录位置必须还原来单实例目录一致)
mkdir -p /oradata/dxj/
mv /home/oracle/redo*.log /oradata/dxj/
再次执行recover 操作
RMAN> recover database;
详细过程:
RMAN> recover database;
Starting recover at 29-MAY-24
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=29 device type=DISK
starting media recovery
archived log for thread 1 with sequence 14 is already on disk as file /oradata/dxj/redo02.log
archived log for thread 1 with sequence 15 is already on disk as file /oradata/dxj/redo03.log
archived log file name=/oradata/dxj/redo02.log thread=1 sequence=14
archived log file name=/oradata/dxj/redo03.log thread=1 sequence=15
media recovery complete, elapsed time: 00:00:00
Finished recover at 29-MAY-24
注意:这次是第二次进行recover database,这里会copy过来的日志全部应用了,并且,注意这里是完全恢复,也就说这里没有数据丢失,不需要用open resetlogs来打开数据库。
重置归档位置
如果在参数文件中已设置正确,该步骤可忽略
SQL> alter system set log_archive_dest_1='LOCATION=+ARCH' SID='*';
处理online redo
RAC的redo是需要存放在共享设备上的,所以这里需要进行一些转换操作:把单机的在线日志路径修改为ASM路径。
--生成online redo转换脚本
SELECT 'SQL "ALTER DATABASE RENAME FILE ''''' || a.MEMBER || ''''' to ''''' ||
'+DATA' || ''''' ";'
FROM v$logfile a;
'SQL"ALTERDATABASERENAMEFILE'''''||A.MEMBER||'''''TO'''''||'+DATA'||'''''";'
--------------------------------------------------------------------------------
SQL "ALTER DATABASE RENAME FILE ''/oradata/dxj/redo03.log'' to ''+DATA'' ";
SQL "ALTER DATABASE RENAME FILE ''/oradata/dxj/redo02.log'' to ''+DATA'' ";
SQL "ALTER DATABASE RENAME FILE ''/oradata/dxj/redo01.log'' to ''+DATA'' ";
--rman中执行上面输出的语句
这里只是更改了online redo的记录,实际上文件并没有生成,当open db的时候,会自动创建online redo log。
RESETLOGS打开数据库
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01092: ORACLE instance terminated. Disconnection forced
ORA-00704: bootstrap process failure
ORA-39700: database must be opened with UPGRADE option
Process ID: 28383
Session ID: 32 Serial number: 53
解决办法:
目标库重新登陆按如下执行(执行catupgrd.sql完后实例会自动shutdown,之后直接startup的过程不再需要resetlogs了)。不要多窗口并行执行脚本,会引发死锁,该过程比较耗时。
export ORACLE_SID=dxj1
sqlplus / as sysdba
sql>startup upgrade;
执行脚本
不要多窗口并行执行脚本,会引发死锁,该过程比较耗时。
sql>@?/rdbms/admin/catalog.sql --这个脚本执行很快就结束了
sql>@?/rdbms/admin/catproc.sql --这个脚本执行大概3-5分钟
sql>@?/rdbms/admin/catupgrd.sql --这个脚本执行时间比较久,脚本执行结束会shutdown immediate;
脚本说明:
主要用于创建数据字典视图。其中,脚本catalog.sql 和 catproc.sql 是创建数据库后必须要运行的两个脚本。
catalog.sql 创建系统常用的数据字典视图和同义词
catproc.sql 运行服务器端所需要的PL/SQL脚本
(1) catalog.sql
该脚本创建相对于系统基表的视图和系统动态性能视图以及他们的同义词。该脚本又同时运行创建其他对象的脚本,主要有:
基本PL/SQL环境,包括PL/SQL的声明:
- 数据类型
- 预定义例外
- 内建的过程和函数
- SQL操作等
- 审计
- 导入/导出
- SQL*Loader
- 安装选项
(2)catproc.sql
该脚本主要用于建立PL/SQL功能的使用环境。此外,还创建几个PL/SQL包用于扩展RDBMS功能。该脚本同时还为下面的一些RDBMS功能创建另外的一些包和视图:
-警告(Alerts)
-管道(Pipes)
-日志分析(LogMiner)
-大对象(Large objects)
-对象(Objects)
- 高级队列(Advanced queuing)
-复制选项( Replication option)
-其他的一些内建包和选项(Other built-ins and options)
(3) catupgrd.sql
随着Oracle版本的升级,某些对象的属性需要改变,而这些改变操作都将体现在升级脚本catupgrd.sql中
启库
idle 29-MAY-24> startup
ORACLE instance started.
Total System Global Area 2638954496 bytes
Fixed Size 2256152 bytes
Variable Size 1476395752 bytes
Database Buffers 1157627904 bytes
Redo Buffers 2674688 bytes
Database mounted.
Database opened.
查看版本
idle 29-MAY-24> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
数据量查看
--查看数据库
SQL> select sum(bytes)/1024/1024/1024 as "size(G)" from dba_data_files;
size(G)
----------
1.87988281 比原来大
--查看总大小
select round(sum(bytes) / 1024 / 1024 / 1024, 2) || 'G'
from dba_segments;
ROUND(SUM(BYTES)/1024/1024/1024,2)||'G'
-----------------------------------------
1.83G
--每个业务用户下的总对象数量校验
SELECT D.OWNER,COUNT(1)
FROM dba_objects d
WHERE d.OWNER in ('FUWA')
AND NOT EXISTS (SELECT 1 FROM DBA_RECYCLEBIN B WHERE B.object_name=D.OBJECT_NAME AND D.OWNER=B.owner)
GROUP BY D.OWNER
ORDER BY D.OWNER ;
OWNER COUNT(1)
------------------------------ ----------
FUWA 1
--每个业务用户下的各个对象类别的数量校验
SQL> select OWNER,OBJECT_TYPE,status,count(OBJECT_NAME) from dba_objects where owner in ('FUWA') group by OBJECT_TYPE,owner,status order by 1,3,2;
OWNER OBJECT_TYPE STATUS COUNT(OBJECT_NAME)
------------------------------ ------------------- ------- ------------------
FUWA TABLE VALID 1
数据库配置更改
修改参数
--在RAC的orcl01机器上修改参数,修改数据库的实例数目,为每个实例命名,并使每个实例拥有独立的thread
alter system set cluster_database=true scope=spfile;
alter system set cluster_database_instances=2 scope=spfile;
alter system set instance_number=1 scope=spfile sid='dxj1';
alter system set instance_number=2 scope=spfile sid='dxj2';
alter system set thread=1 scope=spfile sid='dxj1';
alter system set thread=2 scope=spfile sid='dxj2';
--在RAC的orcl01机器上启动第二个thread
alter database enable thread 2;
undo tablespace
在RAC的orcl01机器上修改参数,使每个实例有独立的undo tablespace
--查看undo tablespace,保证只有一个undo tablespace
show parameter undo
--在RAC的orcl01机器上创建第二个undo tablespace
create undo tablespace undotbs2 datafile '+DATA' size 512m autoextend on maxsize unlimited;
--在RAC的orcl01机器上修改参数,使每个实例有独立的undo tablespace
alter system set undo_tablespace='undotbs1' scope=spfile sid='dxj1';
alter system set undo_tablespace='undotbs2' scope=spfile sid='dxj2';
创建在线日志组
在RAC的orcl01机器上为第二个thread创建在线日志组,开了闪回区后,默认1个日志组会有2个日志成员,闪回区一个,数据目录一个。
--查看日志文件:
--查看redo log大小和位置
set linesize 999
col member for a60
select b.thread#,a.group#,a.member,bytes/1024/1024,b.members,b.status from v$logfile a,v$log b where a.group#=b.group#;
--第二个thread创建在线日志组
alter database add logfile thread 2 group 4 ('+DATA','+DATA') size 50m;
alter database add logfile thread 2 group 5 ('+DATA','+DATA') size 50m;
alter database add logfile thread 2 group 6 ('+DATA','+DATA') size 50m;
检查归档路径是否在ASM中
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination +ARCH
Oldest online log sequence 48
Next log sequence to archive 50
Current log sequence 50
关闭节点1数据库
export ORACLE_SID=dxj1
sqlplus / as sysdba
shutdown immediate
启动所有节点实例
在RAC的所有机器即orcl01、orcl02上都启动数据库,并在每台机器上检查是否能够查询到所有实例信息
--orcl01启动数据库 发现每台机器上都能够查询到所有实例信息 最后再关闭
export ORACLE_SID=dxj1
sqlplus / as sysdba
SQL> set linesize 999
SQL> select status,instance_number,instance_name,host_name from gv$instance;
STATUS INSTANCE_NUMBER INSTANCE_NAME HOST_NAME
------------ --------------- ---------------- ----------------------------------------------------------------
OPEN 1 dxj1 orcl01
OPEN 2 dxj2 orcl02
SQL> shutdown immediate
--orcl02启动数据库 发现每台机器上都能够查询到所有实例信息 最后再关闭
export ORACLE_SID=dxj2
sqlplus / as sysdba
SQL> set linesize 999
SQL> select status,instance_number,instance_name,host_name from gv$instance;
STATUS INSTANCE_NUMBER INSTANCE_NAME HOST_NAME
------------ --------------- ---------------- ----------------------------------------------------------------
OPEN 1 dxj1 orcl01
OPEN 2 dxj2 orcl02
SQL> shutdown immediate
把数据库加入集群
在RAC的随机一台机器如orcl01机器上把数据库加入集群(grid或oracle用户都可以)
srvctl add database -d dxj -o $ORACLE_HOME -p +DATA/dxj/spfiledxj.ora
srvctl add instance -d dxj -i dxj1 -n orcl01
srvctl add instance -d dxj -i dxj2 -n orcl02
srvctl start database -d dxj
如下输出:
[oracle@orcl01:/home/oracle]$ srvctl start database -d dxj
[oracle@orcl01:/home/oracle]$ srvctl status database -d dxj
Instance dxj1 is running on node orcl01
Instance dxj2 is running on node orcl02
查看集群状态
[grid@orcl02:/home/grid]$ crsctl stat res -t
--------------------------------------------------------------------------------
NAME TARGET STATE SERVER STATE_DETAILS
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.ARCH.dg
ONLINE ONLINE orcl01
ONLINE ONLINE orcl02
ora.DATA.dg
ONLINE ONLINE orcl01
ONLINE ONLINE orcl02
ora.LISTENER.lsnr
ONLINE ONLINE orcl01
ONLINE ONLINE orcl02
ora.OCR.dg
ONLINE ONLINE orcl01
ONLINE ONLINE orcl02
ora.asm
ONLINE ONLINE orcl01 Started
ONLINE ONLINE orcl02 Started
ora.gsd
OFFLINE OFFLINE orcl01
OFFLINE OFFLINE orcl02
ora.net1.network
ONLINE ONLINE orcl01
ONLINE ONLINE orcl02
ora.ons
ONLINE ONLINE orcl01
ONLINE ONLINE orcl02
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
1 ONLINE ONLINE orcl02
ora.cvu
1 ONLINE ONLINE orcl02
ora.dxj.db
1 ONLINE ONLINE orcl01 Open
2 ONLINE ONLINE orcl02 Open
ora.oc4j
1 ONLINE ONLINE orcl02
ora.orcl01.vip
1 ONLINE ONLINE orcl01
ora.orcl02.vip
1 ONLINE ONLINE orcl02
ora.scan1.vip
1 ONLINE ONLINE orcl02
重新配置初始化pfile
查看参数文件位置
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string +DATA/dxj/spfiledxj.ora
2个节点,重新配置初始化pfile
--节点1
echo "spfile='+DATA/dxj/spfiledxj.ora'" > /u01/app/oracle/product/11.2.0/db/dbs/initdxj1.ora
--节点2
echo "spfile='+DATA/dxj/spfiledxj.ora'" > /u01/app/oracle/product/11.2.0/db/dbs/initdxj2.ora
问题处理
本实验文档未出现以下报错,如果备份恢复中遇到以下报错可参考以下解决办法。
ORA-27102: out of memory
--问题描述
SQL> startup nomount pfile='/home/oracle/initdxj20240529.ora';
ORA-27102: out of memory
Linux-x86_64 Error: 28: No space left on device
Additional information: -939524096
Additional information: 1
--问题原因
由于目标服务器32G和源服务器内存128G差异大,需要更改内存参数。
参数文件中sga pga参数太大
--解决办法
--sga和pga配置的最佳实践
对于OLTP系统来说,oracle建议是sga=系统内存*0.8*0.8 单位字节
pga=系统内存*0.8*0.2
对于DSS系统来说,oracle建议是sga=系统内存*0.8*0.5 单位字节
pga=系统内存*0.8*0.5
更改参数文件中的关于内存的参数
recover database提示unable to find archived log
--问题描述
还原归档文件时间报错
RMAN> recover database;
Starting recover at 25-JAN-24
using channel ORA_DISK_1
starting media recovery
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=16
channel ORA_DISK_1: reading from backup piece /topsoft/newbak/autobackup/arch_dxj_20240125_1159207499_60_1.bak
channel ORA_DISK_1: piece handle=/topsoft/newbak/autobackup/arch_dxj_20240125_1159207499_60_1.bak tag=ARCH
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/topsoft/oracle/oradata/archivelog/1_16_1155666473.dbf thread=1 sequence=16
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=17
channel ORA_DISK_1: reading from backup piece /topsoft/newbak/autobackup/arch_dxj_20240125_1159207499_61_1.bak
channel ORA_DISK_1: piece handle=/topsoft/newbak/autobackup/arch_dxj_20240125_1159207499_61_1.bak tag=ARCH
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/topsoft/oracle/oradata/archivelog/1_17_1155666473.dbf thread=1 sequence=17
unable to find archived log
archived log thread=1 sequence=18
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 01/25/2024 19:54:41
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 18 and starting SCN of 2895113
--解决办法
--进行不完全恢复 归档序列号+1
RMAN> recover database until sequence 18;
Starting recover at 25-JAN-24
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=2271 device type=DISK
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 25-JAN-24
--恢复完成后,将库启动到read only模式,查询一下数据是否正常
SQL> alter database open read only;
Database altered.
--对比数据量无问题后
SQL> shutdown immediate;
--resetlogs方式打开
SQL> alter database open resetlogs;
Database altered.
--查看数据库状态
SQL> select status from v$instance;
STATUS
------------
OPEN
最后小版本升级完成,且数据验证无问题。
概念补充
完全恢复:数据文件+归档+在线redo,就能做实例恢复 这一级别就是完全恢复。ctl scn 、 datafile scn 、datafile head scn一致
不完全恢复:数据文件+归档 只能到 归档的最后一条redo,不能实例恢复 就是不完全恢复
restore 解决 datafile
recover 解决实例恢复
catalog就是把三者注册到 ctl ,自动完成
如果你只注册前两个部分,那么第三个部分就要手工指定
recover database until cancel时 把当前redo的路径写上就行了
最后会显示下一个redo sequence号,这个号其实是不存在的,因为还没产生,oracle是机器,它只会让你找最全的redo,向前恢复
--实例恢复
老备份+归档+在线redo=内存中的oracle
关机了 归档+在线全都不需要
在线redo的存在,解决数据文件和内存不一致
归档,解决老备份和现有数据文件不一致
--文件恢复
recover
restore
小版本升级参考链接:
oracle 单机 恢复 rac,单机11.2.0.1恢复到RAC 11.2.0.4的案例-CSDN博客