Oracle学习之DATAGUARD(十)在同台机器上使用11grman新特性创建DG
首先使用dbca建立一个数据库,db_name=primary 。
专注于为中小企业提供网站设计制作、成都做网站服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业清丰免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了1000+企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
2. 为两个数据库准备静态监听。及连接彼此的TNSNAME
11gdg1-> cat listener.ora tnsnames.ora # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora # Generated by Oracle configuration tools. SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = primary) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = primary) ) (SID_DESC = (GLOBAL_DBNAME = standby) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = standby) ) ) LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 11gdg1.localdomain.com)(PORT = 1521)) ) ADR_BASE_LISTENER = /u01/app/oracle # tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. PRIMARY = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.199.216)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = primary) ) ) STANDBY = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.199.216)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = standby) ) ) 11gdg1->
3. 为从库创建一个简单的pfile
11gdg1-> echo "db_name=whatever" > initstandby.ora
4. 为从库创建口令文件
11gdg1-> cp orapwprimary orapwstandby
5. 建立从库需要的目录
11gdg1->mkdir -p /u01/app/oracle/admin/standby/adump 11gdg1->mkdir -p /u01/app/oracle/oradata/standby 11gdg1->mkdir -p /u01/app/oracle/fast_recovery_area/standby
6. 启动从数据库到mount
7. 将主库改为FORCE LOGGING
SQL> alter database force logging; Database altered.
8. 开启主库归档
SQL> archive log list Database log mode No Archive Mode Automatic archival Disabled Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 1 Current log sequence 2 SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount ORACLE instance started. Total System Global Area 839282688 bytes Fixed Size 2233000 bytes Variable Size 494931288 bytes Database Buffers 339738624 bytes Redo Buffers 2379776 bytes Database mounted. SQL> alter database archivelog; Database altered. SQL> alter database open; Database altered.
9. 创建standby log
ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/primary/sredo01.log' size 50M; ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/primary/sredo02.log' size 50M; ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/primary/sredo03.log' size 50M; ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/primary/sredo04.log' size 50M;
10. 创建standby数据库
run { allocate channel prmy1 type disk; allocate channel prmy2 type disk; allocate channel prmy3 type disk; allocate channel prmy4 type disk; allocate channel prmy5 type disk; allocate auxiliary channel stby1 type disk; duplicate target database for standby from active database spfile parameter_value_convert 'primary','standby' set 'db_unique_name'='standby' set control_files='/u01/app/oracle/oradata/standby/control01.ctl' set db_recovery_file_dest='/u01/app/oracle/fast_recovery_area' set DB_RECOVERY_FILE_DEST_SIZE='4G' set log_file_name_convert='/primary/','/standby/' set db_file_name_convert='/primary/','/standby/' set fal_server='primary' set standby_file_management='AUTO' set log_archive_config='dg_config=(primary,standby)' set log_archive_dest_2='service=primary LGWR ASYNC valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=primary' nofilenamecheck; sql channel prmy1 "alter system set log_archive_config=''dg_config=(primary,standby)''"; sql channel prmy1 "alter system set log_archive_dest_2=''service=standby LGWR ASYNC valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=standby''"; sql channel prmy1 "alter system set log_archive_max_processes=5"; sql channel prmy1 "alter system set fal_server=standby"; sql channel prmy1 "alter system set standby_file_management=AUTO"; sql channel prmy1 "alter system archive log current"; allocate auxiliary channel stby type disk; sql channel stby "alter database recover managed standby database using current logfile disconnect"; }
11. 验证数据同步
主库
SQL> conn / as sysdba Connected. SQL> alter user scott account unlock; User altered. SQL> alter user scott identified by tiger; User altered. SQL> conn scott/tiger Connected. SQL> create table t1 as select * from emp; Table created.
从库
SQL> alter database recover managed standby database cancel; Database altered. SQL> alter database open; Database altered. SQL> conn scott/tiger Connected. SQL> select count(*) from t1; COUNT(*) ---------- 14
标题名称:Oracle学习之DATAGUARD(十)在同台机器上使用11grman新特性创建DG
网站链接:http://pwwzsj.com/article/ippjss.html