几个关于表空间与数据文件重要视图
dba_tablespaces; v$tablespace; dba_data_files v$datafile;
SQL> desc dba_tablespaces;
LINEID NAME TYPE$ NULLABLE
---------- --------------- ------------ --------
1 TABLESPACE_NAME VARCHAR(128) Y
2 BLOCK_SIZE BIGINT Y
3 INITIAL_EXTENT VARCHAR(1) Y
4 NEXT_EXTENT VARCHAR(1) Y
5 MIN_EXTENTS VARCHAR(1) Y
6 MAX_EXTENTS VARCHAR(1) Y
7 MAX_SIZE BIGINT Y
8 PCT_INCREASE VARCHAR(1) Y
9 MIN_EXTLEN VARCHAR(1) Y
10 STATUS INTEGER Y
11 CONTENTS VARCHAR(9) Y
12 LOGGING VARCHAR(1) Y
13 FORCE_LOGGING VARCHAR(1) Y
14 EXTENT_MANAGEMENT VARCHAR(1) Y
15 ALLOCATION_TYPE VARCHAR(1) Y
16 PLUGGED_IN VARCHAR(1) Y
17 SEGMENT_SPACE_MANAGEMENT VARCHAR(1) Y
18 DEF_TAB_COMPRESSION VARCHAR(8) Y
19 RETENTION VARCHAR(1) Y
20 BIGFILE VARCHAR(1) Y
21 PREDICATE_EVALUATION VARCHAR(1) Y
22 ENCRYPTED VARCHAR(1) Y
23 COMPRESS_FOR VARCHAR(1) Y
23 rows got
used time: 15.647(ms). Execute id is 64.
SQL>
SQL> desc v$tablespace;
LINEID NAME TYPE$ NULLABLE
---------- ------------- ------------ --------
1 ID INTEGER Y
2 NAME VARCHAR(128) Y
3 CACHE VARCHAR(20) Y
4 TYPE$ TINYINT Y
5 STATUS$ TINYINT Y
6 MAX_SIZE BIGINT Y
7 TOTAL_SIZE BIGINT Y
8 FILE_NUM INTEGER Y
9 ENCRYPT_NAME VARCHAR(128) Y
10 ENCRYPTED_KEY VARCHAR(500) Y
11 COPY_NUM INTEGER Y
12 SIZE_MODE VARCHAR(128) Y
12 rows got
used time: 6.468(ms). Execute id is 67.
SQL>
SQL>
SQL>
SQL> desc dba_data_files
LINEID NAME TYPE$ NULLABLE
---------- --------------- ------------ --------
1 FILE_NAME VARCHAR(256) Y
2 FILE_ID INTEGER Y
3 TABLESPACE_NAME VARCHAR(128) Y
4 BYTES BIGINT Y
5 BLOCKS BIGINT Y
6 STATUS VARCHAR(9) Y
7 RELATIVE_FNO INTEGER Y
8 AUTOEXTENSIBLE VARCHAR(9) Y
9 MAXBYTES NUMBER Y
10 MAXBLOCKS INTEGER Y
11 INCREMENT_BY INTEGER Y
12 USER_BYTES BIGINT Y
13 USER_BLOCKS BIGINT Y
14 ONLINE_STATUS VARCHAR(9) Y
14 rows got
used time: 10.466(ms). Execute id is 65.
SQL>
SQL> desc v$datafile;
LINEID NAME TYPE$ NULLABLE
---------- -------------- ------------ --------
1 GROUP_ID INTEGER Y
2 ID INTEGER Y
3 PATH VARCHAR(256) Y
4 CLIENT_PATH VARCHAR(256) Y
5 CREATE_TIME DATETIME(0) Y
6 STATUS$ TINYINT Y
7 RW_STATUS TINYINT Y
8 LAST_CKPT_TIME DATETIME(0) Y
9 MODIFY_TIME DATETIME(0) Y
10 MODIFY_TRX BIGINT Y
11 TOTAL_SIZE BIGINT Y
12 FREE_SIZE BIGINT Y
13 FREE_PAGE_NO BIGINT Y
14 PAGES_READ BIGINT Y
15 PAGES_WRITE BIGINT Y
16 PAGE_SIZE INTEGER Y
17 READ_REQUEST INTEGER Y
18 WRITE_REQUEST INTEGER Y
19 AUTO_EXTEND INTEGER Y
20 MAX_SIZE INTEGER Y
21 NEXT_SIZE INTEGER Y
22 MIRROR_PATH VARCHAR(256) Y
22 rows got
used time: 7.156(ms). Execute id is 68.
SQL>
查询表空间名称
SQL> select tablespace_name from dba_tablespaces;
LINEID TABLESPACE_NAME
---------- ---------------
1 SYSTEM
2 ROLL
3 TEMP
4 MAIN
5 HMAIN
used time: 2.326(ms). Execute id is 69.
查询表空间与数据文件关联的位置
SQL> select tablespace_name, file_name, status from dba_data_files order by 1;
LINEID TABLESPACE_NAME FILE_NAME STATUS
---------- --------------- --------------------------------- ---------
1 MAIN /dm/dmdbms/data/DAMENG/MAIN.DBF AVAILABLE
2 ROLL /dm/dmdbms/data/DAMENG/ROLL.DBF AVAILABLE
3 SYSTEM /dm/dmdbms/data/DAMENG/SYSTEM.DBF AVAILABLE
4 TEMP /dm/dmdbms/data/DAMENG/TEMP.DBF AVAILABLE
used time: 3.375(ms). Execute id is 70.
SQL>
创建表空间
SQL> create tablespace test datafile '/dm/dmdbms/data/DAMENG/test01.DBF' size 64;
executed successfully
used time: 47.240(ms). Execute id is 71.
查看创建结果
SQL> select tablespace_name, file_name, status,bytes/1024/1024 from dba_data_files order by 1;
LINEID TABLESPACE_NAME FILE_NAME STATUS BYTES/1024/1024
---------- --------------- --------------------------------- --------- --------------------
1 MAIN /dm/dmdbms/data/DAMENG/MAIN.DBF AVAILABLE 128
2 ROLL /dm/dmdbms/data/DAMENG/ROLL.DBF AVAILABLE 128
3 SYSTEM /dm/dmdbms/data/DAMENG/SYSTEM.DBF AVAILABLE 23
4 TEMP /dm/dmdbms/data/DAMENG/TEMP.DBF AVAILABLE 10
5 TEST /dm/dmdbms/data/DAMENG/test01.DBF AVAILABLE 64
used time: 3.343(ms). Execute id is 74.
扩展表空间
SQL> alter tablespace test add datafile '/dm/dmdbms/data/DAMENG/test02.DBF' size 32;
executed successfully
used time: 23.449(ms). Execute id is 75.
SQL> select tablespace_name, file_name, status,bytes/1024/1024 from dba_data_files order by 1;
LINEID TABLESPACE_NAME FILE_NAME STATUS BYTES/1024/1024
---------- --------------- --------------------------------- --------- --------------------
1 MAIN /dm/dmdbms/data/DAMENG/MAIN.DBF AVAILABLE 128
2 ROLL /dm/dmdbms/data/DAMENG/ROLL.DBF AVAILABLE 128
3 SYSTEM /dm/dmdbms/data/DAMENG/SYSTEM.DBF AVAILABLE 23
4 TEMP /dm/dmdbms/data/DAMENG/TEMP.DBF AVAILABLE 10
5 TEST /dm/dmdbms/data/DAMENG/test01.DBF AVAILABLE 64
6 TEST /dm/dmdbms/data/DAMENG/test02.DBF AVAILABLE 32
6 rows got
used time: 3.343(ms). Execute id is 76.
SQL>
修改表空间名称
SQL> alter tablespace test rename to jisen;
executed successfully
used time: 11.021(ms). Execute id is 77.
SQL> select tablespace_name, file_name, status,bytes/1024/1024 from dba_data_files order by 1;
LINEID TABLESPACE_NAME FILE_NAME STATUS BYTES/1024/1024
---------- --------------- --------------------------------- --------- --------------------
1 JISEN /dm/dmdbms/data/DAMENG/test01.DBF AVAILABLE 64
2 JISEN /dm/dmdbms/data/DAMENG/test02.DBF AVAILABLE 32
3 MAIN /dm/dmdbms/data/DAMENG/MAIN.DBF AVAILABLE 128
4 ROLL /dm/dmdbms/data/DAMENG/ROLL.DBF AVAILABLE 128
5 SYSTEM /dm/dmdbms/data/DAMENG/SYSTEM.DBF AVAILABLE 23
6 TEMP /dm/dmdbms/data/DAMENG/TEMP.DBF AVAILABLE 10
6 rows got
used time: 1.706(ms). Execute id is 78.
SQL>
移动数据文件位置
SQL> alter tablespace jisen offline;
executed successfully
used time: 89.413(ms). Execute id is 79.
SQL> alter tablespace jisen rename datafile '/dm/dmdbms/data/DAMENG/test01.DBF' TO '/dm/dmdbms/data/test01.DBF';
executed successfully
used time: 196.679(ms). Execute id is 80.
SQL> select tablespace_name, file_name, status,bytes/1024/1024 from dba_data_files order by 1;
LINEID TABLESPACE_NAME FILE_NAME STATUS BYTES/1024/1024
---------- --------------- --------------------------------- --------- --------------------
1 JISEN /dm/dmdbms/data/test01.DBF AVAILABLE 64
2 JISEN /dm/dmdbms/data/DAMENG/test02.DBF AVAILABLE 32
3 MAIN /dm/dmdbms/data/DAMENG/MAIN.DBF AVAILABLE 128
4 ROLL /dm/dmdbms/data/DAMENG/ROLL.DBF AVAILABLE 128
5 SYSTEM /dm/dmdbms/data/DAMENG/SYSTEM.DBF AVAILABLE 23
6 TEMP /dm/dmdbms/data/DAMENG/TEMP.DBF AVAILABLE 10
6 rows got
alter tablespace jisen online;
executed successfully
移动是自动的
[dmdba@dm1 ~]$ cd /dm/dmdbms/data/
[dmdba@dm1 data]$ ll
total 65540
drwxr-xr-x. 6 dmdba dinstall 4096 Mar 2 14:35 DAMENG
-rw-r--r-- 1 dmdba dinstall 67108864 Mar 2 14:34 test01.DBF
可以看到默认情况下,是自增模式,最大为16TB。这个跟Oracle单个文件有点不一样。
SQL> drop tablespace jisen;
executed successfully
used time: 99.385(ms). Execute id is 87.