网站首页 > 技术文章 正文
表空间修改/扩展
增加现有表空间的容量:
查询现各表空间容量
SQL> select file_name,tablespace_name,bytes/1024/1024 from dba_data_files;
FILE_NAME TABLESPACE BYTES/1024/1024
--------------------------------------------- ---------- ---------------
/u01/app/oracle/oradata/ORCL/system01.dbf SYSTEM 850
/u01/app/oracle/oradata/ORCL/sysaux01.dbf SYSAUX 750
/u01/app/oracle/oradata/ORCL/undotbs01.dbf UNDOTBS1 310
/u01/app/oracle/oradata/ORCL/users01.dbf USERS 100
/u02/ts/ts1.dbf TS1 50
/u02/ts/ts22.dbf TS22 20
/u01/app/oracle/oradata/ORCL/tsts41.dbf TS4 50
将TS1的空间调整到60MB
SQL> alter database datafile '/u02/ts/ts1.dbf' resize 60M;
Database altered.
为表空间增加数据文件:
为TS22表空间增加一个20M大小的数据文件。
SQL> alter tablespace ts22 add datafile '/u02/ts/ts22-1.dbf' size 20M;
Tablespace altered.
允许表空间自动扩展到多大:
允许TS4自动扩展到100M
SQL> alter database datafile '/u01/app/oracle/oradata/ORCL/tsts41.dbf'
2 autoextend on next 10M maxsize 100M;
Database altered.
再次查询一下:
SQL> select tablespace_name,file_name,
2 autoextensible,increment_by,maxbytes/1024/1024 as max_mb
3 from dba_data_files
4 where tablespace_name = 'TS4';
TABLESPACE_NAME FILE_NAME AUTOEX INCREMENT_BY MAX_MB
-------------------- ---------------------------------------- ------ ------------ ----------
TS4 /u01/app/oracle/oradata/ORCL/tsts41.dbf YES 1280 100
表空间的使用
默认临时表空间使用临时表空间组
假设已经创建了临时表空间组g1
SQL>alter database default temporary tablespace g1;
为scott用户指定默认的临时表空间temp,不使用系统默认的临时表空间
SQL>alter user scott temporary tablespace temp1;
给scott用户指定默认的表空间ts2
SQL>alter user scott default tablespace ts2;
给数据库指定默认的表空间 ts1,不使用默认的 users 表空间
SQL>alter database default tablespace ts1;
给表指定默认的表空间:
SQL> create table tb1(id number)
2 tablespace ts7;
表空间状态改变
SQL>alter tablespace ts1 offline; --表空间离线,不能读写数据
SQL>alter tablespace ts1 online; --恢复表空间的在线状态
SQL>alter tablespace ts1 read only; --使表空间处于只读状态
SQL>alter tablespace ts1 read write; --表空间为读写状态
表空间删除
删除临时表空间组:
停止(删除)表空间tmp1,tmp2的临时表空间组,停止临时表空间组,需要指定一个数据库默认的临时表。
SQL>alter database default temporary tablespace tmp1; --指定数据库默认临时表空间。
SQL>alter tablespace tmp1 tablespace group '';
SQL>alter tablespace tmp2 tablespace group '';
删除用户的表空间:
一、不带参数(选项)
直接删除表空间不带参数,如果表空间已分配给某个用户,或者某个表使用的情况下,是不能直接删除,系统会提示,表控件不是空的,需要使用 INCLUDING CONTENTS选项进行删除;
SQL> create tablespace ts6
2 datafile '/u02/ts/ts6.dbf' size 10M;
SQL> create table tb2(id number)
2 tablespace ts6;
SQL> drop tablespace ts6;
drop tablespace ts6
*
ERROR at line 1:
ORA-01549: tablespace not empty, use INCLUDING CONTENTS option
如果需要使用上面的方法删除ts6表空间,则需要将tb2的表空间移动到其他表空间。然后再到系统中删除对于的数据文件。
SQL> alter table tb2 move tablespace ts5;
Table altered.
SQL> drop tablespace ts6;
Tablespace dropped.
[oracle@host01 ts]$ rm ts6.dbf -rf
二、带including contents参数(选项)
including contents 选项会删除表空间中的元数据,导致使用该表空间的表的数据全部删除,数据文件会保留,需要手动删除。
SQL> drop tablespace ts5 including contents;
Tablespace dropped.
[oracle@host01 ts]$ rm ts5
三、删除表空间时将数据文件一起删除()
SQL> create tablespace ts7
2 datafile '/u02/ts/ts7' size 10m;
Tablespace created.
SQL> create table tb1(id number)
2 tablespace ts7;
Table created.
SQL> select a.table_name,a.tablespace_name,b.file_name
2 from user_tables a
3 join dba_data_files b on b.tablespace_name = a.tablespace_name
4 where table_name = 'TB1';
TABLE_NAME TABLESPACE_NAME FILE_NAME
-------------------- -------------------- ----------------------------------------
TB1 TS7 /u02/ts/ts7
SQL> select * from tb1;
ID
----------
1
2
SQL> drop tablespace ts7 including contents and datafiles;
Tablespace dropped.
SQL> select a.table_name,a.tablespace_name,b.file_name
2 from user_tables a
3 join dba_data_files b on b.tablespace_name = a.tablespace_name
4 where table_name = 'TB1';
no rows selected
SQL> select * from tb1;
select * from tb1
*
ERROR at line 1:
ORA-00942: table or view does not exist
数据文件在线移动:
SQL> create table tb2 (id number)
2 tablespace ts4;
Table created.
SQL> select a.table_name,a.tablespace_name,b.file_name
2 from user_tables a
3 join dba_data_files b on b.tablespace_name = a.tablespace_name
4 where table_name = 'TB2';
TABLE_NAME TABLESPACE_NAME FILE_NAME
-------------------- -------------------- ----------------------------------------
TB2 TS4 /u01/app/oracle/oradata/ORCL/tsts41.dbf
SQL> alter database move datafile '/u01/app/oracle/oradata/ORCL/tsts41.dbf' to
2 '/u02/ts/ts4.dbf';
Database altered.
SQL> select a.table_name,a.tablespace_name,b.file_name
2 from user_tables a
3 join dba_data_files b on b.tablespace_name = a.tablespace_name
4 where table_name = 'TB2';
TABLE_NAME TABLESPACE_NAME FILE_NAME
-------------------- -------------------- ----------------------------------------
TB2 TS4 /u02/ts/ts4.dbf
猜你喜欢
- 2024-11-10 数据库的存储结构 数据库的存储结构分为哪两种
- 2024-11-10 mysql文件结构及InnoDB引擎表空间整理
- 2024-11-10 临时表空间的实时监控,百度99%的搜索结果都是错误的
- 2024-11-10 一文看懂postgresql表空间--概念、用途、分类、相关命令等
你 发表评论:
欢迎- 616℃几个Oracle空值处理函数 oracle处理null值的函数
- 609℃Oracle分析函数之Lag和Lead()使用
- 596℃0497-如何将Kerberos的CDH6.1从Oracle JDK 1.8迁移至OpenJDK 1.8
- 593℃Oracle数据库的单、多行函数 oracle执行多个sql语句
- 590℃Oracle 12c PDB迁移(一) oracle迁移到oceanbase
- 581℃【数据统计分析】详解Oracle分组函数之CUBE
- 570℃最佳实践 | 提效 47 倍,制造业生产 Oracle 迁移替换
- 560℃Oracle有哪些常见的函数? oracle中常用的函数
- 最近发表
-
- PageHelper - 最方便的 MyBatis 分页插件
- 面试二:pagehelper是怎么实现分页的,
- MyBatis如何实现分页查询?(mybatis-plus分页查询)
- SpringBoot 各种分页查询方式详解(全网最全)
- 如何在Linux上运行exe文件,怎么用linux运行windows软件
- 快速了解hive(快速了解美国50个州)
- Python 中的 pyodbc 库(pydbclib)
- Linux搭建Weblogic集群(linux weblogic部署项目步骤)
- 「DM专栏」DMDSC共享集群之部署(一)——共享存储配置
- 故障分析 | MySQL 派生表优化(mysql pipe)
- 标签列表
-
- 前端设计模式 (75)
- 前端性能优化 (51)
- 前端模板 (66)
- 前端跨域 (52)
- 前端缓存 (63)
- 前端aes加密 (58)
- 前端脚手架 (56)
- 前端md5加密 (54)
- 前端路由 (61)
- 前端数组 (73)
- 前端js面试题 (50)
- 前端定时器 (59)
- 前端获取当前时间 (50)
- Oracle RAC (76)
- oracle恢复 (77)
- oracle 删除表 (52)
- oracle 用户名 (80)
- oracle 工具 (55)
- oracle 内存 (55)
- oracle 导出表 (62)
- oracle约束 (54)
- oracle 中文 (51)
- oracle链接 (54)
- oracle的函数 (58)
- 前端调试 (52)
本文暂时没有评论,来添加一个吧(●'◡'●)