以权限最高用户身份进入数据库
SQL> conn / as sysdba
Connected to an idle instance.
启动数据库
SQL> startup
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 96470608 bytes
Database Buffers 184549376 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SQL> set lines 1000 pages 1000
查看是否在归档模式下
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 4
查看数据库默认归档日志存放目录
SQL> show parameter recover
NAME TYPE VALUE
----------------------------------------------------------------------------------------------------------------------------
db_recovery_file_dest string /opt/oracle/flash_recovery_area
db_recovery_file_dest_size big integer 2G
recovery_parallelism integer 0
数据库归档方式配置
1. 正常关闭数据库
SQL> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
2. 启动数据库到加载状态
SQL> startup mount
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 96470608 bytes
Database Buffers 184549376 bytes
Redo Buffers 2973696 bytes
Database mounted.
3. 修改数据库为归档模式
SQL> alter database archivelog;
Database altered.
4. 查看归档模式是否被修改
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 2
Next log sequence to archive 4
Current log sequence 4
5. 修改归档路径(可选)
先在oracle家目录创建一个目录archive专门放归档日志
[oracle@lukai ~]$ mkdir archive
[oracle@lukai ~]$ ls -l
total 8
drwxr-xr-x 2 oracle oinstall 4096 Jul 25 11:12 archive
-rw-r--r-- 1 oracle oinstall 2079 Jul 17 01:12 sqlnet.log
然后修改归档路径
SQL> alter system set log_archive_dest_1='location=/home/oracle/archive' scope=both;
System altered.
6. 打开数据库查看数据库归档状态
SQL> alter database open;
Database altered.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/archive
Oldest online log sequence 2
Next log sequence to archive 4
Current log sequence 4
7. 切换日志,看是否生效
首先去刚才创建的归档目录下查看现在是否有归档日志
[oracle@lukai ~]$ cd archive/
[oracle@lukai archive]$ ls
[oracle@lukai archive]$
然后在切换日志
SQL> alter system switch logfile;
System altered.
再次去刚才在oracle家目录创建archive下查看是否生成归档日志
[oracle@lukai archive]$ ls -l
total 592
-rw-r----- 1 oracle oinstall 598528 Jul 25 11:18 1_4_692409988.dbf
注意:Oracle数据库在ARCHIVELOG(归档日志)方式下,可实施在线日志的归档备份,以便以后数据库发生故障时对数据库实现数据恢复,但数据库运行在此模式下,会产生大量的归档日志(archived redo log),并且耗费大量硬盘空间,一般建议启用此模式时,将归档日志转移到磁带机上,或者定期将归档日志转移到其他存储介质中。