课程目标:
1、如何存储表数据
当创建表时,将创建一个段以保存其数据。一个表空间包含一组段。
在逻辑上,一个表包含行和列。行最终以行块的形式存储在数据库块中。因为在某些情况下,整行可能不会被存储在一个地方,故称之为行块。当插入行太大以至于一个块装不下(行链接)或者更新导致行增长超过当前块的空闲空间(行迁移),就会出现这种情况。当一个表超过255列时也会使用行块。
2、数据块
数据块可以分为三部分:
块头增长的情况:
最初,块中的空闲空间是连续的。然而,删除和更新可能会产生碎片。可以在必要的时候进行合并。
3、查看存储结构
逻辑数据结构存储在数据库的物理文件中。可以通过EM查看您的数据库的逻辑结构。通过点击服务器页面存储区域的链接进行查看。
4、创建表空间
(1)单击“服务器”选项卡,然后单击存储的标题下“表空间”。
(2)单击“创建”。 注:如果你想创建一个与现有表空间类似的表空间,选择一个现有的表空间,然后从动作菜单选择“Create Like”。
(3)输入表空间名称。在区管理标题下,选择“本地管理”。使用本地管理方式管理表空间的区更加高效,“字典管理”是使用数据字典来进行区管理,Oracle不推荐使用,此处是为了向后兼容。在“类型”标题下选择“永久”, 永久存储由系统或用户创建的数据库对象。在”状态”,选择“读写”, 读写状态是默认选项,用户可以读写创建后的表空间写。
(4)在“数据文件”区域,单击“添加”按钮为表空间增加数据文件。
一个表空间必须至少有一个数据文件。根据你的环境选择合适的存储类型。非常大的数据库可以使用大文件表空间,其中ASM或其他逻辑卷管理器支持条带或独立磁盘冗余阵列(RAID)和动态扩展逻辑卷。在“添加数据文件”页中选择所需的存储类型和输入所需的信息。如果是ASM,则磁盘组是必需的。如果是文件系统,则需要输入数据文件的文件名和路径。然后输入文件大小。在”存储“”部分,选择“数据文件满后自动扩展”,然后指定的增量大小。空间用完后会自动扩展,但受物理磁盘大小限制。可以指定数据文件的最大值也可以不指定。
点击“显示SQL”可以看到创建这个表空间的SQL语句:
CREATESMALLFILETABLESPACE"TS03"DATAFILE'+DATA'SIZE100MAUTOEXTENDONNEXT10MMAXSIZEUNLIMITEDLOGGINGEXTENTMANAGEMENTLOCALSEGMENTSPACEMANAGEMENTAUTO
点击“确定”完成表空间创建。
4、表空间的存储选项
区分配:“本地管理”表空间的区分配有下面两种方式:
段空间管理:“本地管理”表空间的段空间管理有下面两种方式:
压缩选项:默认情况下禁用数据段压缩。启用数据段压缩可以节省磁盘空间的使用,减少在缓存中的内存使用,并在读取时加快查询执行。然而,在数据加载和DML会增加CPU的开销。在有长时间读取操作的联机分析处理(OLAP)系统特别有用,但也可以用于联机事务处理(OLTP)系统。
日志:表空间中的段默认都是记录日志的,将对表空间对象的更改写入到联机重做日志文件。如果没有启用日志,对象的数据丢失是不可恢复的。当创建对象而不启用日志记录时,如果想让对象可恢复,则必须备份这些对象。
如果数据库是在FORCE LOGGING模式,将覆盖此处日志的设置。可以在数据库创建或数据库创建后使用alter database force logging语句将数据库置于FORCE LOGGING模式。
块信息:可以选择表空间块的大小。如果没有设置其他块大小的初始化参数(db_nk_cache_size),则不能选择其他值。如果设置了其他块大小的初始化参数(db_nk_cache_size),则可以选择设置的值。
5、数据库自带的表空间
创建数据库的时候系统创建的表空间:
例子:使用EM查看SYSAUX表空间使用情况
6、修改表空间
创建表空间后,可以进行如下修改:
例子:修改表空间
7、表空间的操作
8、删除表空间
可以删除表空间及其内容(在表空间中的段),需要DROP TABLESPACE系统权限。
当删除一个表空间,控制文件的文件指针被删除。如果使用Oracle-managed files(OMF),对应操作系统文件(数据文件)也会被删除。如果没有使用OMF,可以选择让Oracle服务器去删除对应的操作系统文件,也可以手动删除操作系统文件。
不能删除包含活动段的表空间。最好在删除前将表空间脱机。
例子:删除表空间
9、查看表空间信息
点击”查看”查看选定的表空间信息。在查看表空间的页,可以点击编辑修改表空间。
可以通过数据字典查询表空间和数据文件的信息:
例子:查看表空间及对应的数据文件
SQL> select tablespace_name,file_name from dba_data_files;
TABLESPACE_NAME FILE_NAME
------------------------------ ------------------------------------------------------------
USERS +DATA/stone/datafile/users.259.893370691
UNDOTBS1 +DATA/stone/datafile/undotbs1.258.893370691
SYSAUX +DATA/stone/datafile/sysaux.257.893370691
SYSTEM +DATA/stone/datafile/system.256.893370691
EXAMPLE +DATA/stone/datafile/example.265.893370807
TS02 +DATA/stone/datafile/ts02.268.898602153
TS01 +DATA/stone/datafile/ts01.dbf_reorg0
7 rows selected.
10、查看表空间内容
“显示表空间内容”页面可以看到表空间详细信息,段的信息以及区映射。
例子:查看表空间内容
11、Oracle-Managed Files(OMF)
使用OMF避免了在Oracle数据库中直接管理操作系统文件,特定的操作只需要使用数据库对象而不需要使用文件名,下面的数据库结构都可以使用OMF:
例子:查看参数DB_CREATE_FILE_DEST,并创建表空间不指定数据文件,使用默认值自动创建数据文件(大小100M,自动扩展,增量100M)
SQL> show parameter db_create_file_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string +DATA
SQL> create tablespace tbs_1;
Tablespace created.
SQL> select tablespace_name,file_name,bytes/1024/1024 from dba_data_files where tablespace_name='TBS_1';
TABLESPACE_NAME FILE_NAME BYTES/1024/1024
------------------------------ -------------------------------------------------- ---------------
TBS_1 +DATA/stone/datafile/tbs_1.269.898717219 100
不要对OMF管理的文件重命名,不然数据库识别不到。ASM默认使用OMF,但是如果在表空间创建的时候给ASM数据文件指定了别名或者给现有的表空间增加了一个ASM数据文件,则该文件将不使用OFM。
12、扩展数据库
可以通过如下方式扩展数据库空间:
13、相关习题
(1)You executed the following command to create a tablespace called SALES_DATA:
SQL> CREATE TABLESPACE sales_data
DATAFILE SIZE 100M
SEGMENT SPACE MANAGEMENT AUTO;
Which two statements are true about the SALES_DATA tablespace? (Choose two)
A. The database automatically determines the extent-sizing policy for the tablespace.
B. The segments are automatically shrunk when the contents are removed from them.
C. The allocation of extents within the tablespace is managed through the dictionary tables.
D. The space utilization description of the data blocks in segments is recorded in bitmap blocks.
E. The space utilization description of the data blocks in segments is managed through free lists.
答案:AD
(2)See the Exhibit:
Which statements are true regarding the USERS tablespace? (Choose all that apply.)
A. A bitmap is used to record free extents
B. Free extents information is managed within the tablespace
C. Free extents information is managed in the SYSAUX tablespace
D. The data dictionary tables are updated when extents are allocated or deallocated
答案:AB
(3)SQL> CREATE BIGFILE TABLESPACE MRKT
2 DATAFILE '/u01/app/oracle/oradata/orcl/mrkt.dbf' size 10M LOGGING
3 EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
Tablespace created.
SQL> ALTER DATABASE DEFAULT TABLESPACE MRKT;
Database altered.
Which two statements are true regarding the MRKT tablespace? (Choose two.)
A. No more data files can be added to the tablespace.
B. Segment space is managed by free lists in the tablespace.
C. A user created without being assigned a default tablespace uses this tablespace.
D. The tablespace can be dropped with the current setting with segments present in it.
答案:AC
(4)Examine the command that is used to create a table:
SQL> CREATE TABLE orders (
oid NUMBER(6) PRIMARY KEY,
odate DATE,
ccode NUMBER (6),
oamt NUMBER(10,2)
) TABLESPACE users;
Which two statements are true about the effect of the above command? (Choose two.)
A. A CHECK constraint is created on the OID column.
B. A NOT NULL constraint is created on the OID column.
C. The ORDERS table is the only object created in the USERS tablespace.
D. The ORDERS table and a unique index are created in the USERS tablespace.
E. The ORDERS table is created in the USERS tablespace and a unique index is created on the OID column in the SYSTEM tablespace.
答案:BD
(5)You configured the Flash Recovery Area for your database. The database instance has been started in ARCHIVELOG mode and the LOG_ARCHIVE_DEST_1 parameter is not set.
What will be the implications on the archiving and the location of archive redo log files?
A. Archiving will be disabled because the destination for the redo log files is missing
B. The database instance will shut down and the error details will be logged in the alert log file
C. Archiving will be enabled and the destination for the archived redo log file will be set to the Flash Recovery Area implicitly
D. Archiving will be enabled and the location for the archive redo log file will be created in the default location $ORACLE_HOME/log
答案:C
(6)Identify two situations in which the block header grows in a data block. (Choose two.)
A. When row directories need more row entries
B. When there is row migration in the data block
C. When there is an increase in the PCTFREE value for the data block
D. When more transaction slots are required than are initially configured
答案:AD
(7)View the Exhibit. You want to create a tablespace to contain objects with block size 16 KB. But while configuring the storage you find that the block size that you can provide is only 8 KB.
Which configuration could have enabled the block selection of 16 KB?
此主题相关图片如下:
A. Choosing the extent allocation type to uniform
B. Choosing the Segment Space Management option to manual
C. Setting autoextension on for the data file mentioned for the tablespace
D. Setting the DB_16K_CACHE_SIZE parameter for the database instance to a nonzero value
答案:D
(8)User SCOTT wants to perform a bulk insert operation in the EMP_DEP table. SCOTT receives the following error after the INSERT statement is issued and few rows are inserted:
INSERT INTO EMP_DEP (emp_id,name,salary,dep_name,mgr_id)
*
ERROR at line 1:
ORA-01653: unable to extend table SCOTT.EMP_DEP by 128 in tablespace USERS
Identify two actions either of which will help you resolve this problem. (Choose two.)
A. Grant the RESOURCE role to SCOTT.
B. Add data files to the USERS tablespace.
C. Grant the CREATE ANY TABLE privilege to SCOTT.
D. Increase the space for SCOTT on the USERS tablespace.
E. Increase the size of the data file associated with the USERS tablespace.
答案:BE
(9)You execute the following command to change the status of the SALES tablespace:
SQL> ALTER TABLESPACE sales OFFLINE;
Which statements describe the effect of the command? (Choose all that apply.)
A. The tablespace would require recovery to go back online.
B. A checkpoint is taken on all data files that are associated with the SALES tablespace.
C. The sessions that subsequently try to access the objects in the SALES tablespace receive an error.
D. The new status of the SALES tablespace is recorded in the control file when the database instance is closed.
答案:BC
(10)You configured the Flash Recovery Area (FRA) for your database. The database instance is running in ARCHIVELOG mode. The default location for the archived redo log files is the Flash Recovery Area.
Which two files are removed automatically if the space is required in the FRA as per the retention policy? (Choose two.)
A. Flashback log files
B. Backups that have become obsolete
C. User managed backups of the data files and control files
D. Archived redo log files that have multiple copies in a different archive location and not backed up
答案:AB
(11)The user HR receives the following error while inserting data into the TTK table:
ERROR at line 1:
ORA-01653: unable to extend table HR.TTK by 128 in tablespace SMD
Upon investigation, you find that SMD is a small file tablespace.
Which three action would allow the user to insert data? (Choose three.)
A. Add a data file to the SMD tablespace.
B. Add a data file to the temporary tablespace associated with the user HR.
C. Resize the data file associated with the SMD tablespace to make it larger.
D. Alter the data file associated with the SMD tablespace to grow automatically.
E. Change the segment space management for the SMD tablespace to automatic.
答案:ACD
欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) | Powered by Discuz! X3.2 |