1. 程式人生 > >oracle system表空間的管理

oracle system表空間的管理

1、空間管理(字典所在,定義資訊,不放使用者資料)
單個數據檔案即可
設定自動擴充套件,設定bigfile
2、system如何備份
必須歸檔下才能在open下完成備份
a、熱備 b、rman備
非歸檔下只能進行冷備
使用archive log list命令檢視資料庫是否為歸檔模式:

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

熱備操作:
SQL> alter tablespace system begin backup;

Tablespace altered.

SQL> ho cp /u01/app/oracle/oradata/orcl/system01.dbf /u01/app/oracle/bak/system01.dbf

SQL> alter tablespace system end backup;

Tablespace altered.

RMAN備操作:

[[email protected] bak]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Apr 24 11:48:48 2017

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1445346880)

RMAN> backup tablespace system;

Starting backup at 24-APR-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=17 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
channel ORA_DISK_1: starting piece 1 at 24-APR-17
channel ORA_DISK_1: finished piece 1 at 24-APR-17
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_04_24/o1_mf_nnndf_TAG20170424T114901_dhtxfg5p_.bkp tag=TAG20170424T114901 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 24-APR-17
channel ORA_DISK_1: finished piece 1 at 24-APR-17
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_04_24/o1_mf_ncsnf_TAG20170424T114901_dhtxh8g7_.bkp tag=TAG20170424T114901 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 24-APR-17

RMAN> 

3、system表出現問題,如何恢復
a、歸檔 有備份 日誌完整 可以恢復
b、歸檔 有備份 日誌不完整 可以恢復,不能保證資料不丟失

熱備恢復:
SQL> startup
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2217952 bytes
Variable Size             624953376 bytes
Database Buffers          205520896 bytes
Redo Buffers                2412544 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl/system01.dbf'


SQL> ho cp /u01/app/oracle/oracle/bak/system01.dbf /u01/app/oracle/oradata/orcl/system01.dbf

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl/system01.dbf'


SQL> recover database;
Media recovery complete.
SQL> alter database open;

Database altered.

RMAN備恢復:

SQL> startup;
    ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2217952 bytes
Variable Size             624953376 bytes
Database Buffers          205520896 bytes
Redo Buffers                2412544 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl/system01.dbf'


SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[[email protected] ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Apr 24 12:48:15 2017

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1445346880, not open)

RMAN> list backup;

using target database control file instead of recovery catalog

List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1       Full    588.09M    DISK        00:00:36     19-APR-17      
        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20170419T115143
        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_04_19/o1_mf_nnndf_TAG20170419T115143_dhfqphqg_.bkp
  List of Datafiles in backup set 1
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1044250    19-APR-17 /u01/app/oracle/oradata/orcl/system01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2       Full    9.36M      DISK        00:00:04     19-APR-17      
        BP Key: 2   Status: AVAILABLE  Compressed: NO  Tag: TAG20170419T115143
        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_04_19/o1_mf_ncsnf_TAG20170419T115143_dhfqr17l_.bkp
  SPFILE Included: Modification time: 19-APR-17
  SPFILE db_unique_name: ORCL
  Control File Included: Ckp SCN: 1044266      Ckp time: 19-APR-17

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3       Full    589.84M    DISK        00:00:41     20-APR-17      
        BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20170420T142552
        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_04_20/o1_mf_nnndf_TAG20170420T142552_dhjo3jv0_.bkp
  List of Datafiles in backup set 3
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1089734    20-APR-17 /u01/app/oracle/oradata/orcl/system01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4       Full    9.36M      DISK        00:00:01     20-APR-17      
        BP Key: 4   Status: AVAILABLE  Compressed: NO  Tag: TAG20170420T142552
        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_04_20/o1_mf_ncsnf_TAG20170420T142552_dhjo4z8l_.bkp
  SPFILE Included: Modification time: 20-APR-17
  SPFILE db_unique_name: ORCL
  Control File Included: Ckp SCN: 1093814      Ckp time: 20-APR-17

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
5       Full    593.09M    DISK        00:00:49     24-APR-17      
        BP Key: 5   Status: AVAILABLE  Compressed: NO  Tag: TAG20170424T114901
        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_04_24/o1_mf_nnndf_TAG20170424T114901_dhtxfg5p_.bkp
  List of Datafiles in backup set 5
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1268534    24-APR-17 /u01/app/oracle/oradata/orcl/system01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
6       Full    9.36M      DISK        00:00:03     24-APR-17      
        BP Key: 6   Status: AVAILABLE  Compressed: NO  Tag: TAG20170424T114901
        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_04_24/o1_mf_ncsnf_TAG20170424T114901_dhtxh8g7_.bkp
  SPFILE Included: Modification time: 24-APR-17
  SPFILE db_unique_name: ORCL
  Control File Included: Ckp SCN: 1268564      Ckp time: 24-APR-17

RMAN> restore tablespace system;

Starting restore at 24-APR-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_04_24/o1_mf_nnndf_TAG20170424T114901_dhtxfg5p_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_04_24/o1_mf_nnndf_TAG20170424T114901_dhtxfg5p_.bkp tag=TAG20170424T114901
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 24-APR-17

RMAN> recover tablespace system;

Starting recover at 24-APR-17
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 24-APR-17

RMAN> sql 'alter database open';

sql statement: alter database open

4、system表空間不可只讀、不可離線

SQL> alter tablespace system read only
  2  ;
alter tablespace system read only
*
ERROR at line 1:
ORA-01643: system tablespace can not be made read-only


SQL> alter tablespace system offline;
alter tablespace system offline
*
ERROR at line 1:
ORA-01541: system tablespace cannot be brought offline; shut down if necessary


SQL>