♣
题目部分
在Oracle中,如何将一个数据库添加到CRS中?
♣
答案部分
虽然通过DBCA(DataBase Configuration Assistant,数据库配置助手)创建的数据库会自动加入CRS中,但通过RMAN创建的数据库是不会被加入CRS中的,在这种情况下就需要手动添加,将数据库加入CRS中后就可以通过srvctl来管理数据库了。
主要的命令包括:
1srvctl remove database -d lhrrac1 -f 2srvctl add db -d lhrrac1 -o /u01/app/oracle/product/11.2.0/dbhome_1 -c RAC -p '+DATA/lhrrac1/spfilelhrrac1.ora' -r PRIMARY 3srvctl add instance -d lhrrac1 -i lhrrac11 -n raclhr-11gR2-N1 4srvctl add instance -d lhrrac1 -i lhrrac12 -n raclhr-11gR2-N2 5crsctl start res ora.lhrrac1.db 6srvctl config db -d lhrrac1 -a 7crsctl stat res ora.lhrrac1.db -p
修改数据库的属性:
1srvctl modify database -d lhrrac1 -p '+DATA/lhrrac1/spfilelhrrac.ora' 2srvctl modify database -d lhrrac1 -s MOUNT 3srvctl modify database -d lhrrac1 -t ABORT 4srvctl modify database -d lhrrac1 -s open -t immediate
禁用数据库随CRS的启动而启动:
1crsctl modify resource ora.lhrrac1.db -attr AUTO_START=never 2crsctl stat res ora.lhrrac1.db -p | grep AUTO_START
禁止CRS管理数据库:
1srvctl disable db -d lhrrac1 2crsctl stat res ora.lhrrac1.db -p | grep ENABLE 3crsctl modify res ora.lhrrac1.db -attr "ENABLED=0"
属性AUTO_START表示Oracle Clusterware在群集服务器重启后是否自动启动资源。有效的AUTO_START值为:
l always:在服务器重新启动时重新启动资源,而不管服务器停止时资源的状态如何。
l restore:将资源恢复到服务器停止时的状态。如果在服务器停止之前TARGET的值为ONLINE,那么Oracle Clusterware会尝试重新启动资源。
l never:无论服务器何时停止,Oracle Clusterware都不会重新启动资源。
下面的例子演示了如何将一个物理DG添加到CRS中。
1[ZHLHRDB2:Oracle]:/Oracle>crsctl stat res -t 2-------------------------------------------------------------------------------- 3NAME TARGET STATE SERVER STATE_DETAILS 4-------------------------------------------------------------------------------- 5Local Resources 6-------------------------------------------------------------------------------- 7ora.DATA.dg 8 ONLINE ONLINE ZHLHRDB1 9 ONLINE ONLINE ZHLHRDB2 10ora.LISTENER.lsnr 11 ONLINE ONLINE ZHLHRDB1 12 ONLINE ONLINE ZHLHRDB2 13ora.asm 14 ONLINE ONLINE ZHLHRDB1 Started 15 ONLINE ONLINE ZHLHRDB2 Started 16ora.gsd 17 OFFLINE OFFLINE ZHLHRDB1 18 OFFLINE OFFLINE ZHLHRDB2 19ora.net1.network 20 ONLINE ONLINE ZHLHRDB1 21 ONLINE ONLINE ZHLHRDB2 22ora.ons 23 ONLINE ONLINE ZHLHRDB1 24 ONLINE ONLINE ZHLHRDB2 25ora.registry.acfs 26 ONLINE ONLINE ZHLHRDB1 27 ONLINE ONLINE ZHLHRDB2 28-------------------------------------------------------------------------------- 29Cluster Resources 30-------------------------------------------------------------------------------- 31ora.LISTENER_SCAN1.lsnr 32 1 ONLINE ONLINE ZHLHRDB1 33ora.cvu 34 1 ONLINE ONLINE ZHLHRDB1 35ora.oc4j 36 1 ONLINE ONLINE ZHLHRDB1 37ora.scan1.vip 38 1 ONLINE ONLINE ZHLHRDB1 39ora.ZHLHRDB1.vip 40 1 ONLINE ONLINE ZHLHRDB1 41ora.ZHLHRDB2.vip 42 1 ONLINE ONLINE ZHLHRDB2 43[ZHLHRDB2:oracle]:/oracle>srvctl add database -h 44 45Adds a database configuration to the Oracle Clusterware. 46 47Usage: srvctl add database -d <db_unique_name> -o <oracle_home> [-c {RACONENODE | RAC | SINGLE} [-e <server_list>] [-i <inst_name>] [-w <timeout>]] [-m <domain_name>] [-p <spfile>] [-r {PRIMARY | PHYSICAL_STANDBY | LOGICAL_STANDBY | SNAPSHOT_STANDBY}] [-s <start_options>] [-t <stop_options>] [-n <db_name>] [-y {AUTOMATIC | MANUAL | NORESTART}] [-g "<serverpool_list>"] [-x <node_name>] [-a "<diskgroup_list>"] [-j "<acfs_path_list>"] 48 -d <db_unique_name> Unique name for the database 49 -o <oracle_home> ORACLE_HOME path 50 -c <type> Type of database: RAC One Node, RAC, or Single Instance 51 -e <server_list> Candidate server list for RAC One Node database 52 -i <inst_name> Instance name prefix for administrator-managed RAC One Node database (default first 12 characters of <db_unique_name>) 53 -w <timeout> Online relocation timeout in minutes 54 -x <node_name> Node name. -x option is specified for single-instance databases 55 -m <domain> Domain for database. Must be set if database has DB_DOMAIN set. 56 -p <spfile> Server parameter file path 57 -r <role> Role of the database (primary, physical_standby, logical_standby, snapshot_standby) 58 -s <start_options> Startup options for the database. Examples of startup options are OPEN, MOUNT, or 'READ ONLY'. 59 -t <stop_options> Stop options for the database. Examples of shutdown options are NORMAL, TRANSACTIONAL, IMMEDIATE, or ABORT. 60 -n <db_name> Database name (DB_NAME), if different from the unique name given by the -d option 61 -y <dbpolicy> Management policy for the database (AUTOMATIC, MANUAL, or NORESTART) 62 -g "<serverpool_list>" Comma separated list of database server pool names 63 -a "<diskgroup_list>" Comma separated list of disk groups 64 -j "<acfs_path_list>" Comma separated list of ACFS paths where database's dependency will be set 65 -h Print usage 66[ZHLHRDB2:oracle]:/oracle>echo $ORACLE_HOME 67/oracle/app/oracle/product/11.2.0/db 68[ZHLHRDB2:oracle]:/oracle>srvctl add database -d TESTDGPHY -c RAC -o /oracle/app/oracle/product/11.2.0/db -p '+DATA/TESTDGPHY/PARAMETERFILE/spfiledgphy.ora' -r physical_standby -n TESTDG -i DGPHY 69[ZHLHRDB2:oracle]:/oracle> 70[ZHLHRDB2:oracle]:/oracle>srvctl add instance -d TESTDGPHY -i DGPHY1 -n ZHLHRDB1 71[ZHLHRDB2:oracle]:/oracle>srvctl add instance -d TESTDGPHY -i DGPHY2 -n ZHLHRDB2 72[ZHLHRDB2:oracle]:/oracle>srvctl status database -d TESTDGPHY 73Instance DGPHY1 is not running on node ZHLHRDB1 74Instance DGPHY2 is not running on node ZHLHRDB2 75[ZHLHRDB2:oracle]:/oracle>srvctl start database -d TESTDGPHY 76[ZHLHRDB2:oracle]:/oracle>srvctl status database -d TESTDGPHY 77Instance DGPHY1 is running on node ZHLHRDB1 78Instance DGPHY2 is running on node ZHLHRDB2 79[ZHLHRDB2:oracle]:/oracle>srvctl config database -d TESTDGPH Y -a 80Database unique name: TESTDGPHY 81Database name: TESTDG 82Oracle home: /Oracle/app/Oracle/product/11.2.0/db 83Oracle user: Oracle 84Spfile: +DATA/TESTDGPHY/PARAMETERFILE/spfiledgphy.ora 85Domain: 86Start options: open 87Stop options: immediate 88Database role: PHYSICAL_STANDBY 89Management policy: AUTOMATIC 90Server pools: DGPHY 91Database instances: DGPHY1,DGPHY2 92Disk Groups: 93Mount point paths: 94Services: 95Type: RAC 96Database is enabled 97Database is administrator managed 98[ZHLHRDB2:oracle]:/oracle> 99[ZHLHRDB2:root]:/>crsctl stat res -t 100-------------------------------------------------------------------------------- 101NAME TARGET STATE SERVER STATE_DETAILS 102-------------------------------------------------------------------------------- 103Local Resources 104-------------------------------------------------------------------------------- 105ora.DATA.dg 106 ONLINE ONLINE ZHLHRDB1 107 ONLINE ONLINE ZHLHRDB2 108ora.LISTENER.lsnr 109 ONLINE ONLINE ZHLHRDB1 110 ONLINE ONLINE ZHLHRDB2 111ora.asm 112 ONLINE ONLINE ZHLHRDB1 Started 113 ONLINE ONLINE ZHLHRDB2 Started 114ora.gsd 115 OFFLINE OFFLINE ZHLHRDB1 116 OFFLINE OFFLINE ZHLHRDB2 117ora.net1.network 118 ONLINE ONLINE ZHLHRDB1 119 ONLINE ONLINE ZHLHRDB2 120ora.ons 121 ONLINE ONLINE ZHLHRDB1 122 ONLINE ONLINE ZHLHRDB2 123ora.registry.acfs 124 ONLINE ONLINE ZHLHRDB1 125 ONLINE ONLINE ZHLHRDB2 126-------------------------------------------------------------------------------- 127Cluster Resources 128-------------------------------------------------------------------------------- 129ora.LISTENER_SCAN1.lsnr 130 1 ONLINE ONLINE ZHLHRDB1 131ora.cvu 132 1 ONLINE ONLINE ZHLHRDB1 133ora.oc4j 134 1 ONLINE ONLINE ZHLHRDB1 135ora.scan1.vip 136 1 ONLINE ONLINE ZHLHRDB1 137ora.testdgphy.db 138 1 ONLINE ONLINE ZHLHRDB1 Open,Readonly 139 2 ONLINE ONLINE ZHLHRDB2 Open,Readonly 140ora.ZHLHRDB1.vip 141 1 ONLINE ONLINE ZHLHRDB1 142ora.ZHLHRDB2.vip 143 1 ONLINE ONLINE ZHLHRDB2 144
可以看到物理备库testdgphy已经添加到CRS中了。
本文选自《Oracle程序员面试笔试宝典》,作者:小麦苗
---------------优质麦课------------
详细内容可以添加麦老师微信或QQ私聊。
About Me:小麦苗
● 本文作者:小麦苗,只专注于数据库的技术,更注重技术的运用
● 作者博客地址:http://blog.itpub.net/26736162/abstract/1/
● 本系列题目来源于作者的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解
● 版权所有,欢迎分享本文,转载请保留出处
● QQ:646634621 QQ群:618766405
● 提供OCP、OCM和高可用部分最实用的技能培训
● 题目解答若有不当之处,还望各位朋友批评指正,共同进步
DBA宝典
长按下图识别二维码或微信扫描下图二维码来关注小麦苗的微信公众号:xiaomaimiaolhr,学习最实用的数据库技术。