Oracle DataGuard(Physical)的一些管理命令

1.         设置主站点为FORCE LOGGING模式;
Alter DATABASE FORCE LOGGING;
2.         设置归档模式,在整个DATAGUARD环境中,不允许出现非归档模式,因此以后导数据之类的工作不能改到非归档模式下做,否则dataguard需要重做。
a)       打开 /关闭自动归档
alter system set log_archive_start=true  scope=spfile;
alter system set log_archive_start=false  scope=spfile;
alter system archive log start; --打开自动归档
alter system archive log stop; --关闭自动归档
 
b)       打开 /关闭归档日志状态
Shutdown immediate
Startup mount
alter database archivelog;      --打开
alter database noarchivelog;     --关闭
alter database open;
 
3.         做数据库的冷备份
a)         关闭数据库;
Shutdown immediate
b)        拷贝数据文件等等;
执行下面的查询,可以看到数据文件的路径,
Select name from v$datafile;
c)        重新打开数据库;
Startup
4.         创建standby控制文件
alter database create standby controlfile as '/orasoft/app/oradata/oracl/control01.ctl';
5.         创建pfile;
create pfile from spfile;
以上 3 4 5 步骤文件均拷贝至 standby 服务器上;
6.         在主节点/standby节点分别配制相关的tnsnames.ora
TJJ650 =
 (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.72)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orACL)
    )
 )
 
TJJ570 =
 (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.85)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orACL)
    )
 )
7.         standby_archive_dest,log_archive_dest_1, log_archive_dest_2参数
standby_archive_dest
指定来自一个主服务器的归档日志传送到standby服务器的到达位置。
standby_archive_dest=/orasoft/app/archive
 
log_archive_dest_1
指定本地 (指定 LOCATION) 归档日志的存放目标位置
log_archive_dest_1= 'LOCATION=/orasoft/app/archive'
 
log_archive_dest_2
指定远程 (指定 SERVICE) 归档日志的存放目标位置,此地SERVICE的配置与tnsnames.ora中相一致
log_archive_dest_2= 'SERVICE=TJJ570'
log_archive_dest_2= 'SERVICE=TJJ650'
 
8.         启动备用数据库
SQL> STARTUP NOMOUNT;
SQL> Alter DATABASE MOUNT STANDBY DATABASE;
SQL> Alter DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
9.       关闭备用数据库
SQL> Alter DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> SHUTDOWN IMMEDIATE;
10.  只读方式打开备用数据库
a)      从关闭状态打开;
SQL> STARTUP NOMOUNT;
SQL> Alter DATABASE MOUNT STANDBY DATABASE;
SQL> Alter DATABASE OPEN READ ONLY;
b)      从正在恢复状态只读打开;
SQL> Alter DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> Alter DATABASE OPEN READ ONLY;
c)      切换回到恢复状态;
SQL> Alter DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
 
11.     主备数据库切换
a)         正常切换:(即主备服务器均可用的情况下,需维护主服务器的情况下):
主服务器:
SQL> alter database commit to switchover to physical standby;
SQL> shutdown immediate
SQL> startup nomount
SQL> alter database mount standby database;
SQL> Alter DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
 
备用服务器:
SQL> alter database commit to switchover to primary;
SQL> shutdown immediate;
SQL> startup
 
b)        非正常切换:(即主服务器当机的情况):
备用服务器:
SQL> Alter DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;
SQL> Alter DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP;
 
12.     验证及测试
SQL> Select SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG orDER BY SEQUENCE#;
SQL> Select SEQUENCE#, APPLIED FROM V$ARCHIVED_LOG orDER BY SEQUENCE#;
上述两个SQL是测试standby数据库的归档日志接受和恢复情况
 
SQL> Select TO_CHAR(TIMESTAMP,'YYYY-MM-DD HH24:MI:SS'), MESSAGE FROM V$DATAGUARD_STATUS order by TIMESTAMP;
 
上述SQL 查看最新 STANDBY 的状态信息
 
select database_role from v$database;
上述SQL 查看当前数据库的角色状态;
 

你可能感兴趣的:(oracle,职场,休闲)