sysdba权限远程访问nomount状态数据库和ASM实例
对于nomount状态的数据库,在动态监听状态下,所有用户远程都无法连接数据库。
下面测试下动态监听下,sysdba权限远程访问nomount状态和mount状态的数据库。
1.修改监听为动态监听
LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = stream-PC)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) )
2.将数据库启动到nomount状态
SQL> startup nomount ORACLE 例程已经启动。 Total System Global Area 1071333376 bytes Fixed Size 1375792 bytes Variable Size 570425808 bytes Database Buffers 494927872 bytes Redo Buffers 4603904 bytes SQL> select status from v$instance; STATUS ------------------------ STARTED
3.检查监听的状态
C:\Windows\system32>lsnrctl status LSNRCTL for 32-bit Windows: Version 11.2.0.1.0 - Production on 21-10月-2013 10:33:15 Copyright (c) 1991, 2010, Oracle. All rights reserved. 正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=stream-PC)(PORT=1521))) LISTENER 的 STATUS ------------------------ 别名 LISTENER 版本 TNSLSNR for 32-bit Windows: Version 11.2.0.1.0 - Production 启动日期 21-10月-2013 10:03:14 正常运行时间 0 天 0 小时 30 分 0 秒 跟踪级别 off 安全性 ON: Local OS Authentication SNMP OFF 监听程序参数文件 D:\app\stream\product\11.2.0\dbhome_1\network\admin\listener.ora 监听程序日志文件 d:\app\stream\diag\tnslsnr\stream-PC\listener\alert\log.xml 监听端点概要... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=stream-PC)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc))) 服务摘要.. 服务 "dbdream" 包含 1 个实例。 实例 "dbdream", 状态 BLOCKED, 包含此服务的 1 个处理程序... 命令执行成功
在动态监听状态下,nomount状态的数据库是BLOCKED的状态,此时所有用户远程访问数据库都会报ORA-12528错误。
C:\Windows\system32>sqlplus sys/oracle@localhost/dbdream as sysdba SQL*Plus: Release 11.2.0.1.0 Production on 星期一 10月 21 10:37:57 2013 Copyright (c) 1982, 2010, Oracle. All rights reserved. ERROR: ORA-12528: TNS: 监听程序: 所有适用例程都无法建立新连接 请输入用户名:
网上有人说只有在mount状态下PMON进程才会将服务推送给监听,这种说法我认为是不对的,从告警日至就可以看到,PMON进程是在分配内存后第一个启动的进程,PID=2。
Starting up: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production With the Partitioning option. Using parameter settings in server-side spfile D:\APP\STREAM\PRODUCT\11.2.0\DBHOME_1\DATABASE\SPFILEDBDREAM.ORA System parameters with non-default values: processes = 150 memory_target = 1232M control_files = "D:\APP\STREAM\ORADATA\DBDREAM\CONTROL01.CTL" control_files = "D:\APP\STREAM\FLASH_RECOVERY_AREA\DBDREAM\CONTROL02.CTL" db_block_size = 8192 compatible = "11.2.0.0.0" log_archive_dest_1 = "location=D:\ARCH" log_archive_dest_2 = "" log_archive_format = "SID%S_%R_%T.ARC" db_recovery_file_dest = "D:\app\stream\flash_recovery_area" db_recovery_file_dest_size= 10G log_checkpoints_to_alert = TRUE undo_tablespace = "UNDOTBS1" remote_login_passwordfile= "EXCLUSIVE" db_domain = "" dispatchers = "(PROTOCOL=TCP) (SERVICE=dbdreamXDB)" audit_file_dest = "D:\APP\STREAM\ADMIN\DBDREAM\ADUMP" audit_trail = "DB" db_name = "dbdream" open_cursors = 300 diagnostic_dest = "D:\APP\STREAM" Mon Oct 21 10:10:49 2013 PMON started with pid=2, OS id=6092
而且,在数据库关闭状态,在动态监听状态,监听服务里是看不到数据库的信息的,在nomount状态下,监听信息里可以看到数据库状态是BLOCKED,那也就是说在nomount状态下,PMON已经将数据库的状态推送给监听了,而不是在mount状态才会推送的,我估计这个网友是要表达在mount状态下, sysdba权限可以访问动态监听的数据库,就认为只有在mount状态下,PMON进程才会将数据库信息推送给监听。
4.启动数据库到mount状态
SQL> alter database mount; 数据库已更改。
5.查看监听状态
C:\Windows\system32>lsnrctl status LSNRCTL for 32-bit Windows: Version 11.2.0.1.0 - Production on 21-10月-2013 10:46:56 Copyright (c) 1991, 2010, Oracle. All rights reserved. 正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=stream-PC)(PORT=1521))) LISTENER 的 STATUS ------------------------ 别名 LISTENER 版本 TNSLSNR for 32-bit Windows: Version 11.2.0.1.0 - Production 启动日期 21-10月-2013 10:03:14 正常运行时间 0 天 0 小时 43 分 41 秒 跟踪级别 off 安全性 ON: Local OS Authentication SNMP OFF 监听程序参数文件 D:\app\stream\product\11.2.0\dbhome_1\network\admin\listener.ora 监听程序日志文件 d:\app\stream\diag\tnslsnr\stream-PC\listener\alert\log.xml 监听端点概要... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=stream-PC)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc))) 服务摘要.. 服务 "dbdream" 包含 1 个实例。 实例 "dbdream", 状态 READY, 包含此服务的 1 个处理程序... 命令执行成功
在mount状态下,监听状态是READY,在READY状态, sysdba权限是可以远程访问数据库的(在动态监听状态,数据库在OPEN时,监听状态也是READY)。
6.尝试sysdba权限远程访问数据库
C:\Windows\system32>sqlplus sys/oracle@localhost/dbdream as sysdba SQL*Plus: Release 11.2.0.1.0 Production on 星期一 10月 21 11:04:49 2013 Copyright (c) 1982, 2010, Oracle. All rights reserved. 连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production With the Partitioning option
在静态监听状态下,sysdba权限远程是可以访问nomount的数据库的。
- 修改监听为静态模式
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = CLRExtProc) (ORACLE_HOME = D:\app\stream\product\11.2.0\dbhome_1) (PROGRAM = extproc) (ENVS = "EXTPROC_DLLS=ONLY:D:\app\stream\product\11.2.0\dbhome_1\bin\oraclr11.dll") ) (SID_DESC = (SID_NAME = dbdream) (ORACLE_HOME = D:\app\stream\product\11.2.0\dbhome_1) (GLOBAL_DBNAME=dbdream) ) )
2.数据库启动到nomount状态
SQL> startup nomount ORACLE 例程已经启动。 Total System Global Area 1071333376 bytes Fixed Size 1375792 bytes Variable Size 570425808 bytes Database Buffers 494927872 bytes Redo Buffers 4603904 bytes
3.查看监听状态
C:\Windows\system32>lsnrctl start LSNRCTL for 32-bit Windows: Version 11.2.0.1.0 - Production on 21-10月-2013 11:28:19 Copyright (c) 1991, 2010, Oracle. All rights reserved. 启动tnslsnr: 请稍候... TNSLSNR for 32-bit Windows: Version 11.2.0.1.0 - Production 系统参数文件为D:\app\stream\product\11.2.0\dbhome_1\network\admin\listener.ora 写入d:\app\stream\diag\tnslsnr\stream-PC\listener\alert\log.xml的日志信息 监听: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=stream-PC)(PORT=1521))) 正在连接到 (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) LISTENER 的 STATUS ------------------------ 别名 LISTENER 版本 TNSLSNR for 32-bit Windows: Version 11.2.0.1.0 - Production 启动日期 21-10月-2013 11:28:24 正常运行时间 0 天 0 小时 0 分 7 秒 跟踪级别 off 安全性 ON: Local OS Authentication SNMP OFF 监听程序参数文件 D:\app\stream\product\11.2.0\dbhome_1\network\admin\listener.ora 监听程序日志文件 d:\app\stream\diag\tnslsnr\stream-PC\listener\alert\log.xml 监听端点概要... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=stream-PC)(PORT=1521))) 服务摘要.. 服务 "CLRExtProc" 包含 1 个实例。 实例 "CLRExtProc", 状态 UNKNOWN, 包含此服务的 1 个处理程序... 服务 "dbdream" 包含 1 个实例。 实例 "dbdream", 状态 UNKNOWN, 包含此服务的 1 个处理程序... 命令执行成功
在静态监听状态,nomount的数据库的状态是UNKNOWN状态,sysdba权限可以远程访问nomount状态的数据库。
4.尝试用sysdba权限远程访问nomount的数据库
C:\Windows\system32>sqlplus sys/oracle@localhost/dbdream as sysdba SQL*Plus: Release 11.2.0.1.0 Production on 星期一 10月 21 11:28:34 2013 Copyright (c) 1982, 2010, Oracle. All rights reserved. 连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production With the Partitioning option SQL> select status from v$instance; STATUS ------------------------ STARTED
在静态监听模式,sysdba权限是可以远程访问数据库的,而动态监听模式,只有mount状态,sysdba才可以访问数据库。现在好多数据库监听模式都是默认的动态监听,那么有什么办法可以使动态监听的数据库在nomount状态也能用sysdba权限远程访问数据库呢?10g版本之后的数据库可以在TNS文件里加上UR=A来解决这个问题。下面来测试下这个功能。
- 修改监听文件,该为动态监听
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = CLRExtProc) (ORACLE_HOME = D:\app\stream\product\11.2.0\dbhome_1) (PROGRAM = extproc) (ENVS = "EXTPROC_DLLS=ONLY:D:\app\stream\product\11.2.0\dbhome_1\bin\oraclr11.dll") ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = stream-PC)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) )
2.数据库启动到nomount状态
SQL> startup nomount ORACLE 例程已经启动。 Total System Global Area 1071333376 bytes Fixed Size 1375792 bytes Variable Size 570425808 bytes Database Buffers 494927872 bytes Redo Buffers 4603904 bytes
3.查看监听状态
C:\Windows\system32>lsnrctl status LSNRCTL for 32-bit Windows: Version 11.2.0.1.0 - Production on 21-10月-2013 11:51:01 Copyright (c) 1991, 2010, Oracle. All rights reserved. 正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=stream-PC)(PORT=1521))(UR=A)) LISTENER 的 STATUS ------------------------ 别名 LISTENER 版本 TNSLSNR for 32-bit Windows: Version 11.2.0.1.0 - Production 启动日期 21-10月-2013 11:50:31 正常运行时间 0 天 0 小时 0 分 33 秒 跟踪级别 off 安全性 ON: Local OS Authentication SNMP OFF 监听程序参数文件 D:\app\stream\product\11.2.0\dbhome_1\network\admin\listener.ora 监听程序日志文件 d:\app\stream\diag\tnslsnr\stream-PC\listener\alert\log.xml 监听端点概要... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=stream-PC)(PORT=1521))(UR=A)) (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc))(UR=A)) 服务摘要.. 服务 "CLRExtProc" 包含 1 个实例。 实例 "CLRExtProc", 状态 UNKNOWN, 包含此服务的 1 个处理程序... 服务 "dbdream" 包含 1 个实例。 实例 "dbdream", 状态 BLOCKED, 包含此服务的 1 个处理程序... 命令执行成功
监听状态是BLOCKED,之前测试过,默认情况下动态监听模式,sysdba权限远程是无法访问nomount状态的数据库的,加入TNS文件加入UR=A后是否可以成功访问数据库呢?
4.修改TNS文件,加入UR=A
dbdream = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = dbdream) (UR=A) ) )
5.尝试用sysdba权限远程访问nomount状态的数据库
C:\Windows\system32>sqlplus sys/oracle@dbdream as sysdba SQL*Plus: Release 11.2.0.1.0 Production on 星期一 10月 21 12:02:49 2013 Copyright (c) 1982, 2010, Oracle. All rights reserved. 连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production With the Partitioning option SQL> select status from v$instance; STATUS ------------------------ STARTED
大家都知道ASM实例最多启动到MOUNT状态,而ASM的监听状态一直都是BLOCKED,在配置OGG时,如果数据库使用ASM文件系统,那么就需要设置UR=A,否则OGG将无法正常访问ASM,下面看ASM的监听状态。
[oracle@node1 admin]$ lsnrctl status LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 21-OCT-2013 05:30:03 Copyright (c) 1991, 2010, Oracle. All rights reserved. Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) STATUS of the LISTENER ------------------------ Alias LISTENER_NODE1 Version TNSLSNR for Linux: Version 10.2.0.5.0 - Production Start Date 11-OCT-2013 04:15:00 Uptime 10 days 1 hr. 15 min. 2 sec Trace Level off Security ON: Password or Local OS Authentication SNMP OFF Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener_node1.log Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.56)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC))) Services Summary... Service "+ASM" has 1 instance(s). Instance "+ASM1", status BLOCKED, has 1 handler(s) for this service... Service "+ASM_XPT" has 1 instance(s). Instance "+ASM1", status BLOCKED, has 1 handler(s) for this service... The command completed successfully
配置TNS,添加ASM信息。
+ASM1 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = node1-vip)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = +ASM) (INSTANCE_NAME = +ASM1) ) )
这样sysdba权限无法远程访问ASM。
[oracle@node1 admin]$ sqlplus sys/oracle@+ASM1 as sysdba SQL*Plus: Release 10.2.0.5.0 - Production on Mon Oct 21 05:33:04 2013 Copyright (c) 1982, 2010, Oracle. All Rights Reserved. ERROR: ORA-12528: TNS:listener: all appropriate instances are blocking new connections Enter user-name:
修改TNS文件,加入UR=A。
+ASM1 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = node1-vip)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = +ASM) (INSTANCE_NAME = +ASM1) (UR=A) ) )
在加入UR=A后,sysdba权限就可以远程访问ASM了。
[oracle@node1 admin]$ sqlplus sys/oracle@+ASM1 as sysdba SQL*Plus: Release 10.2.0.5.0 - Production on Mon Oct 21 05:34:24 2013 Copyright (c) 1982, 2010, Oracle. All Rights Reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production With the Partitioning, Real Application Clusters, OLAP, Data Mining and Real Application Testing options SQL>
可见,不论是数据库还是ASM,在BLOCKED状态,都可以使用在TNS文件中加入UR=A选项实现sysdba权限远程访问。