学习笔记八(managing tablespaces and data files)

分了三天总算听完了,而且很多概念也是这样澄清的,的确蛮不错的   ------managing tablespaces and data files

[@more@]

--8 managing tablespaces and data files
---database strorage hierarchy
database ---
tablespace ---logical area
segment--specific logical structure occupied space collection(某一个特定的存

储结构所占用的space得集合)
     exp:table/index/temp/rollback虽然oracle里有很多很多数据对象如有函数,有

视图,有存储过程,有表,有index,但是从段的角度来讲在数据库的环境里面可以归结

为我们的段只有这table/index/temp/rollback四类,数据库可以申请空间分配的单位除

了table and index外其它都是没有的,temp是用来支持排序的时候所存放的临时的结果

集,rollback在数据改变过程中用来存放数据改变的旧值,用来提供数据的读一致性,

rollback transaction 帮助recovery
段就是某一个特定的逻辑结构所占用的空间的集合,一个表所占用的空间的集合就是一

个段,一个tablespace 可以有多个段
database 就是一个大的房子,database 根据他的特征可以将这个房子分成多个房间如

厨房,卫生间,阳台,客厅等等segment就是每个房间里面的桌子,椅子,电脑,床,沙

发等等这些实体所占用空间的集合就是一个一个的段
table随着数据的插入空间则越来越大需要分配空间通过extent分配
extent---allocate unit(空间分配单位--分区)
block---use&store unit(是oracle 使用和存储单位)一个分区由多个块组成,且分区的

单位一定是块的整数倍
一个tablespace由一个or 多个datafile组成类似房子10几平方米这种空间的来源是操作

系统,所以就是来自datafile了,
一个段不可以跨表空间(分区表已经是多个段的概念)但是它可以跨数据文件,在空间分

配的时候分区支援的来源只能来自于一个datafile
oracle块是os块的整数倍
sql>select * from v$tablespace;
查到系统里面的表空间
sql>select * from v$datafile;
查到系统里面的datafile
sql>select t1.name,t2.name
2 from v$tablespace t1,v$datafile t2
3 on t1.ts#=t2.ts#;
error ora-00933 sql命令为正确结束
sql>l3
sql> c /on/where/
sql>run
可见tablespace and datafile的对应关系
/
---system and Non-system tablespace
1.system tablespace
A.create with the database
B.contains the data dictionary
C.contains the system undo segment
sql>select * from dba_rollback_segs;

2.non-system tablespace
A.separate segments(用来分离段,例如将table and index等放在不同的segment)
B.ease space administration
C.control amount of space allocated to a user(控制user使用空间的配额)
sql>alter user scott quota 10m on users;(限定scott对users表空间的使用配额为

10m)
/
---create tablespace command
create tablespace xxx
[datafile 'xxx'] --OMF管理的话就可以没有该项
[size xxx  ---kb,mb]
[extent management local/dictionary]
[default storage(xxx)]如果使用local管理的模式的话default storage是不可以指定


sql>create tablespace test
2 datafile 'd:oracletest.dbf' size 5m
3 extent management dictionary
4 default storage(
5 initial 100K,
6 next 100k,
7 pctincrease 10)
8 offline;
error ora-02143无效的storage 选项
sql>l5
sql>c /,/
sql>l6
sql>c /,/
sql>run
另:9i里在创建tablespace的时候可以指定不同大小的块单位但前提是设定了不同大小的

catch 区

