MGMTDB实际上就是一个SID为-MGMTDB的单节点、可插拔数据库。
因此,对MGMTDB的数据库实例迁移,实际上就是对一个单节点实例的迁移。我们常做的迁移,是从一个ASM磁盘组迁移到另一个磁盘组。以下为迁移的详细步骤:
1.检查当前的MGMTDB的状态
--查看磁盘组信息
$ asmcmd lsdg
--确认当前实例所在磁盘
select dg.name group_name,cli.instance_name,cli.db_name,cli.status
from v$asm_client cli
left join v$asm_diskgroup dg
on cli.group_number=dg.group_number;
--查看MGMTDB的运行状态和配置信息
$ srvctl status mgmtdb
$ srvctl config mgmtdb
$ srvctl status mgmtlsnr
2.备份实例,防止数据丢失
$ mkdir mgmtdb_bak
$ srvctl stop cha
$ srvctl stop MGMTDB
$ srvctl stop MGMTLSNR
--grid用户
$ export ORACLE_SID=-MGMTDB
$ rman target /
RMAN> startup mount
RMAN> backup database format '/home/grid/mgmtdb_bak/rman_mgmtdb_%U' tag='bk_mgmtdb_dg';
3.逐步迁移实例:spfile-->controlfile-->datafile
/*迁移spfile*/
RMAN> restore spfile to '+<NEW_DG>';
$ srvctl config mgmtdb |grep Spfile
--重启mgmtdb实例
RMAN> shutdown immediate
/*迁移controlfile*/
--登陆MGMTDB实例
$ sqlplus / as sysdba
SQL> startup nomount
--在实例中查看参数文件和控制文件的路径情况
SQL> show parameter spfile
SQL> show parameter controlfile --获取原控制文件路径 ctl_p1
SQL> alter system set control_files='+<NEW_DG>' scope=spfile;
SQL> shutdown immediate
--RMAN还原控制文件到新路径下
RMAN> start nomount
RMAN> restore controlfile from '<ctl_p1>';
RMAN> alter database mount;
/*迁移数据文件*/
RMAN> BACKUP AS COPY DEVICE TYPE DISK DATABASE FORMAT '+<NEW_DG>';
RMAN> switch database to copy;
RMAN> report schema;
--手动迁移临时文件
RMAN> run {
2> SET NEWNAME FOR TEMPFILE 1 TO '+<NEW_DG>';
3> SWITCH TEMPFILE ALL;
4> }
--手动迁移logfile
物理上mv logfile到新的路径下,然后sqlplus上rename logfile
或者:
select lf.group#,lf.member,lg.status from v$logfile lf, v$log lg where lf.GROUP#=lg.GROUP# order by 1;
--获得原logfile路径LG_P1
ALTER DATABASE ADD LOGFILE MEMBER '+<NEW_DG>' TO GROUP 1;
select lf.group#,lf.member,lg.status from v$logfile lf, v$log lg where lf.GROUP#=lg.GROUP# order by 1;
ALTER DATABASE DROP LOGFILE MEMBER '<LG_P1>';
select lf.group#,lf.member,lg.status from v$logfile lf, v$log lg where lf.GROUP#=lg.GROUP# order by 1;
4.重启服务,检查变更后的MGMTDB信息
$ srvctl config mgmtdb
# ./srvctl stop mgmtdb
# ./srvctl start mgmtdb
# ./srvctl status mgmtlsnr
# ./srvctl status mgmtdb
# ./srvctl config mgmtdb