oracle 03-06 高级空间管理

Posted 世界树

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle 03-06 高级空间管理相关的知识,希望对你有一定的参考价值。

Managing Space

Objectives
After completing this lesson, you should be able to:
• Describe how the Oracle Database server automatically manages space
• Save space by using compression 压缩
• Proactively主动的 monitor监听 and manage tablespace space usage 使用(情况)
• Describe segment段 creation in the Oracle database
• Control deferred延迟 segment creation
• Use the Segment Advisor指导
• Reclaim回收 wasted space from tables and indexes索引 by using the segment shrink收缩 functionality
• Manage resumable可恢复的 space allocation分配的东西

 

目标

完成本课程后,您应该能够:

•描述Oracle数据库服务器如何自动管理空间

•通过压缩节省空间

•主动监视和管理表空间使用情况

•描述Oracle数据库中的段创建

•控制延迟段创建

•使用Segment Advisor

•使用段收缩功能从表和索引中回收浪费的空间

•管理可恢复空间分配

 

Space Management: Overview
Space is automatically managed by the Oracle Database server. It generates alerts about potential problems and recommends possible solutions. 
Features include:
• Oracle Managed Files (OMF)
• Free-space management with bitmaps (“locally managed”) and automatic data file extension
• Proactive space management (default thresholds and server-generated alerts)
• Space reclamation (shrinking segments, online table redefinition)
• Capacity planning (growth reports)

空间管理:概述

空间由Oracle数据库服务器自动管理。它会生成有关潜在问题的警报,并建议可能的解决方案。

功能包括:

•Oracle托管文件(OMF)

•具有位图(“本地管理”)和自动数据文件扩展名的可用空间管理

•主动空间管理(默认阈值和服务器生成的警报)

•空间回收(收缩段,在线表格重新定义)

•容量规划(增长报告)

 

 

  ASMM机制控制预留空间PCTFREE = 10 预留10% 为updata准备

 

Row Chaining and Migration
Example:
• On update: Row length increases,exceeding the available free space in the block.
• Data needs to be stored in a new block.
• Original原始 physical identifier标识符 of row (ROWID) is preserved保留.
• The Oracle Database server needs to read two blocks to retrieve检索 data.
• The Segment Advisor finds segments containing the migrated迁移 rows.
• There is automatic coalescing合并 of fragmented碎片 free space inside the block.

Original block with pointer指针 to migrated迁移 row

行链接和迁移

例子:

更新时:行长度增加,超过块中的可用可用空间。

数据需要存储在新的块中。

保留行的原始物理标识符(ROWID)。

Oracle数据库服务器需要读取两个块才能检索数据。

Segment Advisor查找包含迁移行的段。

在块内有碎片自由空间的自动合并。

 

When a row is chained or migrated, the I/O performance associated with this row decreases because the Oracle Database server must scan more than one data block to retrieve the information for the row.

True

当一行被链接或迁移时,与该行关联的I/O性能会降低,因为Oracle数据库服务器必须扫描多个数据块才能检索该行的信息

 

Types of Segments
• A segment is a set of extents allocated for a certain logical structure. The different types of segments include:
– Table and cluster segments
– Index segment
– Undo segment
– Temporary segment
• Segments are dynamically allocated by the Oracle Database server.

段的类型

段是为某个逻辑结构分配的一组区段。不同类型的段包括:

表段和簇段

索引段

撤消段

临时段

段由Oracle数据库服务器动态分配。

 

SQL> show user
USER is "SYS"
SQL> desc dba_segments 查看静态视图

 

SQL> select distinct segment_name from dba_segments; 查看数据库中所有段的名称

SQL> select distinct segment_type from dba_segments; 查看数据库中所有段的类型

EGMENT_TYPE
------------------
INDEX   索引段
CLUSTER
TABLE PARTITION
LOBINDEX  
TABLE SUBPARTITION
LOBSEGMENT
INDEX PARTITION
ROLLBACK  回退段
TABLE  表段
LOB PARTITION
NESTED TABLE

SEGMENT_TYPE
------------------
TYPE2 UNDO

12 rows selected.

 

