当前位置:网站首页>Oracle-表空间管理
Oracle-表空间管理
2022-07-05 20:03:00 【旷世奇才李先生】
万般皆下品、惟有读书高
文章持续更新,可以微信搜索【小奇JAVA面试】第一时间阅读,回复【资料】获取福利,回复【项目】获取项目源码,回复【简历模板】获取简历模板,回复【学习路线图】获取学习路线图。
文章目录
一、表空间概述
为了便于对数据库进行管理和优化,oracle数据库被划分成许多表空间的逻辑区域,一个oracle数据库有一个或者多个表空间,而一个表空间则对应一个或者多个物理上的数据库文件。表空间和数据文件紧密相连,相互依存,在创建表空间的同时要创建数据文件,同理,增加数据文件的同时也要指定表空间。数据库在物理上由数据文件大小和数量决定,在逻辑上由表空间大小和数量决定。
表空间是数据管理的基本方法,所有用户对象都放在表空间中,即用户有空间的使用权才能创建用户对象,否则不允许创建对象。在创建表空间的同时,需要合理规划表空间的存储设置,分配适当大小的存储空间。
1、表空间的属性
1、类型
2、管理方式
3、区分配方式
4、段管理方式
2、表空间的类型
1、永久性表空间
系统表空间和普通用户使用的表空间默认都是永久性表空间。
2、临时表空间
一般用来存放sql语句处理的表和索引信息,其空间不存放实际的数据。
3、撤销表空间
此类型主要用于事务回滚,提供读一致性。数据库可以同时存在多个撤下表空间,但任一时间只有一个撤销表空间可以被激活。
4、大文件表空间
大文件表空间存放一个单一的数据文件中,单个数据文件最大可达128TB。
3、表空间的状态
1、联机状态
数据只有处于联机状态,才能访问其中的数据。
2、读写状态
默认情况下所有的表空间都是读写状态,具有适当权限的用户可以读写该表空间的数据。
3、只读状态
表空间为只读状态是指用户只能读表空间中数据,不能修改表空间的数据。
4、脱机状态
如果某个表空间设置为脱机转态,是指用户暂时不能访问该表空间。
二、表空间的创建
在实际数据库表空间管理中,可以根据具体应用情况,建立不同类型的表空间,例如用于专门存放表数据的表空间,专门存放索引的表空间等。
1、表空间的创建语法
create tablespace tablespace_name
datafile file_name datafile_options
storage_options
其中:tablespace_name为要创建的表空间名称,file_name为对应的数据文件名称,datafile_options是数据文件选项,Storage_options是存储结构选项。
2、创建一个永久性的表空间,设置表空间的初始大小为100MB,自动扩展为100MB,无最大大小限制,并且该表空间为在线状态,产生日志
create tablespace tspace 1 datafile 'c:\oracle\tspace1.dbf' size 100m
autoextend on next 100m maxsize unlimited logging online permanent;
三、表空间维护
1、设置默认表空间
创建一个新用户,如果不指定表空间,则默认的永久表空间是system,默认的临时表空间是temp,这样如果存在多个用户,那么各个用户都要竞争使用system和temp表空间,会大大影响oracle系统的效率,数据库管理员可以修改默认永久表空间和临时表空间,基本语法如下所示。
alter database default [temporary] tablespace 新表空间名称
案例:把临时表空间tspace4修改为默认临时表空间
alter database default temporary tablespace tspace4;
案例:把tspace3修改为默认永久表空间。
alter database default tablespace tspace3;
2、重命名表空间
案例:将表空间tspace3修改为tspace3_1
alter tablespace tspace3 renatspaceme to tspace3_1;
3、修改表空间的状态
修改tspace为联机状态
alter tablespace tspace online;
设置表空间tspace为脱机状态
alter tablespace tspace offline;
设置表空间tspace为只读状态
alter tablespace tspace read only;
设置表空间tspace为读写状态。
alter tablespace tspace read write;
4、修改表空间对应数据文件的大小
语法如下
alter database datafile 数据文件 resize 新文件大小
修改表空间tspace7对应的其中一个数据文件大小
alter database datafile 'c:\oracle\tspace7_1.dbf' resize 100MB;
5、增加表空间的数据文件
alter tablespace 表空间名称 add datafile 数据文件 size 文件大小;
6、删除表空间的数据文件
alter tablespace 表空间名称 drop datafile 数据文件名称;
7、修改数据文件为自动扩展
将表空间tspace7的数据文件设置为自动扩展
alter database datafile 'c:\oracle\tspace7_3.dbf' autoextend on next 10MB;
8、修改数据文件的名称或位置
alter tablespace 表空间名称 rename datafile 数据文件名称 to 新数据文件名称
9、表空间的备份
alter tablespace tspace 1 begin backup;
10、删除表空间
drop tablespace tspace7;
四、表空间查询
查询表空间的名称、区的管理方式、段的管理方式和表空间类型等信息。
select tablespace_name,extent_management,allocation_type,contents from dba_tablespaces;
查看表空间的名字、所属文件和空间大小
select tablespace_name,file_name,round(bytes/(1024*1024),0) total_space from dba_data_files;
五、总结
这里的相关内容还没有整理完毕,文章后面持续更新,建议收藏。
文章中涉及到的命令大家一定要像我一样每个都敲几遍,只有在敲的过程中才能发现自己对命令是否真正的掌握了。
可以微信搜索【小奇JAVA面试】第一时间阅读,回复【资料】获取福利,回复【项目】获取项目源码,回复【简历模板】获取简历模板,回复【学习路线图】获取学习路线图。
边栏推荐
- 线程池参数及合理设置
- Is the education of caiqiantang reliable and safe?
- 安信证券在网上开户安全吗?
- 95后阿里P7晒出工资单:狠补了这个,真香...
- [hard core dry goods] which company is better in data analysis? Choose pandas or SQL
- The difference between ID selector and class selector
- 处理文件和目录名
- C#应用程序界面开发基础——窗体控制(5)——分组类控件
- js实现禁止网页缩放(Ctrl+鼠标、+、-缩放有效亲测)
- 解决php无法将string转换为json的办法
猜你喜欢
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
Win10 x64环境下基于VS2017和cmake-gui配置使用zxing以及opencv,并实现data metrix码的简单检测
aggregate
Fundamentals of deep learning convolutional neural network (CNN)
How to safely and quickly migrate from CentOS to openeuler
港股将迎“最牛十元店“,名创优品能借IPO突围?
. Net distributed transaction and landing solution
Jvmrandom cannot set seeds | problem tracing | source code tracing
Inventory of the most complete low code / no code platforms in the whole network: Jiandao cloud, partner cloud, Mingdao cloud, Qingliu, xurong cloud, Jijian cloud, treelab, nailing · Yida, Tencent clo
【无标题】
随机推荐
Leetcode: binary tree 15 (find the value in the lower left corner of the tree)
Is it safe to open a mobile stock account? Is it reliable?
Is it safe for Galaxy Securities to open an account online?
【c语言】快速排序的三种实现以及优化细节
leetcode刷题:二叉树14(左叶子之和)
中金财富在网上开户安全吗?
Debezium series: modify the source code to support UNIX_ timestamp() as DEFAULT value
Let's talk about threadlocalinsecurerandom
C application interface development foundation - form control (5) - grouping control
Gstreamer中的task
2023年深圳市绿色低碳产业扶持计划申报指南
Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
Go language | 01 wsl+vscode environment construction pit avoidance Guide
Inventory of the most complete low code / no code platforms in the whole network: Jiandao cloud, partner cloud, Mingdao cloud, Qingliu, xurong cloud, Jijian cloud, treelab, nailing · Yida, Tencent clo
Ffplay document [easy to understand]
Is it safe for Anxin securities to open an account online?
Securerandom things | true and false random numbers
What is the function of okcc call center
Android interview classic, 2022 Android interview written examination summary
Float. The specific meaning of the return value of floattorawintbits is to convert float into byte array