1. 程式人生 > >Oracle11G DG 搭建及管理

Oracle11G DG 搭建及管理

一、準備工作

  1. 環境準備
  2. 主資料庫Oracle Database安裝
  3. 備伺服器Oracle Database software 安裝

二、正式配置ADG

三、ADG基本管理

--------------------------------------------------------------分割線-------------------------------------------------------------

一、準備工作

1.環境配置:

主機配置

 節點   作業系統 主機名稱        IP地址
 主庫 CentOS6.4_x86_64   dgp 192.168.10.61
 備庫 CentOS6.4_x86_64   dgs 192.168.10.62

 

 

 

 

修改主機名:

[root@db /]# cat /etc/sysconfig/network
[root@db /]# sed -i s/HOSTNAME=.*/HOSTNAME=dgp/ /etc/sysconfig/network
[root@db /]# reboot

 

規劃資料庫配置

 節點   Oracle版本   SID    db_name
db_unique_name
 主庫   11.2.0.4   orcl     orcl      orcl
 備庫   11.2.0.4   orcl     orcl      orcl_std

 

 

 

以上完成之後,對兩臺主機進行以下操作:

1)禁用防火牆

[root@dgp ~]# chkconfig iptables off
[root@dgp ~]# service iptables stop

2)禁用selinux

[root@dgp ~]# sed -i s/SELINUX=.*/SELINUX=disabled/ /etc/sysconfig/selinux
[root@dgp ~]# setenforce 0

3)配置host檔案

[root@dgp ~]# cat /etc/hosts
[root@dgp ~]# echo -e '192.168.10.61 dgp \n192.168.10.62 dgs' >>/etc/hosts

備註:echo -e 表示開啟轉義。

4)軟體準備

資料庫檔案如下:

p13390677_112040_Linux-x86-64_1of7.zip

p13390677_112040_Linux-x86-64_2of7.zip

建立路徑 /install路徑,上傳安裝檔案並解壓。

[root@dgp /]# mkdir /install
[root@dgp /]# cd /install
[root@dgp /]# unzip p13390677_112040_Linux-x86-64_1of7.zip
[root@dgp /]# unzip p13390677_112040_Linux-x86-64_1of7.zip

 

2.主資料庫Oracle Database安裝

配置最小引數

修改引數檔案/etc/sysctl.conf

 

[root@dgp /]# echo 'fs.suid_dumpable = 1
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 536870912
kernel.shmmni = 4096
# semaphores: semmsl, semmns, semopm, semmni
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default=262144
net.core.rmem_max=4194304
net.core.wmem_default=262144
net.core.wmem_max=1048586' >> /etc/sysctl.conf

 

 執行命令使配置生效

[root@dgp /]# /sbin/sysctl -p

修改limits.conf

新增以下內容到配置檔案/etc/security/limits.conf:

[root@db /]# echo 'oracle              soft    nproc   16384
oracle              hard    nproc   16384
oracle              soft    nofile  4096
oracle              hard    nofile  65536
oracle              soft    stack   10240' >> /etc/security/limits.conf

安裝必要的rpm包

[root@dgp /]# yum install -y binutils-2*x86_64* glibc-2*x86_64* nss-softokn-freebl-3*x86_64* glibc-2*i686* nss-softokn-freebl-3*i686* compat-libstdc++-33*x86_64*
yum install -y glibc-common-2*x86_64* glibc-devel-2*x86_64* glibc-devel-2*i686* glibc-headers-2*x86_64* elfutils-libelf-0*x86_64*
yum install -y elfutils-libelf-devel-0*x86_64* gcc-4*x86_64* gcc-c++-4*x86_64* ksh-*x86_64* libaio-0*x86_64*
yum install -y libaio-devel-0*x86_64* libaio-0*i686* libaio-devel-0*i686* libgcc-4*x86_64*  libgcc-4*i686* libstdc++-4*x86_64* libstdc++-4*i686* 
yum install -y libstdc++-devel-4*x86_64* make-3.81*x86_64* numactl-devel-2*x86_64* sysstat-9*x86_64* compat-libstdc++-33*i686* compat-libcap*