Allocating Extents
• Searching the data file’s bitmap for the required number of adjacent free blocks
• Sizing extents with storage clauses:
– UNIFORM
– AUTOALLOCATE
• Viewing extent map
• Obtaining deallocation advice

 

 

分配范围

在数据文件的位图中搜索所需数量的相邻空闲块

使用存储子句调整范围大小:

指定分配

自动分配

查看范围图

获取解除分配通知

 

Understanding Deferred Segment Creation
• DEFERRED_SEGMENT_CREATION = TRUE is the default.
• Segment creation takes place as follows:
1. Table creation > Data dictionary operation
2. DML > Segment creation
CREATE TABLE INSERT INTO
• Saving disk space
• Improving installation time of big applications

段的延迟创建

默认为延迟段和CREATION=TRUE。

段创建过程如下:

一。表创建>数据字典操作

2。DML>段创建

创建表不插入

节省磁盘空间

提高大型应用程序的安装时间 

 

SQL> show parameter segment  显示参数段

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
deferred_segment_creation boolean TRUE
rollback_segments string
transactions_per_rollback_segment integer 5
SQL>

 

SQL> conn hr/hr
Connected.
SQL> select segment_name from user_segments where segment_type=\'TABLE\';

SEGMENT_NAME
--------------------------------------------------------------------------------
DEPARTMENTS
EMPLOYEES
JOBS
JOB_HISTORY
LOCATIONS
REGIONS

6 rows selected.  显示hr下的表,共有6张

 

SQL> create table seg_test (col1 number);  创建一张表

SQL> insert into seg_test values(10);  在创建的表中添加一行数字

 

SQL> select segment_name from user_segments where segment_type=\'TABLE\'; 再次查看段

SEGMENT_NAME
--------------------------------------------------------------------------------
DEPARTMENTS
EMPLOYEES
JOBS
JOB_HISTORY
LOCATIONS
REGIONS
SEG_TEST   这事新增的段

7 rows selected.   变成了7个段

 

 

 

 

 

Controlling Deferred Segment Creation
With the DEFERRED_SEGMENT_CREATION parameter in the:
• Initialization file
• ALTER SESSION command
• ALTER SYSTEM command
With the SEGMENT CREATION clause:
• IMMEDIATE
• DEFERRED (default)
CREATE TABLE SEG_TAB3(C1 number, C2 number)
SEGMENT CREATION IMMEDIATE TABLESPACE SEG_TBS;
CREATE TABLE SEG_TAB4(C1 number, C2 number)
SEGMENT CREATION DEFERRED; 表示对段延迟创建
Note: Indexes inherit table characteristics.

 

Restrictions and Exceptions
• Segment creation on demand is:
– Only for nonpartitioned tables and indexes
– Not for IOTs, clustered tables, or other special tables
– Not for tables in dictionary-managed tablespaces
• If you were to migrate a table without segments from a locally managed to a dictionary-managed tablespace, you must drop and re-create it.

限制和例外

按需创建细分市场是:

仅适用于非分区表和索引

物联网、集群表或其他特殊表的说明

不适用于字典管理表空间中的表

如果要将不带段的表从本地管理的表空间迁移到字典管理的表空间,则必须删除并重新创建它。

 

Which of the following statements are true?
a. Deferred segment creation is always enabled. You cannot control it.
b. You can control the deferred segment creation with the SEGMENT CREATION clause of the CREATE TABLE command.
c. Segment creation on demand is available for all types of tables, including those owned by the SYS user.
d. Segment creation on demand is available for nonpartitioned tables.

以下哪项陈述是正确的?

a、 始终启用延迟段创建。你无法控制它。 错的:可在实例级或会话级别通过设置延迟段参数指定。可在创建表的时候通过对延迟字段属性进行管理

b、 可以使用CREATE TABLE命令的segment creation子句控制延迟的段创建。  对的

c、 所有类型的表(包括SYS用户拥有的表)都可以按需创建段。 错的:延迟创建功能只对普通的堆表试用,数据字典表等就不适用延迟创建

d、 无分区表可按需创建段。 对的

 

 

 

 

 

 

