[20160905]DUMMY实例.txt

本文介绍在缺少spfile及init*.ora文件的情况下,如何使用Oracle RMAN启动DUMMY实例,并通过备份恢复spfile,最终使数据库能够正常启动。

[20160905]DUMMY实例.txt

--如果spfile,init*.ora不存在,oracle数据库是无法启动到nomount状态.
--但是rman支持启动DUMMY实例的特殊情用于恢复。做一个记录。

1.建立测试环境:
--测试前做一个spfile的备份
RMAN> backup spfile format '/u01/backup/spfile_%U';
Starting backup at 2016-09-05 09:13:50
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=90 device type=DISK
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 2016-09-05 09:13:50
channel ORA_DISK_1: finished piece 1 at 2016-09-05 09:13:51
piece handle=/u01/backup/spfile_03rf1gue_1_1 tag=TAG20160905T091350 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-09-05 09:13:51

--关闭数据库。

$ echo $ORACLE_SID
book

$ cd /u01/app/oracle/product/11.2.0.4/dbhome_1/dbs
$ mv spfilebook.ora spfilebook.ora_20160905
$ mv initbook.ora initbook.ora_20160905

2.测试:

SYS@book> startup nomount
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/initbook.ora'

--//在sqlplus无法启动。而在rman里面

RMAN> startup nomount
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/initbook.ora'
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
Total System Global Area    1068937216 bytes
Fixed Size                     2260088 bytes
Variable Size                301990792 bytes
Database Buffers             754974720 bytes
Redo Buffers                   9711616 bytes
--退出在进入。

$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Aug 3 11:34:33 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: DUMMY (not mounted)

--可以发现数据库实例DUMMY.

3.观察OS进程:
$ ps -ef | grep -i  dummy
oracle   26360 48541  0 09:07 pts/2    00:00:00 grep -i dummy

--可以发现没有包含dummy的进程.

$ ps -ef | grep   "_boo[k]"
oracle   26309     1  0 09:06 ?        00:00:00 ora_pmon_book
oracle   26311     1  0 09:06 ?        00:00:00 ora_psp0_book
oracle   26313     1  1 09:06 ?        00:00:01 ora_vktm_book
oracle   26317     1  0 09:06 ?        00:00:00 ora_gen0_book
oracle   26319     1  0 09:06 ?        00:00:00 ora_diag_book
oracle   26321     1  0 09:06 ?        00:00:00 ora_dbrm_book
oracle   26323     1  0 09:06 ?        00:00:00 ora_dia0_book
oracle   26325     1  0 09:06 ?        00:00:00 ora_mman_book
oracle   26327     1  0 09:06 ?        00:00:00 ora_dbw0_book
oracle   26329     1  0 09:06 ?        00:00:00 ora_dbw1_book
oracle   26331     1  0 09:06 ?        00:00:00 ora_dbw2_book
oracle   26333     1  0 09:06 ?        00:00:00 ora_lgwr_book
oracle   26335     1  0 09:06 ?        00:00:00 ora_ckpt_book
oracle   26337     1  0 09:06 ?        00:00:00 ora_smon_book
oracle   26339     1  0 09:06 ?        00:00:00 ora_reco_book
oracle   26341     1  0 09:06 ?        00:00:00 ora_mmon_book
oracle   26343     1  0 09:06 ?        00:00:00 ora_mmnl_book

--反到是存在包含实例名book的进程.

4.恢复spfile文件看看:

RMAN> restore spfile from autobackup ;
Starting restore at 2016-09-05 09:08:10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1345 device type=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 09/05/2016 09:08:11
RMAN-06495: must explicitly specify DBID with SET DBID command

--要求指定dbid。我感觉主要不知道fast_recovery_area目录在哪里。确定dbid可以看文件头

BBED> set dba 1,1
        DBA             0x00400001 (4194305 1,1)

BBED> p kcvfh.kcvfhhdr.kccfhdbi
ub4 kccfhdbi                                @28       0x4fb7216e

BBED> p /d kcvfh.kcvfhhdr.kccfhdbi
ub4 kccfhdbi                                @28       1337401710
======================================================================

