• A datafile can be associated with only one tablespace and only one database • A datafile is physically made up of a number of operating system blocks... Segments, Extents, Blocks, and
Trang 1Oracle storage
Trang 2Tổng quan về tablespace và datafile
• Dữ liệu được lưu trữ luận lý trong segment (thông thường là table), và lưu trữ vật
lý trong datafile
• Một tablespace có thể chứa nhiều segment và được tạo thành từ nhiều datafile
Trang 3Mô hình lưu trữ dữ liệu Oracle
Trang 4Operating system block
• is the basic unit of I/O for file system
• is the minimum unit of data that the operating system can read or write
Trang 5• A datafile can be associated with only one tablespace and only one database
• A datafile is physically made up of a number of operating system blocks.
Trang 6Segments, Extents, Blocks, and Rows
• A segment is a set of extents that contains all the data for a specific logical storage structure within a tablespace
• Every segment is comprised of one or more extents
• An extent consists of a set of consecutively numbered blocks
• A data block is the smallest unit of data, Oracle Database stores data in data blocks
Trang 7The relationships among segments, extents, and data blocks
Trang 9Create and Manage Tablespaces
• Example: Using Tablespace
create tablespace tbs_user datafile ' userdata _01.dbf' size 10M
Create table T (a NUMBER)
tablespace tbs_user ;
Trang 10Bigfile and smallfile tablespace
• bigfile tablespace:
– Constain a single large file
– can be 1024 times larger than a smallfile tablespace
• Smallfile tablespace (default):
– can contain up to 1024 files
- CREATE BIGFILE TABLESPACE user_tbs
DATAFILE ‘oradata/grid/user_tbs01.dbf’ SIZE 1024 M;
- ALTER TABLESPACE user_tbs RESIZE 10G;
Trang 11Space Management in Tablespaces
• Extent Management
• Segment Space Management
Trang 12Extent Management
• Locally managed tablespaces (default)
– uses bitmaps stored in each datafile
– Each bit in the bitmap covers a range of blocks
– Bit value indicates free or used (0-free, 1 used)
• Dictionary-managed tablespaces
– Free extents recorded in data dictionary tables (SYS.UET$ and FET$)
Trang 13Extent Management
Locally Managed Tablespaces
• Every extent allocated in this tablespace will be 160MB, the bitmap needs only
64 bits
• Oracle will allocate extents of 64KB up to 16 extents, from which it will allocate progressively larger extents
create tablespace large_tabs datafile 'large_tabs_01.dbf' size 10g extent management local uniform size 160m;
create tablespace any_tabs datafile 'any_tabs_01.dbf' size 10g
extent management local autoallocate;
Trang 14Segment Space Management
• is set per tablespace and applies to all segments in the tablespace
• There are two techniques: manual or automatic
• There are five bitmaps for each segment: for full blocks used, 75- 100 percent used; 50 - 75 percent used; 25 - 50 percent used; and 0 - 25 percent used
Trang 15Segment Space Management
• For instance,
– if the block size is 4KB and the row to be inserted is 1500 bytes
– an appropriate block will be found by searching the 25 percent to 50 percent bitmap
– Every block on this bitmap is guaranteed to have at least 2KB of free space.
Trang 17Taking a Tablespace Online or Offline
• An online tablespace or datafile is available for use
• an offline tablespace or datafile exists as a definition in the data dictionary and
the controlfile but cannot be used
• cannot take the following tablespaces offline
– SYSTEM
– The undo tablespace
– Temporary tablespaces
Trang 18Taking a Tablespace Online or Offline
• ALTER TABLESPACE tablespacename OFFLINE [NORMAL | IMMEDIATE |
TEMPORARY];
– ALTER TABLESPACE users OFFLINE
• To bring a tablespace online
– ALTER TABLESPACE users ONLINE;
Trang 19Mark a Tablespace as Read Only
• makes the flights tablespace read-only:
– ALTER TABLESPACE flights READ ONLY;
• makes the flights tablespace writable:
– ALTER TABLESPACE flights READ WRITE;
Trang 20Rename a Tablespace and Its Datafiles
Trang 21Resize a Tablespace
• Add a data file
• Change the size of a data file
– Automatically
– Manually
Trang 22Add datafile to a tablespace
• alter tablespace storedata add datafile ‘STOREDATA_03.DBF' size 50m;
Trang 23Change size of datafile Manually
• alter database datafile '/oradata/users02.dbf' resize 10m;
Trang 24enable automatic extension of datafile
• alter database datafile ‘ \STOREDATA_03.DBF‘ autoextend on next 50m maxsize 2g;
Trang 25Dropping Tablespaces
• Tablespace removed from data dictionary
• Optionally, contents removed from data dictionary
• OS files can be deleted with the optional AND DATAFILES clause
– DROP TABLESPACE tbs_02 INCLUDING CONTENTS AND DATAFILES;
Trang 26Obtain Tablespace Info