Table Compression: Overview
Reducing storage costs by compressing all data:
• Basic compression for direct-path insert operations: 10x
• Advanced row compression for all DML operations: 2–4x
Compression
Method
Compression
Ratio
CPU
Overhead
CREATE and ALTER
TABLE Syntax
Typical
Applications
Basic table
compression
High Minimal COMPRESS [BASIC] DSS
Advanced row
compression
High Minimal
ROW STORE COMPRESS
ADVANCED
OLTP, DSS

表压缩:概述

通过压缩所有数据降低存储成本:

直接路径插入操作的基本压缩:10倍

所有DML操作的高级行压缩:2-4x

压缩

方法

压缩

比率

中央处理器

头顶上。

创建和其他

表语法

典型的

应用

基本表

压缩

高最小压缩(基本)决策支持系统

高级行

压缩

高最小值

行大压缩

高级的

OCTs,决策支持系统

 

 

Advanced Row Compression for DML Operations
• Is enabled with
CREATE TABLE … ROW STORE COMPRESS ADVANCED …;
• Is recommended for active OLTP environments

DML操作的高级行压缩

已启用

创建表…行高级压缩。。。

建议用于活动OLTP环境

 

 

Specifying Table Compression
You can specify table compression for:
• An entire heap-organized table
• A partitioned table (Each partition can have a different type or level of compression.)
• The storage of a nested table
You cannot :
• Specify basic and advanced row compression on tables with more than 255 columns
• Drop a column if a table is compressed for direct-loads, but you can drop it if the table is advance row compressed

指定表压缩

可以为以下对象指定表压缩:

整个堆组织的表

分区表(每个分区可以有不同类型或级别的压缩)

嵌套表的存储

你不能:

对超过255列的表指定基本和高级行压缩

如果表是为直接加载而压缩的,则删除列;如果表是高级行压缩的,则可以删除列

 

Using the Compression Advisor
The Compression Advisor:
• Analyzes objects to give an estimate of space savings for different compression methods
• Helps in deciding the correct compression level for an application
• Recommends various strategies for compression
– Picks the right compression algorithm for a particular data set
– Sorts on a particular column for increasing the compression ratio
– Presents tradeoffs between different compression algorithms
• Works for OLTP compression (via Enterprise Manager)

使用压缩顾问

压缩顾问:

分析对象以估计不同压缩方法的空间节省

帮助确定应用程序的正确压缩级别

建议各种压缩策略

为特定数据集选择正确的压缩算法

对特定列排序以提高压缩比

显示不同压缩算法之间的折衷

适用于OLTP压缩(通过Enterprise Manager)

 

