關於v$datafile和v$tempfile中的file#

v$datafile視圖中存儲的是有關數據文件的信息,v$tempfile視圖中存儲的是有關臨時文件的信息。在兩個視圖中都有file#字段,先來看一下官方文檔的定義:

V$DATAFILE

This view contains datafile information from the control file.

See Also:

"V$DATAFILE_HEADER", which displays information from datafile headers
Column Datatype Description
FILE# NUMBER File identification number
CREATION_CHANGE# NUMBER Change number at which the datafile was created
CREATION_TIME DATE Timestamp of the datafile creation
TS# NUMBER Tablespace number
RFILE# NUMBER Tablespace relative datafile number
STATUS VARCHAR2(7) Type of file (system or user) and its status. Values: OFFLINEONLINESYSTEMRECOVERSYSOFF (an offline file from the SYSTEM tablespace)
ENABLED VARCHAR2(10) Describes how accessible the file is from SQL:
  • DISABLED - No SQL access allowed

  • READ ONLY - No SQL updates allowed

  • READ WRITE - Full access allowed

  • UNKNOWN - should not occur unless the control file is corrupted

CHECKPOINT_CHANGE# NUMBER SCN at last checkpoint
CHECKPOINT_TIME DATE Timestamp of the checkpoint#
UNRECOVERABLE_CHANGE# NUMBER Last unrecoverable change number made to this datafile. If the database is in ARCHIVELOG mode, then this column is updated when an unrecoverable operation completes. If the database is not in ARCHIVELOG mode, this column does not get updated.
UNRECOVERABLE_TIME DATE Timestamp of the last unrecoverable change. This column is updated only if the database is in ARCHIVELOG mode.
LAST_CHANGE# NUMBER Last change number made to this datafile (null if the datafile is being changed)
LAST_TIME DATE Timestamp of the last change
OFFLINE_CHANGE# NUMBER Offline change number of the last offline range. This column is updated only when the datafile is brought online.
ONLINE_CHANGE# NUMBER Online change number of the last offline range
ONLINE_TIME DATE Online timestamp of the last offline range
BYTES NUMBER Current datafile size (in bytes); 0 if inaccessible
BLOCKS NUMBER Current datafile size (in blocks); 0 if inaccessible
CREATE_BYTES NUMBER Size when created (in bytes)
BLOCK_SIZE NUMBER Block size of the datafile
NAME VARCHAR2(513) Name of the datafile
PLUGGED_IN NUMBER Describes whether the tablespace is plugged in. The value is 1 if the tablespace is plugged in and has not been made read/write, 0 if not.
BLOCK1_OFFSET NUMBER Offset from the beginning of the file to where the Oracle generic information begins. The exact length of the file can be computed as follows:BYTES + BLOCK1_OFFSET.
AUX_NAME VARCHAR2(513) Auxiliary name that has been set for this file via CONFIGURE AUXNAME
FIRST_NONLOGGED_SCN NUMBER First nonlogged SCN
FIRST_NONLOGGED_TIME DATE First nonlogged time


V$TEMPFILE

This view displays tempfile information.

Column Datatype Description
FILE# NUMBER Absolute file number
CREATION_CHANGE# NUMBER Creation System Change Number (SCN)
CREATION_TIME DATE Creation time
TS# NUMBER Tablespace number
RFILE# NUMBER Relative file number in the tablespace
STATUS VARCHAR2(7) Status of the file (OFFLINE|ONLINE)
ENABLED VARCHAR2(10) Enabled for read and/or write
BYTES NUMBER Size of the file in bytes (from the file header)
BLOCKS NUMBER Size of the file in blocks (from the file header)
CREATE_BYTES NUMBER Creation size of the file (in bytes)
BLOCK_SIZE NUMBER Block size for the file
NAME VARCHAR2(513) Name of the file

從上面的文檔可以看出,在v$tempfile和v$datafile中file#均代表絕對文件好,而rfile#代表相對文件號,下面來驗證一下:

SQL> l
  1* select file#,name from v$tempfile
SQL> /

     FILE# NAME
---------- ------------------------------------------------------------
	 1 /home/app/oraten/oradata/oraten/temp01.dbf

SQL> select file#,name from v$datafile;

     FILE# NAME
---------- ------------------------------------------------------------
	 1 /home/app/oraten/oradata/oraten/system01.dbf
	 2 /home/app/oraten/oradata/oraten/undotbs01.dbf
	 3 /home/app/oraten/oradata/oraten/sysaux01.dbf
	 4 /home/app/oraten/oradata/oraten/users01.dbf
	 5 /home/app/oraten/oradata/oraten/test01.dbf
在v$datafile和v$tempfile中都存在絕對文件號爲1的文件,這顯然是不對的。

我們知道在文件無法訪問時,oracle會報錯並在錯誤信息中顯示有關文件的信息,下面我們來模擬臨時文件的故障

[oraten@yue oraten]$ chmod 000 temp01.dbf 
[oraten@yue oraten]$ ll
總用量 932180
-rw-r----- 1 oraten dba   7061504 11月  7 13:59 control01.ctl
-rw-r----- 1 oraten dba   7061504 11月  7 13:59 control02.ctl
-rw-r----- 1 oraten dba   7061504 11月  7 13:59 control03.ctl
-rw-r----- 1 oraten dba  52429312 11月  7 13:44 redo01.log
-rw-r----- 1 oraten dba  52429312 11月  7 13:54 redo02.log
-rw-r----- 1 oraten dba  52429312 11月  7 13:44 redo03.log
-rw-r----- 1 oraten dba 272637952 11月  7 13:49 sysaux01.dbf
-rw-r----- 1 oraten dba 461381632 11月  7 13:49 system01.dbf
---------- 1 oraten dba  20979712 11月  7 13:39 temp01.dbf
-rw-r----- 1 oraten dba  10493952 11月  7 13:44 test01.dbf
-rw-r----- 1 oraten dba  26222592 11月  7 13:49 undotbs01.dbf
-rw-r----- 1 oraten dba   5251072 11月  7 13:44 users01.dbf

強制啓動數據庫

SQL> startup force
ORACLE instance started.

Total System Global Area  134217728 bytes
Fixed Size		    2094544 bytes
Variable Size		   88082992 bytes
Database Buffers	   37748736 bytes
Redo Buffers		    6291456 bytes
Database mounted.
Database opened.
SQL> 
創建臨時表,並插入數據

SQL> insert into t1 select * from user_tables;
insert into t1 select * from user_tables
            *
ERROR at line 1:
ORA-01157: cannot identify/lock data file 101 - see DBWR trace file
ORA-01110: data file 101: '/home/app/oraten/oradata/oraten/temp01.dbf'

呵呵,臨時文件無法訪問,在這裏顯示的文件號爲101,爲什麼那?

我們將參數 db_files修改爲200,繼續實驗

SQL> show parameter db_files

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
db_files			     integer	 100
SQL> alter system set db_files=200 scope=spfile;

System altered.

SQL> startup force
ORACLE instance started.

Total System Global Area  134217728 bytes
Fixed Size		    2094544 bytes
Variable Size		   88082992 bytes
Database Buffers	   37748736 bytes
Redo Buffers		    6291456 bytes
Database mounted.
Database opened.
SQL> insert into t1 select * from user_tables;
insert into t1 select * from user_tables
            *
ERROR at line 1:
ORA-01157: cannot identify/lock data file 201 - see DBWR trace file
ORA-01110: data file 201: '/home/app/oraten/oradata/oraten/temp01.dbf'
原來,v$tempfile中的file#並不是絕對文件號,臨時文件的絕對文件號是file#+db_files參數。

打完手工!!




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章