sql>create tablespace test1
2 datafile 'd:oracletest1.dbf' size 5m
3 extent management local
4 default storage(
5 initial 100K)
error ora-25143默认存储字句与分配策略不兼容
sql>l5
sql>del 5
sql>l
sql>del 4
sql>l
sql>input uniform size 1m (统一大小)
sql>run
/
---space management in tablespaces
1.locally managed tablespace
A.free extents recorded in bitmap
B.each bit corresponds to a block or group of blocks
C.bit value indicates free or used
(自有分区记录在位图里面相当于在表空间的某个部分开一个位图区域纪录自由分区的纪

录,每一位由零or 一来决定对应的分区是否已经分配,他避免了dictionary

management的弊端所以建议使用local management)
2.Dictionary-managed tablespaces
A.default method(缺省的管理方式跟以前版本是兼容的)
B.free extents recorded in data dictionary tables(自由分区是记录在数据字典表

里面的所以在空间分配使用的过程中都与数据字典有关,比如分区被分配后在数据字典

里面有记录,在此涉及到修改系统表所以他跟系统表之间存在资源争用而且修改系统表

时产生回滚数据,同时产生一些空间带来的负担,所以dictionary management现在已经

不建议使用了推荐使用local management)
/
---locally managed tablespace
本地管理空间分配有两种方式1.uniform size(统一大小)和 自动分配
A.Reduced contention on data dictionary tables
B.no undo generated when space allocation or deallocation occurs(被分配or 收

缩)
C.no coalescing required(没有碎片压缩的问题)
exp:
sql>create tablespace test2
2 datafile 'd:oracletest2.dbf' size 5m
3 extent management local autoallocate;
本地管理自动分配
/
---dictionary managed tablespaces
A.extents are managed in the data dictionary
B.each segment stored in the tablespace can have a different storage clause(

每个段存储在表空间里可以有不同的存储参数)
C.coalescing required(会产生碎片)
create tablespace xxx
[datafile 'xxx'] --OMF管理的话就可以没有该项
[size xxx  ---kb,mb]
[extent management local/dictionary]
[default storage(xxx)]--initial /next/pctincrease/min extents..
/
---changing the storage settings
sql>alter tablespace test
2 minimum extent 10;
sql>alter tablespace test
2 default storage(
3 initial 1m
4 next 1m
5 pctincrease 20);
注意test tablespace 是采用dictionary management
对于local management 的tablespace 什么都不可以改变,除了log in log no
/
---undo tablespace

---undo tablespace
1.used to store undo segments
2.cannot contain any other objects(不能放其他任何数据对象)
3.extents are locally managed
4.can only use the DATAFILE and EXTENT MANAGEMENT clauses of the CREATE

TABLESPACE command


undo segements
记录数据改变的旧值,
undo 的作用
A.提供读一致性
B.允许ROLL BACKUP TRANSACTION
EXP
SQL>delete scott.emp
sql>select * from scott.emp;
未选定行
sql>rollback;
sql>select * from scott.emp;
看到又有值被选中
当我们Delete 的时候将表里面的资料标记为删除状态,但是旧数据记录在rollback

segement,只要没有确认则rollback后又会将旧资料从rollback segement里面取出来放

到table里面
C.在系统当掉以后restart db后做roll back roll forword时需要利用到roll back

segement里资料来完成recovery,同时提供读一致性。

sql>show parameter undo;
可见undo 可以实现自动管理了
2's exp
sql>create undo tablespace test3 datafile 'd:oracletest.ora' size 5m
extent management local;
sql>create table test4 (id int) tablespace test3 ;
error ora-30022无法在撤销表空间中创建段
/
---temporary tablespace
1.used for sort operations
2.cannot contain any permanent objects
3.locally managed extents recommended(建议采用locally managed)
exp
sql>select * from scott.emp  order by empno desc;
在排序时oracle 先在内存里排序,如果内存不够则找temp tablespace用来排序;
sql>create temporary tablespace test4 tempfile 'd:oracletest4.ora' size 5m
extent management local;
sql>create table test4 (id int) tablespace test4;
error ora-02195尝试创建的permanent 对象在temporary 表空间中
/
---default temporary tablespace
1.allows you to specify a databasewide default temporary tablespace
2.eliminates the use of the system tablespace for storing temporary data
3.can be created using the CREATE DATABASE OR ALTER DATABSE command
4.when created with the CREATE DATABSE command,the default temporary

tablespace is locally managed
/
---restrictions on default temporary tablespace
1.it cannot be dropped until after a new default is made available
2.it cannot be tabken offline;
3.you cannot alter the default temporary tablespace to a permanent

tablespace.
4.在initfile里面没有记录,如果坏掉的话只是简单的重建就OK了
5.cannot contain any permanent objects
制定某个表空间是我们的default临时表空间的command
sql>alter system set default temporary tablespace test4;
sql>alter tablespace test4 offline/read only ;
error ora-03217变更temporary tablespace 无效的选项

sql>alter tablespace test4 read only;
error ora-03217变更temporary tablespace 无效的选项
/
---Offline status
1.部分的关闭database
sql>select * from scott.emp;
sql>alter tablespace users offline;
sql>elect * from scott.emp;
error ora-00376 此时无法读取文件8
     ora-01110数据文件8 'd:oracleuser01.dbf'
