日期:2014-05-16  浏览次数:20353 次

Data guard standby数据库的ctl文件与数据文件不一致导致的ORA-16012

?目前在弄Oracle dataguard做异地容灾。

一切配置按照文档来,没出什么问题。

但是其他同事创建的时候发现备库无法和主库同步,备库却可以处于正常的mount状态。

查看primary数据库的alert.log

其中有错误

Errors in file /opt/app/oracle/diag/rdbms/xxx/trace/xxx_arc2_18107.trc:
ORA-16012: database identifier mismatch

查看文件xxx_arc2_18107.trc,其中有错误信息

OCISessionBegin failed -1
.. Detailed OCI error val is 1017 and errmsg is 'ORA-01017: invalid username/password; logon denied
'
OCISessionBegin failed. Error -1
.. Detailed OCI error val is 1031 and errmsg is 'ORA-01031: insufficient privileges
'
OCISessionBegin failed. Error -1
.. Detailed OCI error val is 1031 and errmsg is 'ORA-01031: insufficient privileges

主库远程访问备库时需要密码文件登入备库,估计是备库密码文件创建问题,重建密码文件,拷贝到备库dbs目录,ORA-01031错误消失。

?

但仍然不能同步,ORA-16012: database identifier mismatch错误继续出现,在trc文件中,出现下面的内容

Logged on to standby successfully
Client logon and security negotiation successful!
Error 16012 attaching RFS server to standby instance at host 'emadbdg'
Error 16012 attaching to destination LOG_ARCHIVE_DEST_2 standby host 'emadbdg'
ORA-16012: database identifier mismatch
暂时对这个ORA-16012没什么头绪,没有查到对应的措施,但说明前面主库向备库登录的验证已经过了。

继续检查standby数据库的alert.log,发现standby库在mount过程就抛出数据文件的错误。

检查primary数据库alert.log

Mon May 16 10:53:10 2011

alter database create standby controlfile as '/var/tmp/dg/control01.ctl'

ORA-1580 signalled during: alter database create standby controlfile as '/var/tmp/dg/control01.ctl'...

发现在创建备库的ctl控制文件就出现了问题,这是个疑点。

同事回忆发现原来直接拷贝了/var/tmp/dg/中上次创建的ctl文件,这个文件由于创建失败没有覆盖老的,这样造成数据文件和ctl控制文件的时间版本不一致。

重新拷贝数据文件,创建ctl文件,复制,错误消除。

?

在创建主库数据文件备份后要立刻创建备库的控制文件

SQL>?STARTUP?MOUNT;

SQL>?ALTER?DATABASE?CREATE?STANDBY?CONTROLFILE?AS?'/tmp/control01.ctl';

因为控制文件会包含数据文件的checkpoint scn,系统 checkpoint的SCN,数据文件stop scn,数据库在正常运行的情况下要和数据文件的start scn要保持一致。

如果备份主库数据文件之后,数据库被open,再创建ctl文件,则此时的ctl文件与备份的数据文件不同步,用来创建dataguard便会导致问题。