Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2880841
  • 博文数量: 599
  • 博客积分: 16398
  • 博客等级: 上将
  • 技术积分: 6875
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-30 12:04
个人简介

WINDOWS下的程序员出身,偶尔也写一些linux平台下小程序, 后转行数据库行业,专注于ORACLE和DB2的运维和优化。 同时也是ios移动开发者。欢迎志同道合的朋友一起研究技术。 数据库技术交流群:58308065,23618606

文章分类

全部博文(599)

文章存档

2014年(12)

2013年(56)

2012年(199)

2011年(105)

2010年(128)

2009年(99)

分类: Oracle

2009-12-12 13:52:00

利用OracleSTANDBY技术,可以将单实例数据库升级到RAC数据库。这种方式可以有效的降低单实例迁移到RAC环境的停机时间。

这篇文章介绍STANDBY数据库的建立。

利用STANDBY将单实例数据库升级为RAC环境(一):http://yangtingkun.itpub.net/post/468/494736


上一篇完成了绝大部分准备的工作,下面在打开数据库之前,还要设置一下目标数据库上的密码文件。

STANDBYRAC环境的两个节点上分别拷贝密码文件:

bash-3.00$ cd $ORACLE_HOME/dbs
bash-3.00$ ftp 172.0.2.61
Connected to 172.0.2.61.
220 netdb1 FTP server ready.
Name (172.0.2.61:oracle): oracle
331 Password required for oracle.
Password:
230 User oracle logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> bin
200 Type set to I.
ftp> cd /data/oracle/product/11.1/dbs
250 CWD command successful.
ftp> prompt
Interactive mode off.
ftp> mget orapwtest11g
200 PORT command successful.
150 Opening BINARY mode data connection for orapwtest11g (1536 bytes).
226 Transfer complete.
local: orapwtest11g remote: orapwtest11g
1536 bytes received in 0.017 seconds (87.65 Kbytes/s)
ftp> exit
?Invalid command
ftp> quit
221-You have transferred 1536 bytes in 1 files.
221-Total traffic for this session was 2229 bytes in 2 transfers.
221-Thank you for using the FTP service on netdb1.
221 Goodbye.

bash-3.00$ mv orapwtest11g orapwtest11gr1

在节点2上,密码文件应该重命名为orapwtest11gr2

修改STANDBY数据库节点1上的监听配置,在SID_LIST_LISTENER的配置中,添加test11gr1的配置:

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = rac11g1)
(ORACLE_HOME = /data/oracle/product/11.1/database)
)
(SID_DESC =
(SID_NAME = test11gr1)
(ORACLE_HOME = /data/oracle/product/11.1/database)
)
)

下面重启监听:

bash-3.00$ lsnrctl stop

LSNRCTL for Solaris: Version 11.1.0.6.0 - Production on 13-7 -2009 17:21:39

Copyright (c) 1991, 2007, Oracle. All rights reserved.

正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ser1-vip)(PORT=1521)))命令执行成功
bash-3.00$ lsnrctl start

LSNRCTL for Solaris: Version 11.1.0.6.0 - Production on 13-7 -2009 17:21:42

Copyright (c) 1991, 2007, Oracle. All rights reserved.

启动/data/oracle/product/11.1/database/bin/tnslsnr: 请稍候...

TNSLSNR for Solaris: Version 11.1.0.6.0 - Production系统参数文件为/data/oracle/product/11.1/database/network/admin/listener.ora写入/data/oracle/diag/tnslsnr/ser1/listener/alert/log.xml的日志信息监听: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.0.2.68)(PORT=1521)))监听: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ser1)(PORT=1521)))监听: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))

正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ser1-vip)(PORT=1521)))
LISTENER
STATUS
------------------------
别名
LISTENER版本 TNSLSNR for Solaris: Version 11.1.0.6.0 - Production启动日期 13-7 -2009 17:21:42正常运行时间 0 0 小时 0 0 跟踪级别 off安全性 ON: Local OS Authentication
SNMP OFF
监听程序参数文件
/data/oracle/product/11.1/database/network/admin/listener.ora监听程序日志文件 /data/oracle/diag/tnslsnr/ser1/listener/alert/log.xml监听端点概要...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.0.2.68)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ser1)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))
服务摘要
..服务 "rac11g1" 包含 1 个例程。
例程 "rac11g1", 状态 UNKNOWN, 包含此服务的 1 个处理程序...服务 "test11gr1" 包含 1 个例程。
例程 "test11gr1", 状态 UNKNOWN, 包含此服务的 1 个处理程序...命令执行成功

修改两个节点上的TNSNAMES.ORA的配置,添加主库的配置:

TEST11G =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.0.2.61)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = TEST11G.netdb)
(SERVER = DEDICATED)
)
)

确保STANDBY数据库可以通过服务名访问主库:

bash-3.00$ tnsping test11g

TNS Ping Utility for Solaris: Version 11.1.0.6.0 - Production on 13-7 -2009 17:33:07

Copyright (c) 1997, 2007, Oracle. All rights reserved.

已使用的参数文件:

已使用 TNSNAMES 适配器来解析别名
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.0.2.61)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = NEW11G.netdb) (SERVER = DEDICATED)))
OK (10
毫秒)

监测ASM实例是否已经启动,如果ASM没有启动,通过srvctl start asm的方式启动ASM实例:

bash-3.00$ export ORACLE_SID=+ASM1
bash-3.00$ sqlplus "/ as sysdba"

