linux中oracle如何打开归档模式并设置归档路径

发布时间:


linuxoracle如何打开归档模式
大家都知道,默认安装oracle数据中后,数据库的归档日志是非开启状态。对于生产库来说,一定要开启归档模式,这样才能确保在发生误操作行为后,通过归档日志来快速恢复数据,对数据安全有十分重要的意义。
windows环境中启动数据库的归档模式一般来说很简单,只需要简单的几个命令即可实现。但是对于linux操作系统,很多用户都是陌生状态,完全不知道如何操作。只因为对linux系统操作不熟练而导致的。废话不多说。下面就介绍干货,真实操作实验记录,需要对大家有所帮助。
首先需要登录linux数据库。我们一般的远程工具是xshell,输linux对应服务器ip地址已经用户、密码和端口(一般端口为22点击连接即可登录,这里切记,一定要是用oracle用户登录。登录后需要先登录的数据库中。为便于区分,下面将输入的命令用红色加粗字体显示。
[oracle@rac ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Nov 19 09:37:19 2018 Copyright (c 1982, 2013, Oracle.
All rights reserved.
Connected to:



Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options 登录数据库后,我们用命令查看该数据库是否处于open状态。
SQL> select instance_name,status from v$instance;

INSTANCE_NAME ---------------- ------------ racdb

OPEN
STATUS 由此可见该数据库实例是open状态。接下来查看归档模式,是否为开启状态。
SQL>archive log list Database log mode Automatic archival Archive destination No Archive Mode
Disabled
USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 216 Current log sequence
218 从执行结果来看,数据库日志模式为“非存档模式”,自动存档状态为“禁用”状态。这个时候就需要手动调整设置,开启归档模式。
这里,特别需要强调的是,开启归档模式操作,是需要关闭数据库的,会造成停机,导致业务无法正常访问数据库。一定要提前与用



户沟通,切勿直接关闭。
确定无误后,使用shutdown immediate关闭数据库
SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. 此时,Oracle 例程已经关闭。关闭后启动oracle例程。
SQL> startup mount; ORACLE instance started.
Total System Global Area 534462464 bytes Fixed Size
2254952 bytes
255854488 bytes Variable Size
Database Buffers 264241152 bytes Redo Buffers
12111872 bytes Database mounted. SQL>
SQL> 启动oracle例程后,使用命令修改数据库归档模式
SQL> alter database open;




Database altered. SQL>
SQL> alter database open;
Database altered. SQL>
SQL> 开启归档模式后,同步打开数据库。我们需要特别强调一点:支持归档日志在闪回区下的备份恢复,因闪回区空间有限,请确保闪回区空间足够大并实时监控闪回区空间利用率。也可将归档路径设置为本地路径,注意Oracle数据库的安装用户必须对归档路径有读写权限,同时归档路径所在的文件系统,要有足够的空间。如果空间过少,可能会存在因为归档日志爆满导致数据库无法正常启动的情况。切记切记。
退出数据库登陆状态,进入需要创建归档日志的文件夹。
SQL> exit Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production



With the Partitioning, OLAP, Data Mining and Real Application Testing options [oracle@rac ~]$ [oracle@rac ~]$
[oracle@rac ~]$ cd /datafile; [oracle@rac datafile]$ datafile文件存储空间是5T的,足够用,所以将归档日志放到这里,我创建一个文件夹arch专门存放归档日志。
[oracle@rac datafile]$ mkdir -p /datafile/arch [oracle@rac datafile]$ [oracle@rac datafile]$ [oracle@rac datafile]$ ls arch lost+found [oracle@rac datafile]$ [oracle@rac datafile]$
创建arch文件后,需要查看oracle用户和组是否对该文件夹拥有操作权限。如果没有用chowd命令增加权限。
[oracle@rac datafile]$ ls -l /datafile/ |grep arch
drwxr-xr-x. 2 oracle oinstall 4096 11 19 09:41 arch [oracle@rac datafile]$ [oracle@rac datafile]$ [oracle@rac datafile]$



[oracle@rac datafile]$ chown -R oracle:oinstall /datafile/arch/ [oracle@rac datafile]$ [oracle@rac datafile]$ [oracle@rac datafile]$
[oracle@rac datafile]$ ls -l /datafile/ |grep arch
drwxr-xr-x. 2 oracle oinstall 4096 11 19 09:41 arch [oracle@rac datafile]$ 我们可以看看创建arch文件的可用空间。
[oracle@rac datafile]$
[oracle@rac datafile]$ df -h /datafile/arch Filesystem Size Used Avail Use% Mounted on /dev/mapper/mpathcp2 4.5T 363G 3.9T 9% /datafile [oracle@rac datafile]$
[oracle@rac datafile]$ 登录数据库后,采用命令修改归档路径
[oracle@rac datafile]$
[oracle@rac datafile]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Nov 19 09:44:04 2018
Copyright (c 1982, 2013, Oracle.
All rights reserved.




Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> alter system set log_archive_dest_1='location=/datafile/arch' scope=both;
System altered. SQL>
SQL> 细心的大家肯定会发现,log_archive_dest后我们单独添加了_1目的是和数据库默认的名称做区别,避免冲突或其他潜在的报错。置完成后我们查下一遍归档日志,确保归档路径是我们设定的路径是成功的。
SQL>
SQL> archive log list; Database log mode Automatic archival Archive destination Archive Mode Enabled
/datafile/arch Oldest online log sequence
216



Next log sequence to archive 218 Current log sequence 218 SQL> SQL>
为进一步确保归档模式设置的有效性,执行下述命令后,在该归档路径中查看是否有生成归档日志,如果产生了归档log文件就说明归档模式成功设置了。
SQL>
SQL> alter system switch logfile;
System altered. SQL> SQL> exit Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options [oracle@rac datafile]$
[oracle@rac datafile]$ cd /datafile/arch [oracle@rac arch]$ ls 1_218_992012561.dbf [oracle@rac arch]$


到此,linuxoracle数据库归档模式就彻底设置完成了


linux中oracle如何打开归档模式并设置归档路径

相关推荐