首先使用dbca建立一個(gè)數(shù)據(jù)庫(kù),db_name=primary 。
專注于為中小企業(yè)提供網(wǎng)站設(shè)計(jì)制作、成都做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)清豐免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了1000+企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
2. 為兩個(gè)數(shù)據(jù)庫(kù)準(zhǔn)備靜態(tài)監(jiān)聽。及連接彼此的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. 為從庫(kù)創(chuàng)建一個(gè)簡(jiǎn)單的pfile
11gdg1-> echo "db_name=whatever" > initstandby.ora
4. 為從庫(kù)創(chuàng)建口令文件
11gdg1-> cp orapwprimary orapwstandby
5. 建立從庫(kù)需要的目錄
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. 啟動(dòng)從數(shù)據(jù)庫(kù)到mount
7. 將主庫(kù)改為FORCE LOGGING
SQL> alter database force logging; Database altered.
8. 開啟主庫(kù)歸檔
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. 創(chuàng)建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. 創(chuàng)建standby數(shù)據(jù)庫(kù)
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. 驗(yàn)證數(shù)據(jù)同步
主庫(kù)
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.
從庫(kù)
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