SQL*Plus: Release 11.1.0.6.0 - Production on 星期三 7 15 15:09:08 2009

Copyright (c) 1982, 2007, Oracle. All rights reserved.

连接到:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options

SQL> select instance_name, status from v$instance;

INSTANCE_NAME STATUS
-------------------------------- ------------------------
+ASM1 STARTED

SQL> select instance_name, status from gv$instance;

INSTANCE_NAME STATUS
-------------------------------- ------------------------
+ASM1 STARTED
+ASM2 STARTED

SQL> select name from v$asm_diskgroup;

NAME
------------------------------------------------------------
DATA

下面就可以在RAC的节点1上尝试启动STANDBY数据库。

bash-3.00$ export ORACLE_SID=test11gr1
bash-3.00$ sqlplus "/ as sysdba"

SQL*Plus: Release 11.1.0.6.0 - Production on 星期一 7 13 16:47:52 2009

Copyright (c) 1982, 2007, Oracle. All rights reserved.

已连接到空闲例程。

SQL> startup nomount pfile=/export/home/oracle/inittest11gr1.ora
ORACLE
例程已经启动。

Total System Global Area 7418036224 bytes
Fixed Size 2095808 bytes
Variable Size 3183650112 bytes
Database Buffers 4227858432 bytes
Redo Buffers 4431872 bytes
SQL> alter database mount;

数据库已更改。

SQL> alter database recover managed standby database disconnect from session;

数据库已更改。

至此STANDBY数据库已经建立成功。

检查STANDBY数据库的状态:

SQL> select pid, status, client_process, group#, resetlog_id, thread#, sequence#
2 from v$managed_standby;

PID STATUS CLIENT_P GROUP# RESETLOG_ID THREAD# SEQUENCE#
---------- ------------ -------- ---------- ----------- ---------- ----------
24384 CONNECTED ARCH N/A 0 0 0
24386 CONNECTED ARCH N/A 0 0 0
24388 CONNECTED ARCH N/A 0 0 0
24395 CONNECTED ARCH N/A 0 0 0
24549 WAIT_FOR_LOG N/A N/A 683602501 1 156
26208 IDLE UNKNOWN N/A 0 0 0
26214 IDLE UNKNOWN N/A 0 0 0
26229 IDLE UNKNOWN N/A 0 0 0
7061 IDLE LGWR 3 683602501 1 156

已选择9行。

坚持主数据库的归档情况:

SQL> select name, dest_id, thread#, sequence#, creator
2 from v$archived_log
3 where sequence# = 155;

NAME DEST_ID THREAD# SEQUENCE# CREATOR
----------------------------------------------------- -------- -------- ---------- --------
TEST11GR 2 1 155 LGWR
/data/oradata/test11g/archivelog/1_155_683602501.dbf 1 1 155 ARCH

现在STANDBY的进度已经和主库保持一致了。

下面关闭恢复归档状态,并已只读方式打开数据库:

SQL> alter database recover managed standby database cancel;

数据库已更改。

SQL> alter database open read only;

数据库已更改。

检查实例状态:

SQL> select instance_name, status from v$instance;

INSTANCE_NAME STATUS
---------------- ------------
test11gr1 OPEN

SQL> select instance_name, status from gv$instance;

INSTANCE_NAME STATUS
---------------- ------------
test11gr1 OPEN

ASM上创建共享的SPFILE文件:

SQL> create spfile = '+DATA/TEST11G/spfiletest11gr.ora'
2 from pfile = '/export/home/oracle/inittest11gr1.ora';

文件已创建。

在实例2对应的节点上,尝试只读方式打开数据库:

bash-3.00$ echo spfile=+DATA/TEST11G/spfiletest11gr.ora >> /export/home/oracle/inittest11gr2.ora
bash-3.00$ more /export/home/oracle/inittest11gr2.ora
spfile=+DATA/TEST11G/spfiletest11gr.ora
bash-3.00$ export ORACLE_SID=test11gr2
bash-3.00$ sqlplus "/ as sysdba"

SQL*Plus: Release 11.1.0.6.0 - Production on 星期五 7 17 19:37:32 2009

Copyright (c) 1982, 2007, Oracle. All rights reserved.

已连接到空闲例程。

SQL> startup open read only pfile=/export/home/oracle/inittest11gr2.ora
ORACLE
例程已经启动。

Total System Global Area 7418036224 bytes
Fixed Size 2095808 bytes
Variable Size 3250758976 bytes
Database Buffers 4160749568 bytes
Redo Buffers 4431872 bytes
数据库装载完毕。数据库已经打开。
SQL> select instance_name, status from v$instance;

INSTANCE_NAME STATUS
---------------- ------------
test11gr2 OPEN

SQL> select instance_name, status from gv$instance;

INSTANCE_NAME STATUS
---------------- ------------
test11gr2 OPEN
test11gr1 OPEN

检查数据库信息:

SQL> select name, db_unique_name, primary_db_unique_name, database_role
2 from v$database;

NAME DB_UNIQUE_NAME PRIMARY_DB_UNIQUE_NAME DATABASE_ROLE
--------- ------------------------------ ------------------------------ ----------------
TEST11G TEST11GR TEST11G PHYSICAL STANDBY

至此单实例数据库的RAC环境STANDBY数据库建立完成。

下面可以准备进行SWITCHOVER切换了。

阅读(1273) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~