Using the DBMS_COMPRESSION Package
To determine optimal compression ratios:
BEGIN
DBMS_COMPRESSION.GET_COMPRESSION_RATIO (\'USERS\',\'SH\',\'SALES\',
NULL,DBMS_COMPRESSION.COMP_FOR_OLTP, blkcnt_cmp, blkcnt_uncmp,
rowcnt_cmp, rowcnt_uncmp, comp_ration, comptype);
DBMS_OUTPUT.PUT_LINE(\'Blk count compressed = \' || blkcnt_cmp);
DBMS_OUTPUT.PUT_LINE(\'Blk count uncompressed = \' ||
blkcnt_uncmp);
DBMS_OUTPUT.PUT_LINE(\'Row count per block compressed = \' ||
rowcnt_cmp);
DBMS_OUTPUT.PUT_LINE(\'Row count per block uncompressed = \' ||
rowcnt_uncmp);
DBMS_OUTPUT.PUT_LINE(\'Compression type = \' || comptype);
DBMS_OUTPUT.PUT_LINE(\'Compression ratio = \'||comp_ratio||\' to 1\');

 

Proactive Tablespace Monitoring  主动表空间监视

 

 

Thresholds and Resolving Space Problems
Resolve space problem by:
• Adding or resizing data file
• Setting AUTOEXTEND ON
• Shrinking objects
• Reducing UNDO_RETENTION
• Checking for long-running queries in temporary tablespaces

阈值与空间问题的解决

通过以下方式解决空间问题:

添加或调整数据文件的大小

启用自动扩展

缩小对象

减少和重定向

在临时表空间中检查长时间运行的查询

 

Monitoring Tablespace Space Usage
• Read-only and offline tablespaces: Do not set up alerts.
• Temporary tablespace: Threshold corresponds to space currently used by sessions.
• Undo tablespace: Threshold corresponds to space used by active and unexpired extents.
• Auto-extensible files: Threshold is based on the maximum file size.

监视表空间空间使用情况

只读和脱机表空间:不设置警报。

临时表空间:阈值对应于会话当前使用的空间。

撤消表空间:阈值对应于活动范围和未过期范围使用的空间。

自动扩展文件:阈值基于最大文件大小。

 

 

  

Results of Shrink Operation
• Improved performance and space utilization
• Indexes maintained
• Triggers not executed
• Number of migrated rows may be reduced.
• Rebuilding secondary indexes on IOTs recommended

收缩操作结果

提高性能和空间利用率

维护的索引

触发器未执行

迁移的行数可能会减少。

建议重建物联网二级指标

 

Reclaiming Space Within ASSM Segments
• Online and in-place operation
• Applicable only to segments residing in ASSM tablespaces
• Candidate segment types:
– Heap-organized tables and index-organized tables
– Indexes
– Partitions and subpartitions
– Materialized views and materialized view logs

回收ASSM段内的空间

在线和就地操作

仅适用于ASSM表空间中的段

候选段类型:

堆组织表和索引组织表

索引(索引)

分区和子分区

物化视图和物化视图日志

 

 

Automatic Segment Advisor
The Automatic Segment Advisor:
• Is started by a Scheduler job set to run during the default maintenance window:
– Weeknights, Monday–Friday, from 10:00 PM to 2:00 AM
– Saturday and Sunday, both windows start at 6:00 AM and last for 20 hours
• Examines database statistics, samples segment data, and then selects the following objects to analyze:
– Tablespaces that have exceeded a critical or warning threshold
– Segments that have the most activity
– Segments that have the highest growth rate

自动分段顾问:

由设置为在默认维护窗口期间运行的计划程序作业启动:

周末,周一至周五,晚上10:00至凌晨2:00

星期六和星期天,两个窗口都从早上6:00开始,持续20小时

检查数据库统计信息、采样段数据,然后选择要分析的以下对象:

超过临界或警告阈值的表空间

最活跃的部分

增长率最高的细分市场

 

 

 

 

Managing Resumable Space Allocation
A resumable statement:
• Enables you to suspend large operations instead of receiving an error
• Gives you a chance to fix the problem while the operation is suspended, rather than starting over
• Is suspended for the following conditions:
– Out of space
– Maximum extents reached
– Space quota exceeded
• A resumable statement can be suspended and resumed multiple times.

管理可恢复空间分配

简要说明:

使您能够挂起大型操作而不是接收错误

使您有机会在操作暂停时修复问题,而不是重新开始

因下列情况暂停:

空间不足

已达到最大范围

超出空间配额

可恢复语句可以挂起并多次恢复。

 

Using Resumable Space Allocation
• Queries, DML operations, and certain DDL operations can be resumed if they encounter an out-of-space error.
• A resumable statement can be issued through SQL,PL/SQL,SQL*Loader, and Data Pump utilities, or the Oracle Call Interface (OCI).
• A statement executes in resumable mode only if its session has been enabled by one of the following actions:
– The RESUMABLE_TIMEOUT initialization parameter is set to a nonzero value.
– An ALTER SESSION ENABLE RESUMABLE statement is issued:
ALTER SESSION ENABLE RESUMABLE;
INSERT INTO sales_new SELECT * FROM sh.sales;
ALTER SESSION DISABLE RESUMABLE;

使用可恢复空间分配

如果查询、DML操作和某些DDL操作遇到空间不足错误,则可以恢复这些操作。

可恢复语句可以通过SQL、PL/SQL、SQL*加载器和数据泵实用程序或Oracle调用接口(OCI)发出。

只有当语句的会话已由下列操作之一启用时,语句才会在可恢复模式下执行:

超时初始化参数设置为非零值。

在旧会话中发出ENABLE SUMMABLE语句:

 

 

SQL> conn / as sysdba
Connected.
SQL> desc dba_resumable;   查询静态数据字典
Name Null? Type
----------------------------------------- -------- ----------------------------
USER_ID NUMBER
SESSION_ID NUMBER
INSTANCE_ID NUMBER
COORD_INSTANCE_ID NUMBER
COORD_SESSION_ID NUMBER
STATUS VARCHAR2(9)
TIMEOUT NUMBER   超时时间
START_TIME VARCHAR2(20)
SUSPEND_TIME VARCHAR2(20)
RESUME_TIME VARCHAR2(20)
NAME VARCHAR2(4000)
SQL_TEXT VARCHAR2(1000)
ERROR_NUMBER NUMBER
ERROR_PARAMETER1 VARCHAR2(80)
ERROR_PARAMETER2 VARCHAR2(80)
ERROR_PARAMETER3 VARCHAR2(80)
ERROR_PARAMETER4 VARCHAR2(80)
ERROR_PARAMETER5 VARCHAR2(80)
ERROR_MSG VARCHAR2(4000)

 

SQL> alter session enable resumable; 打开断点运行

Session altered.

SQL> select timeout from dba_resumable;

TIMEOUT
----------
7200

在默认情况下,发生错误后,Oracle会将当前操作挂起2个小时7200秒

SQL> alter session disable resumable; 关闭该功能

Session altered.

大型数据库空间不够的情况

 

 

 

What Operations Are Resumable?
The following operations are resumable:
• Queries: SELECT statements that run out of temporary space (for sort areas)
• DML: INSERT, UPDATE, and DELETE statements
• The following DDL statements:
– CREATE TABLE ... AS SELECT
– CREATE INDEX
– ALTER INDEX ... REBUILD
– ALTER TABLE ... MOVE PARTITION
– ALTER TABLE ... SPLIT PARTITION
– ALTER INDEX ... REBUILD PARTITION
– ALTER INDEX ... SPLIT PARTITION
– CREATE MATERIALIZED VIEW

哪些操作是可恢复的?

以下操作可求和:

查询:选择耗尽临时空间的语句(用于黑色区域)

DML:INSERT、UPDATE和DELETE语句

以下DDL语句:

创建表。选择

-创建索引

替代指数重建

旧桌子。搬家党

旧桌子。分裂党

替代指数重建参与

替代指数分裂党

创建视图材质

 

Quiz
Select the true statements about space management:
a. Segment creation in Oracle Database 12c is deferred for all tables. There are no exceptions.
b. All UNUSABLE indexes and index partitions are created without a segment.
c. Shrinking segment space is a nonresumable operation.
d. You can set thresholds by tablespace.

测验。

选择有关空间管理的正确语句:

a、 Oracle数据库12c中的段创建对于所有表都是延迟的。没有例外。 错误:断点延迟创建功能只对普通表起作用

b、 所有不可用的索引和索引分区都是在没有段的情况下创建的。  对的

c、 收缩段空间是不可消耗的操作。错误:断的收缩功能,可从失败的时间继续运行

d、 可以按表空间设置阈值。对的

 

Summary
In this lesson, you should have learned how to:
• Describe how the Oracle Database server automatically manages space
• Save space by using compression
• Proactively monitor and manage tablespace space usage
• Describe segment creation in the Oracle database
• Control deferred segment creation
• Use the Segment Advisor
• Reclaim wasted space from tables and indexes by using the segment shrink functionality
• Manage resumable space allocation

摘要

在本课中,您应该学习如何:

描述Oracle数据库服务器如何自动管理空间

使用压缩节省空间

主动监视和管理表空间使用情况

描述Oracle数据库中的创建段

控制延迟段创建

使用Segment Advisor

使用段收缩功能从表和索引中回收浪费的空间

管理可恢复空间分配

以上是关于oracle 03-06 高级空间管理的主要内容,如果未能解决你的问题,请参考以下文章

Oracle表空间管理

Oracle 表空间的日常维护与管理

oracle asm管理下怎样增加表空间容量

Oracle-表空间管理

oracle 数据库管理--管理表空间和数据文件

oracle 数据库管理--管理表空间和数据文件