1. 新表空间的创建
语法格式:
CREATE TABLESPACE 表空间名 DATAFILE 文件标识符[,文件标识符]...
[DEFAULT STORAGE(存储配置参数)] [ONLINE\OFFLINE];
其中:文件标识符=’文件名’[SIZE整数[K\M][REUSE]
2. 修改表空间配置
语法格式:
ALTER TABLESPCE 表空间名 (ADD DATAFILE 文件标识符[,文件标识符]...
\RENAME DATAFILE ’文件名’[,’文件名’]... TO ’文件名’[,’文件名’]...
\DEFAULT STORAGE(存储配置参数)
\ONLINE\OFFLINE[NORMAL\IMMEDIATE]
\(BEGIN\END)BACKUP);
3. 删除表空间
语法格式:
DROP TABLESPACE 表空间名[INCLUDING CONTENTS AND DATAFILES];
4. 检查表空间使用情况
查询永久表空间剩余及其剩下空间百分比, sql如下:
SQL>select t1.tname "tablespace", t2.total "total/M", t1.free "free/M", t2.total-t1.free "used/M", (t1.free/t2.total)*100 free_percent from ( select sum(nvl(a.bytes,0))/(1024*1024) free, a.tablespace_name tname from dba_free_space a group by a.tablespace_name) t1, (select sum(b.bytes)/(1024*1024) total, b.tablespace_name tname from dba_data_files b group by b.tablespace_name) t2 where t1.tname=t2.tname;
tablespace total/M free/M used/M FREE_PERCENT
------------------------------ ---------- ---------- ---------- ------------
UNDOTBS1 300 276.6875 23.3125 92.2291667
SYSAUX 890 320.0625 569.9375 35.9620787
INDTBS 110 109.875 .125 99.8863636
……………………………………………………………………
查询临时表空间剩余, sql如下:
SQL>select tablespace_name,sum(BYTES_USED/1024/1024) "used/M",sum(BYTES_FREE/1024/1024) "free/M" from v$temp_space_header group by tablespace_name;
TABLESPACE_NAME used/M free/M
-------------------- ---------- ----------
TEMP 105 995
5. 扩展表空间
经常会遇到表空间不足而达到Alert Level: WARNING or CRITICAL
Using OMF files management on ASM, the datafiles by default are created with autoextending enabled on a maxsize of 32G. Calculating tablespace usage is based on how much autoextensible space is available.
首先查看表空间文件名、是否扩展、最大值等。
SQL>col file_name for a50
SQL>select file_name, autoextensible,maxbytes||'' from dba_data_files where tablespace_name='NETCOOL_DATA';
FILE_NAME AUT MAXBYTES||''
-------------------------------------------------- ----------- -------------
+DATA/racdb/datafile/netcool_data.344.722943125 YES 34359721984
方法一、增加数据文件
SQL>alter tablespace NETCOOL_DATA add datafile '+DATA';
Tablespace altered.
SQL>select file_name, autoextensible,maxbytes/1024/1024/1024 GB from dba_data_files where tablespace_name='NETCOOL_DATA';
FILE_NAME AUT GB
-------------------------------------------------- --- ----------
+DATA/racdb/datafile/netcool_data.341.778582069 YES 31.9999847
+DATA/racdb/datafile/netcool_data.344.722943125 YES 31.9999847
方法二、手动增加数据文件尺寸并确保可扩展
SQL>alter database datafile '+DATA/racdb/datafile/netcool_data.344.722943125' resize 300M;
Database altered.
SQL>select file_name, autoextensible,bytes/1024/1024 Mb, STATUS from dba_data_files where tablespace_name='NETCOOL_DATA';
FILE_NAME AUT MB STATUS
------------------------------------------------------------ --- ---------- ---------
+DATA/racdb/datafile/netcool_data.341.778582069 YES 100 AVAILABLE
+DATA/racdb/datafile/netcool_data.344.722943125 YES 300 AVAILABLE
如果相关数据文件没有自动扩展,启用语句如下:
SQL>alter database datafile '+DATA/racdb/datafile/netcool_data.344.722943125' autoextend on maxsize 32000M;
6. 查询数据库默认永久表空间
SQL>select * from database_properties where property_name='DEFAULT_PERMANENT_TABLESPACE';
修改默认永久表空间
SQL> alter database default tablespace NETCOOL_DATA;
Database altered.
<!-- @page { margin: 0.79in } P { margin-bottom: 0.08in } -
语法格式:
CREATE TABLESPACE 表空间名 DATAFILE 文件标识符[,文件标识符]...
[DEFAULT STORAGE(存储配置参数)] [ONLINE\OFFLINE];
其中:文件标识符=’文件名’[SIZE整数[K\M][REUSE]
2. 修改表空间配置
语法格式:
ALTER TABLESPCE 表空间名 (ADD DATAFILE 文件标识符[,文件标识符]...
\RENAME DATAFILE ’文件名’[,’文件名’]... TO ’文件名’[,’文件名’]...
\DEFAULT STORAGE(存储配置参数)
\ONLINE\OFFLINE[NORMAL\IMMEDIATE]
\(BEGIN\END)BACKUP);
3. 删除表空间
语法格式:
DROP TABLESPACE 表空间名[INCLUDING CONTENTS AND DATAFILES];
4. 检查表空间使用情况
查询永久表空间剩余及其剩下空间百分比, sql如下:
SQL>select t1.tname "tablespace", t2.total "total/M", t1.free "free/M", t2.total-t1.free "used/M", (t1.free/t2.total)*100 free_percent from ( select sum(nvl(a.bytes,0))/(1024*1024) free, a.tablespace_name tname from dba_free_space a group by a.tablespace_name) t1, (select sum(b.bytes)/(1024*1024) total, b.tablespace_name tname from dba_data_files b group by b.tablespace_name) t2 where t1.tname=t2.tname;
tablespace total/M free/M used/M FREE_PERCENT
------------------------------ ---------- ---------- ---------- ------------
UNDOTBS1 300 276.6875 23.3125 92.2291667
SYSAUX 890 320.0625 569.9375 35.9620787
INDTBS 110 109.875 .125 99.8863636
……………………………………………………………………
查询临时表空间剩余, sql如下:
SQL>select tablespace_name,sum(BYTES_USED/1024/1024) "used/M",sum(BYTES_FREE/1024/1024) "free/M" from v$temp_space_header group by tablespace_name;
TABLESPACE_NAME used/M free/M
-------------------- ---------- ----------
TEMP 105 995
5. 扩展表空间
经常会遇到表空间不足而达到Alert Level: WARNING or CRITICAL
Using OMF files management on ASM, the datafiles by default are created with autoextending enabled on a maxsize of 32G. Calculating tablespace usage is based on how much autoextensible space is available.
首先查看表空间文件名、是否扩展、最大值等。
SQL>col file_name for a50
SQL>select file_name, autoextensible,maxbytes||'' from dba_data_files where tablespace_name='NETCOOL_DATA';
FILE_NAME AUT MAXBYTES||''
-------------------------------------------------- ----------- -------------
+DATA/racdb/datafile/netcool_data.344.722943125 YES 34359721984
方法一、增加数据文件
SQL>alter tablespace NETCOOL_DATA add datafile '+DATA';
Tablespace altered.
SQL>select file_name, autoextensible,maxbytes/1024/1024/1024 GB from dba_data_files where tablespace_name='NETCOOL_DATA';
FILE_NAME AUT GB
-------------------------------------------------- --- ----------
+DATA/racdb/datafile/netcool_data.341.778582069 YES 31.9999847
+DATA/racdb/datafile/netcool_data.344.722943125 YES 31.9999847
方法二、手动增加数据文件尺寸并确保可扩展
SQL>alter database datafile '+DATA/racdb/datafile/netcool_data.344.722943125' resize 300M;
Database altered.
SQL>select file_name, autoextensible,bytes/1024/1024 Mb, STATUS from dba_data_files where tablespace_name='NETCOOL_DATA';
FILE_NAME AUT MB STATUS
------------------------------------------------------------ --- ---------- ---------
+DATA/racdb/datafile/netcool_data.341.778582069 YES 100 AVAILABLE
+DATA/racdb/datafile/netcool_data.344.722943125 YES 300 AVAILABLE
如果相关数据文件没有自动扩展,启用语句如下:
SQL>alter database datafile '+DATA/racdb/datafile/netcool_data.344.722943125' autoextend on maxsize 32000M;
6. 查询数据库默认永久表空间
SQL>select * from database_properties where property_name='DEFAULT_PERMANENT_TABLESPACE';
修改默认永久表空间
SQL> alter database default tablespace NETCOOL_DATA;
Database altered.
<!-- @page { margin: 0.79in } P { margin-bottom: 0.08in } -
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/628922/viewspace-719237/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/628922/viewspace-719237/