数据库

位置:IT落伍者 >> 数据库 >> 浏览文章

一次误操作引起的Oracle数据库大恢复


发布日期:2021年07月28日
 
一次误操作引起的Oracle数据库大恢复

事情起由是在Oracle g手动建库脚本中看到dbms_backup_restorezerodbid()过程其中作用是修改数据库的dbid于是想通过该存储直接在sqlplus中执行修改dbid

修改之前记录其dbid

引用

SQL> select dbid from v$database;

DBID

修改dbid

引用

SQL> exec dbms_backup_restorezerodbid();

PL/SQL procedure successfully completed

貌似执行成功了但随后alert日志显示ckpt进程将数据实例终止

引用

Tue Mar ::

CKPT: terminating instance due to error

Instance terminated by CKPT pid =

Tue Mar ::

再次启动数据库报错

引用

Tue Mar ::

Errors in file /orag/app/admin/ldbra/udump/ldbra_ora_trc:

ORA: data file is not the same file to a background process

ORA signalled during: ALTER DATABASE OPEN

dump Oracle数据文件头

引用

SQL> ALTER SESSION SET EVENTS immediate trace name file_hdrs level ;

通过跟蹤文件可以看到dbid以被重置为

引用

V STYLE FILE HEADER:

Compatibility Vsn = =xa

Db ID==x Db Name=LDBRA

Activation ID==x

Control Seq==xfba File size==xff

File Number= Blksiz= File Type= DATA

还有一种途径是通过bbed工具观察

引用

struct kcvfhhdr bytes @

ub kccfhswv @ x

ub kccfhcvn @ xa

ub kccfhdbi @ x

当然第一反应是重建控制文件看看能不能恢复成功

引用

SQL> alter database backup controlfile to trace;

Database altered

STARTUP NOMOUNT

CREATE CONTROLFILE REUSE DATABASE LDBRA RESETLOGS ARCHIVELOG

MAXLOGFILES

MAXLOGMEMBERS

MAXDATAFILES

MAXINSTANCES

MAXLOGHISTORY

LOGFILE

GROUP /orag/app/oradata/ldbra/redolog SIZE M

GROUP /orag/app/oradata/ldbra/redolog SIZE M

GROUP /orag/app/oradata/ldbra/redolog SIZE M

STANDBY LOGFILE

DATAFILE

/orag/app/oradata/ldbra/systemdbf

/orag/app/oradata/ldbra/undotbsdbf

/orag/app/oradata/ldbra/sysauxdbf

/orag/app/oradata/ldbra/usersdbf

/orag/app/oradata/ldbra/exampledbf

/orag/app/product//db_/dbs/companydbf

/orag/app/product//db_/dbs/streamsdbf

CHARACTER SET ZHSGBK

;

郁闷的是重建控制文件不成功

引用

CREATE CONTROLFILE REUSE DATABASE LDBRA RESETLOGS NOARCHIVELOG

*

ERROR at line :

ORA: CREATE CONTROLFILE failed

ORA: log is inconsistent with other logs

想到还有另外一种语法重建控制文件(重建控制文件之前备份controlfile和online redolog)

引用

Create controlfile reuse set database LDBRA

MAXINSTANCES

MAXLOGHISTORY

MAXLOGFILES

MAXLOGMEMBERS

MAXDATAFILES

Datafile

/orag/app/oradata/ldbra/systemdbf

/orag/app/oradata/ldbra/undotbsdbf

/orag/app/oradata/ldbra/sysauxdbf

/orag/app/oradata/ldbra/usersdbf

/orag/app/oradata/ldbra/exampledbf

/orag/app/product//db_/dbs/ companydbf

/orag/app/product//db_/dbs/streamsdbf

LOGFILE GROUP (/orag/app/oradata/ldbra/redolog) SIZE K

GROUP (/orag/app/oradata/ldbra/redolog) SIZE K

GROUP (/orag/app/oradata/ldbra/redolog) SIZE K RESETLOGS;

似乎重建成功了!但是进行recover的时候报错了!

引用

SQL> RECOVER DATABASE USING BACKUP CONTROLFILE;

ORA: recovery session canceled due to errors

ORA: internal error code arguments: [kcvhvdf_] [] [] [] [] [] []

[]

可以看到控制文件在重建的过程中进行了dbid重置

引用

SQL> select dbid from v$database;

DBID