2。并不是所有表空间都可以offline
如:
A.SYSTEM tablespace
B.tablespaces with active undo segements
C.default temorary tablespac
这三种不可以离线

3。to take a tablespace offline command
sql>alter tablespace users offline;
4.to bring a tablespace online command
sql>alter tablespace users online;
/
---read only tablespace
Use the following command to place a tablespace in read-only mode:
sql>alter tablespace users read only;
1.tablespace available only for read operations

2.objuects can be dropped from tablespace
SQL>delete scott.emp;
error ora-00372此时无法修改文件8
ora-0110数据文件8:'d:oracleusers01.dbf'
sql>drop table scott.emp;则可以删除

3.to create a read only tablesapce on a removable media drive:
A.ALTER TABLESAPCE ...READ ONLY;
B.Move the data file to the WORM drive
C.ALTER TABLESPACE ...RENAME DATAFILE...;
/
---drop tablespace
1.tablespace removed from data dictionary
2.optionally,contents removed from data dictionary
3.os files can be deleted with the optional
AND DATAFILES clause
DROP TABLESPACE USERS INCLUDING CONTENTS AND DATAFILES;
oracle 8i里面只能drop 掉including contents即删除tablespace 里面的内容但是不可以删除数据文件9i新增了该功能
exp
sql>create table test5 (id int) tablespace test4;
sql>drop tablespace test4
error ora-01549 表空间非空,请使用including contents选项
sql>input including contents
sql>run
此时表空间被删除同时表空间里的内容及在控制文件里面所包含的内容也被删除,但是os 里面的datafile没有删除
sql>drop tablespace  test4 including contents and datafiles;
此时连数据文件都删除掉了。
/
---resizing a tablespace
1.add a data file
2.change the size of a data file
A.Automatically
B.Manually
/
---enabling automatic extension of data files
alter database datafile 'd:oracleusers.dbf' size 200M autoextend on next 10M maxsize 500M
SQL>alter database datafile 'd:oracleusers.dbf' autoextend on;
/
---change the size of data files manually

SQL>alter database datafile 'd:oracleusers.dbf' resize 500M;
Resize 可以改大也可以改小
/
---adding data files to a tablespace
alter tablespace users add datafile 'd:oracleusers02.dbf' size 200m;
/
---moving data files ALTER TABLESPACE
1.THE tablespace must be offline.
2.the target data files must exist.
alter tablespace users rename datafile 'd:oracleusers.dbf' to 'd:oracleoradatausers.dbf'
sql>alter tablespace users offline;
然后在os 处将user.dbf更名为users01.dbf
然后
sql>alter tablespace users rename datafile 'd:oracleusers.dbf' to 'd:oracleusers01.dbf'
以上可以用来改变数据文件的位置or 数据文件的名字
注意如前所述并不是所有的表空间都可以离线,所以
sql>alter tablespace system offline;
error ora-01541系统表空间无法脱机,如有必要清关闭
如果要对system01.dbf改名的话做法为:
1.shutdow db
2.startup mount;
3.alter database rename datafile 'pathsystem01.dbf' to 'newpathsystem01.dbf'
/
---configuring oracle managed files for tablespace creation
1.creating a tablespace with OMF requires the configuration of one initialization parameter
2.DB_CREATE_FILE_DEST:set to give the default location for data files
3. the initialization parameter can be set in an initialization file or set dynamically with the ALTER SYSTEM command
alter system set DB_CREATE_FILE_DEST='PATH'
/
---Create tablespace with OMF
1.With OMF configured the DATAFILE clause of the CREATE TABLESPACE test DATAFILE SIZE 20M
2.the data file is created in the file system specified by DB_CREATE_FILE_DEST.
3.by default files are 100M in size and set to autoextend with an unlimited restrication
4.when the tablespace is dropped ,all files are also deleted at the OS level.
5.AN OMF can be added to an existing tablespace
exp
sql>alter system set db_create_file_dest='d:oracleoralog';
sql>create tablesapce omftbspace;
看到os 文件
sql>drop tablespace omftbspace;
os 文件也不见了
/
---Obtaining Tablespace Information
Obtaining tablespace and data file information can be obtained by querying the following:
Tablespace information:
DBA_TABLESPACES
V$TABLESPACE
Data file information:
DBA_DATA_FILES
V$DATAFILE
Temp file information:
DBA_TEMP_FILES
V$TEMPFILE
待续。。。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/202861/viewspace-796797/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/202861/viewspace-796797/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值