Rman异机恢复

一、查看数据库的dbid
select dbid from v$database;

二、修改参数文件
create pfile=’/tmp/pfile’ from spfile;
直接恢复spfile

三、rman操作
1.rman target /
2.startup nomount pfile=’xxxxxx’
3.set DBID=XXXXXXX

4.恢复控制文件

run{
allocate channel c1 type disk;
restore controlfile from '控制文件rman备份路径';
release channel c1;
}

5.加载控制文件
alter database mount;

6.恢复

run{
allocate channel c1 type disk;
[Set newname for datafile 1 to '新数据文件路径';]
restore database;
[switch datafile all;]
--rman中修改控制文件中datafile path
--sql "alter database rename file ''/opt/oracle/oradata/test/xff_02.dbf'' to ''/opt/oracle/oradata/test/xifenfei02.dbf''"
recover database;
release channel c1;
}

alter table move与shrink space

都知道alter table move 或shrink space可以收缩段,用来消除部分行迁移,消除空间碎片,使数据更紧密,但move跟shrink space还是有区别的。
Move会移动高水位,但不会释放申请的空间,是在高水位以下(below HWM)的操作。
而shrink space 同样会移动高水位,但也会释放申请的空间,是在高水位上下(below and above HWM)都有的操作。

Move解决问题:
a. 我们可以使用move将一个table从当前的tablespace上移动到另一个tablespace上:
alter table t move tablespace tablespace_name;
b. 我们还可以用move来改变table已有的block的存储参数,如:
alter table t move storage (initial 30k next 50k);
c.另外,move操作也可以用来解决table中的行迁移的问题。

使用move的一些注意事项:
a. table上的index需要rebuild:
在前面我们讨论过,move操作后,数据的rowid发生了改变,我们知道,index是通过rowid来fetch数据行的,所以,table上的index是必须要rebuild的。
alter index index_name rebuild online;

b.move时对table的锁定
当我们对table进行move操作时,查询v$locked_objects视图可以发现,table上加了exclusive lock

c.关于move时空间使用的问题:
当我们使用alter table move来降低table的HWM时,有一点是需要注意的,这时,当前的tablespace中需要有1倍于table的空闲空间以供使用

Shrink space语法:
alter table shrink space [ | compact | cascade ];
alter table shrink space compcat;
收缩表,但会保持 high water mark;
alter table shrink space;
收缩表,降低 high water mark;
alter table shrink space cascade;
收缩表,降低 high water mark,并且相关索引也要收缩

用shrink有两个前提条件:
1、表必须启用row movement,如:
alter table nonsrt.TAB_EZG_BIZ_UNCONTRACTED enable row movement;
alter table nonsrt.TAB_EZG_BIZ_UNCONTRACTED shrink space;
2、表段所在表空间的段空间管理(segment space management)必须为auto

segment shrink分为两个阶段:
1、数据重组(compact):通过一系列insert、delete操作,将数据尽量排列在段的前面。在这个过程中需要在表上加RX锁,即只在需要移动的行上加锁。由于涉及到rowid的改变,需要enable row movement.同时要disable基于rowid的trigger.这一过程对业务影响比较小。
2、HWM调整:第二阶段是调整HWM位置,释放空闲数据块。此过程需要在表上加X锁,会造成表上的所有DML语句阻塞。在业务特别繁忙的系统上可能造成比较大的影响。
注意:shrink space语句两个阶段都执行。
shrink space compact只执行第一个阶段。
如果系统业务比较繁忙,可以先执行shrink space compact重组数据,然后在业务不忙的时候再执行shrink space降低HWM释放空闲数据块。

linux查看内存使用情况

使用free命令查看内存使用情况
[oracle@report ~]$ free -m
total   used  free shared buffers  cached
Mem: 7958   7926   3          0          19     6942

物理已用内存 = 实际已用内存 – 缓冲 – 缓存
物理已用内存为:7926-19-6942

物理空闲内存 = 总物理内存 – 实际已用内存 + 缓冲 + 缓存
物理空闲内存:7958-7926+19+6942

应用程序可用空闲内存 = 总物理内存 – 实际已用内存
应用程序可用空闲内存:7958-7926

应用程序已用内存 = 实际已用内存 – 缓冲 – 缓存
应用程序已用内存:7926-19-6942

Goldengate常见错误

ERROR OGG-01031 There is a problem in network communication, a remote file problem, encryption keys for target and source do not match (if using ENCRYPT) or an unknown error. (Reply received is Unable to open file “/opt/OGG/dirdat/AIR/EXTTRAIL/U9000005” (error 11, Resource temporarily unavailable)).
重新启动一次

WARNING OGG-00769 mysql_refresh() failed, falling back to default key. SQL error (1227). Access denied; you need the RELOAD privilege for this operation.
mysql用户权限问题

ERROR OGG-01033 There is a problem in network communication, a remote file problem, encryption keys for target and source do not match (if using ENCRYPT) or an unknown error. (Remote file used is /opt/OGG/dirdat/rl000003, reply received is Unable to lock file “/opt/OGG/dirdat/rl000003” (error 13, Permission denied). Lock currently held by process id (PID) 14409)
原因:网络或者目标段路径不正常,访问到目标端目录失败导致
在目标端kill -9 14409
或者等待2小时,自动系统自动重启目标端进程

ERROR OGG-01033 Oracle GoldenGate Capture for Oracle, p-xz.prm: There is a problem in network communication, a remote file problem, encryption keys for target and source do not match (if using ENCRYPT) or an unknown error. (Remote file used is /opt/OGG/dirdat/XunZhi/EXTFILE/U1000000, reply received is Could not create /opt/OGG/dirdat/XunZhi/EXTFILE/U1000000).
检查远程的目录是否和datapump中的远程目录是否一致