RMAN> restore spfile from '/u01/backup/spfile_03rf1gue_1_1';
Starting restore at 2016-09-05 09:15:59
using channel ORA_DISK_1

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/backup/spfile_03rf1gue_1_1
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 2016-09-05 09:16:00

$ ls -l  /u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/spfilebook.ora
-rw-r----- 1 oracle oinstall 3584 2016-09-05 09:15:59 /u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/spfilebook.ora

SYS@book> shutdown immediate ;
ORA-01507: database not mounted


ORACLE instance shut down.
SYS@book> startup nomount
ORACLE instance started.

Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes

--oracle通过这个实例DUMMY,解决鸡生蛋,蛋生鸡的问题.有了spfile文件,再执行恢复就简单了.

""" LRU缓存组模拟器 处理读写请求并根据LRU策略管理缓存置换,支持多组缓存 """ class CacheNode: def __init__(self, memory_index, next=None, prev=None, is_dirty=False): self.memory_index = memory_index # 内存块标识 self.next = next # 后驱节点 self.prev = prev # 前驱节点 self.is_dirty = is_dirty # 标记是否被修改 class LRUCacheGroup: def __init__(self, capacity): # 初始化双向链表头尾哨兵节点 self.dummy_head = CacheNode(-1) self.dummy_tail = CacheNode(-1) self.dummy_head.next = self.dummy_tail self.dummy_tail.prev = self.dummy_head self.cache_map = {} # 内存块索引 -> 节点映射 self.capacity = capacity # 组内最大缓存容量 self.current_size = 0 # 当前缓存数量 def _remove_node(self, node: CacheNode): """从链表中移除指定节点""" prev_node = node.prev next_node = node.next prev_node.next = next_node next_node.prev = prev_node def _insert_to_head(self, node: CacheNode): """将节点插入链表头部(最近使用位置)""" # 调整头节点和原首节点的指针 original_first = self.dummy_head.next self.dummy_head.next = node node.prev = self.dummy_head node.next = original_first original_first.prev = node def _move_to_head(self, node: CacheNode): """将已存在的节点移动到头部""" self._remove_node(node) self._insert_to_head(node) def _evict_last(self): """淘汰末尾节点(最久未使用),返回需要写回磁盘的操作""" evicted_node = self.dummy_tail.prev self.cache_map.pop(evicted_node.memory_index) self._remove_node(evicted_node) self.current_size -= 1 # 如果节点被修改过,需要写回磁盘 return [[1, evicted_node.memory_index]] if evicted_node.is_dirty else [] def _add_new_node(self, memory_index: int): """添加新节点到缓存组,触发置换逻辑""" operations = [] new_node = CacheNode(memory_index) self.cache_map[memory_index] = new_node self._insert_to_head(new_node) self.current_size += 1 # 超过容量时淘汰末尾节点 if self.current_size > self.capacity: operations.extend(self._evict_last()) # 记录缓存加载操作 operations.append([0, memory_index]) return operations def read_memory(self, memory_index): """处理读请求:命中则移动节点,未命中则加载""" if memory_index in self.cache_map: self._move_to_head(self.cache_map[memory_index]) return [] return self._add_new_node(memory_index) def write_memory(self, memory_index): """处理写请求:标记为脏数据,其余逻辑与读相同""" operations = [] # 未命中时先加载 if memory_index not in self.cache_map: operations.extend(self._add_new_node(memory_index)) else: self._move_to_head(self.cache_map[memory_index]) # 标记数据已被修改 self.cache_map[memory_index].is_dirty = True return operations # 主程序流程 if __name__ == "__main__": # 参数解析 group_size, group_count, query_count = map(int, input().split()) # 初始化所有缓存组(每组容量为group_size) cache_groups = [LRUCacheGroup(group_size) for _ in range(group_count)] output = [] for _ in range(query_count): operation_type, memory_index = map(int, input().split()) # 计算目标缓存组:按 (内存地址//组大小) % 组总数 的哈希策略 group_id = (memory_index // group_size) % group_count current_group = cache_groups[group_id] if operation_type == 0: # 读操作 operations = current_group.read_memory(memory_index) else: # 写操作 operations = current_group.write_memory(memory_index) # 收集操作结果 for op in operations: output.append(f"{op[0]} {op[1]}") # 输出所有操作记录 print("\n".join(output))使用c/c++改写代码
03-30
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值