建立配置使用者

[root@dgp /]# groupadd -g 501 oinstall
groupadd -g 502 dba
groupadd -g 503 oper
groupadd -g 504 asmadmin
groupadd -g 506 asmdba
groupadd -g 505 asmoper
useradd -u 502 -g oinstall -G dba,asmdba,oper oracle
[root@dgp install]# passwd oracle
Changing password for user oracle.
New password:
BAD PASSWORD: it is too simplistic/systematic
Retype new password:
passwd: all authentication tokens updated successfully.

修改"/etc/security/limits.d/90-nproc.conf" 檔案中的內容

將 “* soft nproc 1024”這一行修改為“* - nproc 16384”

[root@dgp /]# cp /etc/security/limits.d/90-nproc.conf /etc/security/limits.d/90-nproc.conf_bak
[root@dgp /]# sed -i s/.*1024/*\ -\ nproc\ 16384/ /etc/security/limits.d/90-nproc.conf

建立資料庫安裝路徑

[root@dgp /]# mkdir -p /u01/app/oracle/product/11.2.0/db_1
chown -R oracle:oinstall /u01
chmod -R 775 /u01

登入oracle使用者,並在 ".bash_profile" 檔案尾部新增內容。

[root@dgp /]# su - oracle
[oracle@dgp /]$ pwd
[oracle@dgp /]$ cat >> .bash_profile <<'EOF'

#Oracle Settings TMP=/tmp; export TMP TMPDIR=$TMP; export TMPDIR ORACLE_HOSTNAME=dgp; export ORACLE_HOSTNAME ORACLE_UNQNAME=orcl; export ORACLE_UNQNAME ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1; export ORACLE_HOME ORACLE_SID=orcl; export ORACLE_SID PATH=/usr/sbin:$PATH; export PATH PATH=$ORACLE_HOME/bin:$PATH; export PATH LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH
EOF

備註:配置備庫時候:ORACLE_HOSTNAME=dgs  ORACLE_UNQNAME=orcl_std   ORACLE_SID=orcl

安裝資料庫

直接以Oracle使用者登入,執行安裝

[oracle@dgp /]$ cd /install/database、
[oracle@dgp /]$ ll
[oracle@dgp /]$ ./runInstaller

圖形介面忽略,過程中在root使用者下執行指令碼。

[root@dgp ~]# /u01/app/oraInventory/orainstRoot.sh
[root@dgp ~]# /u01/app/oracle/product/11.2.0/db_1/root.sh

 備註:主庫選擇安裝資料庫軟體和資料庫例項,備庫僅安裝資料庫軟體。

 

設定Oracle Database自啟動

修改/etc/oratab配置檔案中每一個重起標誌設定成Y:

[root@dgp /]# sed -i 's/\(orcl:\)\(.*:\)N/\1\2Y/' /etc/oratab

 建立自啟動配置檔案/etc/init.d/dbora:

[root@dgp /]# cat >> /etc/init.d/dbora <<EOF
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
ORA_HOME=/u01/app/oracle/product/11.2.0/db_1
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
case "$1" in
'start')
# Start the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
touch /var/lock/subsys/dbora
;;
'stop')
# Stop the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
rm -f /var/lock/subsys/dbora
;;
esac
EOF

賦予執行許可權,新增自啟動

[root@dgp ~]# chmod 750 /etc/init.d/dbora
chkconfig --add dbora
chkconfig dbora on

3.備伺服器Oracle Database software 安裝

備伺服器安裝software,過程參考主庫資料庫安裝過程。

 

二、正式配置ADG

1.主庫檢查歸檔模式等:

在主庫操作:
#檢視log_mode、force_logging、flashback_on
SQL> select name,log_mode,force_logging,flashback_on from v$database;

#切換成歸檔模式
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP MOUNT;
SQL> ALTER DATABASE ARCHIVELOG; #修改成歸檔模式

