查看Oracle是否归档和修改归档模式

查看Oracle是否归档和修改归档模式

1 开启归档日志
1.1 查看状态


查看归档状态

SQL> archive log list;
Database log mode           No Archive Mode
Automatic archival           Disabled
Archive destination           USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     2
Current log sequence           3


查看节点实例状态

 SQL> select instance_name,host_name,status from v$instance;
 
INSTANCE_NAME     HOST_NAME            STATUS
---------------- ------------------------------ ------------
oradb2              rac2                OPEN
oradb1              rac1                OPEN


查看数据库集群参数

SQL> show parameter cluster;

NAME                           TYPE         VALUE
------------------------------------ ----------- ------------------------------
cluster_database                boolean     TRUE
cluster_database_instances      integer     2
cluster_interconnects           string

1.2 修改参数

备份参数文件

SQL> create pfile='/tmp/racdb-bak.ora' from spfile;
File created.


修改cluster_database参数
将rac设置成单实例模式


SQL> alter system set cluster_database=false scope=spfile sid='*';
System altered.


1.3 开启归档

切换到grid用户,两节点停止数据库,再从节点1启动到mount状态

[grid@rac1 ~]$ srvctl stop database -d oradb
[grid@rac1 ~]$ srvctl start instance -d oradb -i oradb1 -o mount


切换到oracle用户,查询节点1数据库实例状态


SQL> select instance_name,status from v$instance;
INSTANCE_NAME     STATUS
---------------- ------------
oradb1         MOUNTED


修改数据库成归档模式


SQL> alter database archivelog;
Database altered.


将集群参数修改回去


SQL> alter system set cluster_database=true scope=spfile sid='*';
System altered.


关闭节点1数据库


SQL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.


切换到grid用户,再启动两节点数据库

[grid@rac1 ~]$ srvctl start database -d oradb
[grid@rac1 ~]$ srvctl status database -d oradb
Instance oradb1 is running on node rac1
Instance oradb2 is running on node rac2


切换到oracle用户下,查看归档状态

SQL> archive log list;
Database log mode           Archive Mode
Automatic archival           Enabled
Archive destination           USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     29
Next log sequence to archive   30
Current log sequence           30

SQL> select name,log_mode from v$database;
NAME      LOG_MODE
--------- ------------
ORADB      ARCHIVELOG

2 修改归档路径
2.1 在asm目录中查看归档目录
[grid@rac1 ~]$ asmcmd
ASMCMD> ls
DATA/
FRA/
OCR/
ASMCMD> cd fra 
ASMCMD> ls
ORADB/
ASMCMD> cd oradb
ASMCMD> ls
ARCHIVELOG/
CONTROLFILE/
ONLINELOG/
ASMCMD> cd archivelog
ASMCMD> ls
2019_05_28/
ASMCMD> cd 2019_05_28
ASMCMD> ls
thread_2_seq_3.261.1009460089
ASMCMD> pwd
+fra/oradb/archivelog/2019_05_28


2.2 修改归档路径

修改归档路径

SQL> alter system set log_archive_dest_1='location=+fra/oradb/archivelog/' scope=spfile sid='*';
System altered.
12

重启两节点数据库

[grid@rac1 ~]$ srvctl stop database -d oradb[grid@rac1 ~]$ srvctl start database -d oradb


重新查看归档状态

SQL> archive log list;
Database log mode           Archive Mode
Automatic archival           Enabled
Archive destination           +FRA/oradb/archivelog/
Oldest online log sequence     29
Next log sequence to archive   30
Current log sequence           30


再次查看归档目录下的文件

ASMCMD> ls
thread_1_seq_30.262.1009460447
thread_2_seq_3.261.1009460089
thread_2_seq_4.263.1009460489
thread_2_seq_5.264.1009460491
————————————————