Oracle学习(十七)之还原表空间管理

一、还原表空间管理
1.查看还原表空间
                SQL> select FILE_NAME,status,TABLESPACE_NAME from dba_data_files;

                FILE_NAME                                          STATUS    TABLESPACE_NAME
               -------------------------------------------------- --------- ---------------
               F:\APP\LEE\ORADATA\D547001\USERS01.DBF             AVAILABLE USERS
               F:\APP\LEE\ORADATA\D547001\UNDOTBS01.DBF           AVAILABLE UNDOEB8
               F:\APP\LEE\ORADATA\D547001\SYSAUX01.DBF            AVAILABLE SYSAUX
               F:\APP\LEE\ORADATA\D547001\SYSTEM01.DBF            AVAILABLE SYSTEM

2.增加还原表空间及数据文件
               SQL> CREATE UNDO TABLESPACE undo1
                 2  datafile 'e:\ora11g\D547001\undotest.dbf'
                 3  size 100M
                 4  autoextend on;

               表空间已创建。

3.还原表空间改名
               SQL> alter tablespace UNDO1 rename to undo2;

               表空间已更改。

4.删除还原表空间
               SQL> drop tablespace UNDO2;

               表空间已删除。

5.切换还原表空间
               SQL> alter system set undo_tablespace='TBS_875';

               系统已更改。

二、还原表空间文件管理
1.查看文件
               SQL> select TABLESPACE_NAME,STATUS from dba_tablespaces;

               TABLESPACE_NAME                STATUS
               ------------------------------ ---------
               SYSTEM                         ONLINE
               SYSAUX                         ONLINE
               UNDOEB8                        ONLINE
               TEMPDF2                        ONLINE
               USERS                          ONLINE

2.增加文件
               SQL> alter tablespace UNDO2
                 2  add datafile 'E:\ORA11G\D547001\UNDOTEST2.DBF'
                 3  size 100M;

               表空间已更改。

3.设置文件自动扩展
               SQL> alter database
                 2  datafile 'E:\ORA11G\D547001\UNDOTEST2.DBF'
                 3  autoextend on;

               数据库已更改。

4.重命名文件
1)查询
               SQL> select FILE_NAME,TABLESPACE_NAME from dba_data_files;

               FILE_NAME                                          TABLESPACE_NAME
               -------------------------------------------------- ---------------
               F:\APP\LEE\ORADATA\D547001\USERS01.DBF             USERS
               F:\APP\LEE\ORADATA\D547001\UNDOTBS01.DBF           UNDOEB8
               F:\APP\LEE\ORADATA\D547001\SYSAUX01.DBF            SYSAUX
               F:\APP\LEE\ORADATA\D547001\SYSTEM01.DBF            SYSTEM

2)启动到mount状态
               SQL> shutdown
               数据库已经关闭。
               已经卸载数据库。
               ORACLE 例程已经关闭。

               SQL> startup mount
               ORACLE 例程已经启动。

               Total System Global Area  627732480 bytes
               Fixed Size                  1376408 bytes
               Variable Size             272633704 bytes
               Database Buffers          348127232 bytes
               Redo Buffers                5595136 bytes
               数据库装载完毕。

3)移动文件
               SQL> $ move F:\APP\LEE\ORADATA\D547001\UNDOTBS01.DBF e:\ora11g\D547001\UNDOTBS01.DBF
               移动了         1 个文件。

4)修改数据库
               SQL> alter database rename file
                 2  'F:\APP\LEE\ORADATA\D547001\UNDOTBS01.DBF'
                 3  to 'e:\ora11g\D547001\UNDOTBS01.DBF';

               数据库已更改。

5)启动到open状态
               SQL> alter database open;

               数据库已更改。

6)查询
               SQL> select FILE_NAME,TABLESPACE_NAME from dba_data_files;

               FILE_NAME                                          TABLESPACE_NAME
               -------------------------------------------------- -----------------
               F:\APP\LEE\ORADATA\D547001\USERS01.DBF             USERS
               E:\ORA11G\D547001\UNDOTBS01.DBF                    UNDOEB8
               F:\APP\LEE\ORADATA\D547001\SYSAUX01.DBF            SYSAUX
               F:\APP\LEE\ORADATA\D547001\SYSTEM01.DBF            SYSTEM

5.修改文件大小
1)文件大小
               SQL> alter database
                 2  datafile 'E:\ORA11G\D547001\UNDOTBS01.DBF'
                 3  resize 900M;

               数据库已更改。

2)扩展大小设置
               SQL> alter database
                 2  datafile 'E:\ORA11G\D547001\UNDOTBS01.DBF'
                 3  autoextend on next 190M maxsize 3100M;

               数据库已更改。

7.删除文件(不能删除第一个文件)
               SQL> alter tablespace TBS_875
                 2  drop datafile '第二及之后的个文件';

你可能感兴趣的:(Oracle数据库学习)