#開啟FORCE LOGGING
SQL> ALTER DATABASE FORCE LOGGING #開啟FORCE LOGGING
#修改歸檔日誌路徑(按需修改,這裡僅僅列出供參考)
#[oracle@dgp /]$ mkdir /u01/app/oracle/archivelog
#SQL> archive log list
#SQL> alter system set log_archive_dest_1='location=/u01/app/oracle/archivelog';  

SQL> alter database flashback on;  #開啟flashback on
SQL> ALTER DATABASE OPEN;


2.主庫新增SRL:

注意:standby redo log比 redo log 多一個,並且大小保持一致。
SQL> select * from v$log;
SQL> select * from v$logfile;
SQL> alter database add standby logfile group 11 '/u01/app/oracle/oradata/orcl/redo_std01.log' size 50M;
SQL> alter database add standby logfile group 12 '/u01/app/oracle/oradata/orcl/redo_std02.log' size 50M;
SQL> alter database add standby logfile group 13 '/u01/app/oracle/oradata/orcl/redo_std03.log' size 50M;
SQL> alter database add standby logfile group 14 '/u01/app/oracle/oradata/orcl/redo_std04.log' size 50M;

3.主庫修改引數:

#修改引數(可以用sql命令修改,也可以直接修改pfile檔案)
[oracle@dgp /]$ sqlplus / as sysdba
SQL >
alter system set log_archive_config='DG_CONFIG=(orcl,orcl_std)' scope=both;
alter system set log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl' scope=both;    #主庫log路徑 alter system set log_archive_dest_2='SERVICE=orcl_std  LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl_std' scope=both;  #備庫log路徑 alter system set log_archive_dest_state_1='enable' scope=both; alter system set log_archive_dest_state_2='enable' scope=both; # alter system set db_file_name_convert='/u01/oracle/datafile','/u01/oracle/datafile' scope=both; #主備路徑一致,忽略 # alter system set log_file_name_convert='/u01/oracle/onlinelog','/u01/oracle/onlinelog' scope=both; #主備路徑一致,忽略 alter system set fal_server='orcl_std' scope=both; alter system set fal_client='orcl' scope=both; alter system set standby_file_management='AUTO' scope=both;
alter system set db_unique_name='orcl' scope=both;

#檢查主庫pfile檔案initorcl.ora
[oracle@dgp /]$ cat /u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora
orcl.__db_cache_size=687865856
orcl.__java_pool_size=16777216
orcl.__large_pool_size=33554432
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=671088640
orcl.__sga_target=989855744
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=234881024
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.fal_client='orcl'
*.fal_server='orcl_std'
*.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=orcl'
*.log_archive_dest_2='SERVICE=orcl_std LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl_std'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.memory_target=1660944384
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.db_unique_name='orcl'
*.log_archive_config='DG_CONFIG=(orcl,orcl_std)'

檢查完成確認無誤後,重啟資料庫  
SQL> shutdown immediate
SQL> start nomount
SQL> create spfile from pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora'; #以pfile建立新的spfile
SQL> startup
SQL> show parameter spfile #確認以spfile啟動

備註:備庫的pfile、control file將安排和rman備份完成後建立,然後和其他檔案一起copy至備庫。

 

4.主庫配listener.ora和tnsname.ora

(1)主庫listener.ora配置:
[oracle@dgp admin]$ cat /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.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 = orcl)
  (SID_NAME = orcl)
  )
)

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dgp)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

(2)主庫tnsnames.ora配置:
[oracle@dgp admin]$ cat /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dgp)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

ORCL_STD =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dgs)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl_std)
    )
  )

(2)主庫監聽測試:
# [oracle@dgp ~]$ lsnrctl reload
[oracle@dgp ~]$ lsnrctl stop
[oracle@dgp ~]$ lsnrctl start
[oracle@dgp ~]$ lsnrctl status