问题到这里似乎失去了头绪呵呵拷回之前备份的控制文件替换刚建的控制文件因为我采用的是resetlog选项创建控制文件从理论上来讲应该是会重置redolog的即重新创建redolog但是目前采用此选项确报ORA错误不可思议!后来一想可能是跟数据文件中的dbid为有关于是采用终极修复方法bbed!首先将所有数据文件的dbid用bbed工具重置为其次将fuzzy标记打为x(因为数据库被ckpt进程异常终止将标记打为x表示数据库是shutdown immediate关闭)采用上述方法之后控制文件成功创建!

引用

SQL> STARTUP NOMOUNT

CREATE CONTROLFILE REUSE DATABASE LDBRA RESETLOGS ARCHIVELOG

MAXLOGFILES

MAXLOGMEMBERS

MAXDATAFILES

MAXINSTANCES

MAXLOGHISTORY

LOGFILE

ORACLE instance started

Total System Global Area bytes

Fixed Size bytes

Variable Size bytes

Database Buffers bytes

Redo Buffers bytes

GROUP /orag/app/oradata/ldbra/redolog SIZE M

GROUP /orag/app/oradata/ldbra/redolog SIZE M

GROUP /orag/app/oradata/ldbra/redolog SIZE M

STANDBY LOGFILE

DATAFILE

/orag/app/oradata/ldbra/systemdbf

/orag/app/oradata/ldbra/undotbsdbf

/orag/app/oradata/ldbra/sysauxdbf

/orag/app/oradata/ldbra/usersdbf

/orag/app/oradata/ldbra/exampledbf

/orag/app/product//db_/dbs/companydbf

/orag/app/product//db_/dbs/streamsdbf

CHARACTER SET ZHSGBK

;

Control file created

尝试打开数据库

SQL> alter database open RESETLOGS;

出现数据库挂起状态后台alert日志显示[]错误呵呵看到这个错误希望就来了!

引用

SMON: enabling cache recovery

Tue Mar ::

Errors in file /orag/app/admin/ldbra/udump/ldbra_ora_trc:

ORA: internal error code arguments: [] [] [] [] [] [] [] []

Tue Mar ::

Errors in file /orag/app/admin/ldbra/udump/ldbra_ora_trc:

ORA: internal error code arguments: [] [] [] [] [] [] [] []

Tue Mar ::

由于shutdown abort实例不起作用就采用杀Oracle进程删除共享内存段的做法将挂起的数据库实力强制abort

杀Oracle核心进程

引用

[orag@test bdump]$ ps ef|grep ora_

orag Feb ? :: ora_pmon_streams

orag Feb ? :: ora_psp_streams

orag Feb ? :: ora_mman_streams

orag Feb ? :: ora_dbw_streams

orag Feb ? :: ora_lgwr_streams

orag Feb ? :: ora_ckpt_streams

orag Feb ? :: ora_smon_streams

orag Feb ? :: ora_reco_streams

orag Feb ? :: ora_cjq_streams

orag Feb ? :: ora_mmon_streams

orag Feb ? :: ora_mmnl_streams

orag Feb ? :: ora_d_streams

orag Feb ? :: ora_s_streams

orag Feb ? :: ora_qmnc_streams

orag Feb ? :: ora_q_streams

orag Feb ? :: ora_q_streams

orag : ? :: ora_j_streams

orag : pts/ :: grep ora_

[orag@test bdump]$ kill

删除Oracle 共享内存段

引用

[orag@test bdump]$ ipcs

Shared Memory Segments

key shmid owner perms bytes nattch status

xccbc orag

xbb orag

Semaphore Arrays

key semid owner perms nsems

xdec orag

Message Queues

key msqid owner perms usedbytes messages

[root@test ~]# ipcrm m

[root@test ~]# ipcrm s

再次尝试将实例打开这里用到了事件

引用

SQL> alter session set events trace name adjust_scn level ;

Session altered

SQL> alter database open;

alter database open

*

ERROR at line :

ORA: file needs media recovery

ORA: data file : /orag/app/oradata/ldbra/systemdbf

SQL> recover database;

Media recovery complete

SQL> alter database open;

Database altered

后续工作就是将tempfile添加到temp表空间中终于恢复成功

引用

SQL> alter tablespace temp add tempfile /orag/app/oradata/ldbra/tempdbf size m reuse;

Tablespace altered

               

上一篇:ORCLE导出大量数据到txt

下一篇:SQL编写规范