roothomes 发表于 2011-12-23 01:07

--== 表空间维护 1

<DIV>--==&nbsp; 表空间维护 1<BR>----&nbsp; 查询表空间的数据文件的大小<BR>select * from dba_data_files d order by d.tablespace_name,d.file_name;<BR>select d.tablespace_name,d.file_name ,d.bytes/(1024*1024) as "size MB" ,d.status<BR>&nbsp; from dba_data_files d order by d.tablespace_name ;<BR>---- =====&nbsp; 场景一<BR>----&nbsp; [步骤1]创建表空间 roothomesTS <BR>CREATE TABLESPACE roothomesTS DATAFILE 'D:\oracle\oradata\ora1812\roothomesTS.dbf' SIZE 100M; </DIV>
<DIV>----&nbsp; [步骤2]修改表空间的数据文件的大小 <BR>ALTER DATABASE DATAFILE 'D:\oracle\oradata\ora1812\roothomesTS.dbf' RESIZE 102M; <BR>----&nbsp; [步骤3]为表空间添加数据文件<BR>ALTER TABLESPACE roothomesTS ADD DATAFILE 'D:\oracle\oradata\ora1812\roothomesTS2.dbf' SIZE 20M;<BR>ALTER TABLESPACE roothomesTS ADD DATAFILE 'D:\oracle\oradata\ora1812\roothomesTS3.dbf' SIZE 20M;<BR>----&nbsp; [步骤4]删除数据文件 <BR>ALTER DATABASE DATAFILE 'D:\oracle\oradata\ora1812\roothomesTS2.dbf' OFFLINE&nbsp; DROP;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* 该命令不会删除数据文件,只是将数据文件的状态更改为recover。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; offline drop命令相当于把一个数据文件至于离线状态,并且需要恢复,并非删除数据文件。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 数据文件的相关信息还会存在数据字典和控制文件中。&nbsp; */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- select d.tablespace_name,d.file_name ,d.file_id ,d.bytes/(1024*1024) as "size MB" ,d.status <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&nbsp;&nbsp; from dba_data_files d where d.tablespace_name = 'ROOTHOMESTS';&nbsp; --- 查询结果<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&nbsp; 1&nbsp;ROOTHOMESTS&nbsp;D:\ORACLE\ORADATA\ORA1812\ROOTHOMESTS.DBF&nbsp;14&nbsp;102&nbsp;AVAILABLE<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&nbsp; 2&nbsp;ROOTHOMESTS&nbsp;D:\ORACLE\ORADATA\ORA1812\ROOTHOMESTS2.DBF&nbsp;15&nbsp;&nbsp;AVAILABLE<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&nbsp; 3&nbsp;ROOTHOMESTS&nbsp;D:\ORACLE\ORADATA\ORA1812\ROOTHOMESTS3.DBF&nbsp;16&nbsp;20&nbsp;AVAILABLE</DIV>
<DIV>---- [步骤4-2]把数据文件 offline drop后,进行恢复(mount 模式下面对数据文件进行恢复)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQL&gt; shutdown abort;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ORACLE 例程已经关闭。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQL&gt; startup mount;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ORACLE 例程已经启动。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Total System Global Area&nbsp; 126950220 bytes<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fixed Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 453452 bytes<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Variable Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 109051904 bytes<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Database Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 16777216 bytes<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Redo Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 667648 bytes<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 数据库装载完毕。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQL&gt; recover datafile&nbsp; 'd:\oracle\oradata\ora1812\roothomesTS2.dbf' ;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 完成介质恢复。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQL&gt; alter database datafile 'd:\oracle\oradata\ora1812\roothomesTS2.dbf' online;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 数据库已更改。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQL&gt; alter database open;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 数据库已更改。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQL&gt;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */</DIV>
<DIV>----&nbsp; [步骤5]删除表空间和对应的数据文件 <BR>DROP TABLESPACE roothomesTS INCLUDING CONTENTS AND DATAFILES; <BR>&nbsp;&nbsp;&nbsp;&nbsp; --- 再次查询 ROOTHOMESTS 表空间被删除掉了; 数据文件也全部删掉;<BR></DIV>
页: [1]
查看完整版本: --== 表空间维护 1