[oracle@dgp ~]$ sqlplus system/****@orcl #測試是否正常

 
至此主庫的配置結束,下面將為備庫準備相關檔案。

5.RMAN備份主庫

#在主庫操作
[oracle@dgp ~]$ rman target /
RMAN> backup database plus archivelog

#備註:注意一下rman輸出內容中的備份檔案路徑
#備用命令: backup current controlfile for standby format '/XXX/dbbackup/CTL_%U'; backup database format '/XXX/dbbackup/DB_%d_%U' PLUS ARCHIVELOG;

 

6.建立備庫pfile檔案initorcl_std.ora

#在主庫操作
[oracle@dgp ~]$ cd /u01/app/oracle/product/11.2.0/db_1/dbs
[oracle@dgp ~]$ cp initorcl.ora initorcl_std.ora
#修改initorcl_std.ora中內容,修改後的內容見下面新的initorcl_std.ora
#紅色為DG相關引數,紅色綠底為修改過的內容
[oracle@dgp ~]$ cat initorcl_std.ora
orcl.__db_cache_size=687865856
orcl.__java_pool_size=16777216
orcl.__large_pool_size=33554432
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=671088640
orcl.__sga_target=989855744
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=234881024
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.fal_client='orcl_std'
*.fal_server='orcl'
*.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=orcl_std'
*.log_archive_dest_2='SERVICE=orcl LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.memory_target=1660944384
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.db_unique_name='orcl_std'
*.log_archive_config='DG_CONFIG=(orcl,orcl_std)'

 

7.建立備庫控制檔案

#在主庫操作
[oracle@dgp ~]$ sqlplus / as sysdba
SQL> ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/u01/app/oracle/fast_recovery_area/ORCL/backupset/orcl_stby.ctl'

 

8.傳輸檔案至備庫

需要copy至備庫的檔案有:rman備份、備庫pfile、備庫controlfile、listener.ora、tnsnames.ora、密碼檔案。

在備庫上建立必要目錄

在備庫操作:
[root@dgs ~]# su - oracle
[oracle@dgs ~]$ mkdir -p /u01/app/oracle/oradata/orcl/
[oracle@dgs ~]$ mkdir -p /u01/app/oracle/fast_recovery_area/orcl/
[oracle@dgs ~]$ mkdir -p /u01/app/oracle/admin/orcl/adump
[oracle@dgs ~]$ mkdir -p /u01/app/oracle/fast_recovery_area/ORCL/
#[oracle@dgs ~]$ mkdir /u01/app/oracle/archivelog #忽略
配置主庫oracle使用者免密登入備庫主機oracle使用者

在主庫操作: [oracle@dgp dbs]$ ssh-keygen #一直按回車 [oracle@dgp dbs]$ ssh-copy-id -i .ssh/id_rsa.pub oracle@dgs #輸入備庫oracle作業系統使用者密碼
開始copy檔案至備庫
# 1、controlfile 和 RMAN備份
[oracle@dgp ~]$ scp -r /u01/app/oracle/fast_recovery_area/ORCL/backupset oracle@dgs:/u01/app/oracle/fast_recovery_area/ORCL/
# 2、initorcl_std.ora 和 密碼檔案orapworcl
[oracle@dgp ~]$ scp /u01/app/oracle/product/11.2.0/db_1/dbs/initorcl_std.ora oracle@dgs:/u01/app/oracle/product/11.2.0/db_1/dbs/
[oracle@dgp ~]$ scp /u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl oracle@dgs:/u01/app/oracle/product/11.2.0/db_1/dbs/
#3、listener.ora 和 tnsnames.ora
[oracle@dgp ~]$ scp /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora oracle@dgs:/u01/app/oracle/product/11.2.0/db_1/network/admin/
[oracle@dgp ~]$ scp /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora oracle@dgs:/u01/app/oracle/product/11.2.0/db_1/network/admin/

#複製備庫控制檔案至initorcl_std.ora指定位置(還是在主庫操作,這裡在主庫ssh遠端登入執行命令,避免切換視窗)
[oracle@dgp oracle]$ ssh oracle@dgs cp /u01/app/oracle/fast_recovery_area/ORCL/backupset/orcl_stby.ctl /u01/app/oracle/oradata/orcl/control01.ctl
[oracle@dgp oracle]$ ssh oracle@dgs cp /u01/app/oracle/fast_recovery_area/ORCL/backupset/orcl_stby.ctl /u01/app/oracle/fast_recovery_area/orcl/control02.ctl


至此,除listener.ora有待修改,備庫的相關檔案準備完成,下面將進入最後配置階段。

9.備庫配置監聽

備庫操作:

(1)修改監聽件listener.ora
修改後檢視,其他紅色為修改的內容。
#注意:備庫的SID_NAME為orcl,因此備庫listener.ora靜態監聽SID_LIST_LISTENER中的配置SID_NAME = orcl,不能設為orcl_std,orcl_std是db_unique_name。
[oracle@dgs admin]$ cat /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.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 = orcl_std)
  (SID_NAME = orcl)
  )
)

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dgs)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

(2)備庫的tnsnames.ora和主庫一樣,無需修改
(3)重啟監聽並驗證
   在備庫:
    [oracle@dgs ~]$ lsnrctl stop
    [oracle@dgs ~]$ lsnrctl start
    [oracle@dgs ~]$ lsnrctl status
    [oracle@dgs ~]$ sqlplus sys/******@orcl as sysdba       #在備庫上登入主庫
    [oracle@dgs ~]$ sqlplus sys/******@orcl_std as sysdba    #在備庫上登入備庫
在主庫:
    [oracle@dgs ~]$ sqlplus sys/******@orcl as sysdba       #在主庫上登入主庫
    [oracle@dgs ~]$ sqlplus sys/******@orcl_std as sysdba    #在備庫上登入備庫

 

10.還原備庫

#確認一下,至此備庫相關檔案均已修改完成。

備庫RMAN恢復
[oracle@dgs oracle]$ export ORACLE_SID=orcl
[oracle@dgs oracle]$ sqlplus / as sysdba

SQL> create spfile from pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initorcl_std.ora'; #建立備庫spfile
SQL> startup mount;
SQL> show paramter spfile; #確認以spfile啟動
SQL> exit

[oracle@dgs oracle]$ rman target /
RMAN> alter database mount; #或者alter database mount standby database;
RMAN> restore database;
RMAN> recover database;

11.開啟同步並驗證

# 此時主庫資料庫處於open狀態,備庫處於mount狀態
(1)開啟同步:
在備庫操作
SQL> alter database open read only;
SQL> alter database recover managed standby database using current logfile disconnect from session;

(2)驗證

在主庫操作
SQL> create user mydb identified by ******;
SQL> alter system switch logfile;
在備庫操作
SQL> select username from dba_users where name='MYDB'

檢視備庫應用狀態
SQL> select thread#,sequence#,standby_dest,archived,applied,status from v$archived_log;

 

三、基本管理

1.檢查狀態
檢視資料庫狀態
select open_mode,protection_mode,database_role,switchover_status from v$database;
select max(sequence#) from v$log;--檢查兩邊的序列好,是否一致
     
主庫切換日誌,
alert system switch logfile;

檢視備庫應用狀態
select thread#,sequence#,standby_dest,archived,applied,status from v$archived_log;

檢視有沒有GAP
select * from v$archive_dest_status where dest_id=2;
select status,gap_status from v$archive_dest_status where dest_id=2;

備庫檢視RFS接收日誌和MRP應用日誌同步主庫情況

select process, sequence#,GROUP#,thread#,status,delay_mins from v$managed_standby;  #備庫查詢其中,其中ARCH是歸檔程序,RFS是歸檔傳輸程序,MRP0是日誌應用程序

備庫檢視日誌應用進度及資料庫模式

select dbid,name,open_mode,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status from v$database;

2.啟動資料庫:
--先啟備庫
sql>startup nomount
sql>alter database mount standby database;
sql>alter database open;                 #或者alter database open read only;
sql>alter database recover managed standby database using current logfile disconnect from session;
        
--再啟主庫
sql>startup

3.關閉資料庫
--先關主庫: sql>shutdown immediate
--再關備用庫: sql>alter database recover managed standby database cancel; --停止同步 sql>shutdown immediate;

4.主備切換
待續。。。。。。

&n