« February 2008 |
Digest首页
| April 2008 »
March 21, 2008
Optimizer Operations
How the Optimizer Performs Operations
How the CBO Evaluates IN-List Iterators
当 IN clause 指定了特定的值,并且在该列上有索引,优化器选择 IN-list iterator。如果有多个 OR clauses 使用相同的索引,那么优化器选择更高效的 IN-list iterator,而不使用 CONCATENATION or UNION ALL。
How the CBO Evaluates Concatenation
当不同的条件使用 OR clause 连接起来,并且不同的条件都可以通过不同的索引生成较好的执行计划,那么 Concatenation 是很有用的。
HINT:
USE_CONCAT
NO_EXPAND 会禁止使用 Concatenation,他其实是阻止 QUERY 扩展为多个 QUERY
当一下情况时不要使用 Concatenation:
1.OR conditions 在同一个列上,可以使用 IN-list,后者更高效。
2.每一个 concatenation 都重复昂贵的步骤。
How the CBO Evaluates Remote Operations
影响执行计划的因素:
1.Network round trips 比物理和逻辑 I/Os 昂贵几个数量级
2.如果远程数据库不是 Oracle 数据库,优化器无法获得远程数据库的任何 statistics
一般来说,优化器在访问本地表之前先访问远程表
How the CBO Executes Distributed Statements
1.如果 SQL 语句中的所有表来自同一个远程数据库,Oracle 把语句发送给远程数据库,远程数据库执行完之后把结果发还给本地数据库。
2.如果表来自不同的数据库,Oracle 把语句拆分,每一个部分访问单个数据库上的表,把他们分别发送给各数据库,各数据库执行自己部分的语句,并把结果发还给本地数据库,本地数据库再执行语句的其余处理部分。
如果是 CBO,优化器会考虑远程数据库上的索引,就像本地数据库一样,还会考虑远程的 statistics,此外,在估计访问的 cost 时,还会考虑数据的位置,比如远程的一个全表扫描比本地相同表的全表扫描估计的 cost 要高。
对于 RBO,优化器不会考虑远程数据库上的索引。
How the CBO Executes Sort Operations
SORT UNIQUE
如果使用了 DISTINCT clause 或者 unique values 在下一步中需要,就会发生 SORT UNIQUE
SORT AGGREGATE
SORT AGGREGATE 实际上不发生 sort,他使用于对整个 set of rows 进行聚合计算。
SORT GROUP BY
SORT GROUP BY 用于对不同组上的数据进行聚合计算,这种情况下 sort 是需要的,sort 用于将行拆分成不同的组。
SORT JOIN
在 SORT MERGE JOIN 中,如果数据需要根据 join key 排序,就会发生 SORT JOIN。
SORT ORDER BY
当语句中使用 ORDER BY,并且没有任何索引适合这种排序方式,那么 SORT ORDER BY 就需要。
How the CBO Executes Views
以下情况 CBO 产生 VIEW:
1.语句中有没有被 decomposed 的 View
2.语句中有 temporary or inline view 被使用
How the CBO Evaluates Constants
常量的计算只在语句被优化时执行一次,而不是每次语句被执行的时候。
比如:salary > 24000/12 会被优化器简化为 salary > 2000
优化器不会跨过比较符简化表达式,salary*12 > 24000 不能被简化为 salary > 2000,因此写语句时应尽量用常量和列作比较,而不要将列作计算之后再去比较。
How the CBO Evaluates the UNION and UNION ALL Operators
对于将 OR clauses 组合为一个复合语句,或者将一个复杂语句分解为包含简单 select 语句的复合语句很有用,他们更易于优化和理解。
就和 concatenation 一样,如果 UNION ALL 重复了昂贵的操作,就不应该使用。
How the CBO Evaluates the LIKE Operator
对于没有通配符的 like 条件,优化器会将他简化为等于操作
last_name LIKE 'SMITH' -->> last_name = 'SMITH'
但这种简化只能用于变长的类型,对于固定长度的,比如 CHAR(10) 就不能简化,因为等于操作遵循 blank-padded semantics,而 like 不是(此规则只适合 9i 以上)。
CREATE TABLE ducks (f CHAR(6), v VARCHAR2(6));
INSERT INTO ducks VALUES ('DUCK', 'DUCK');
commit;
select * from ducks where f='DUCK'; <<---'DUCK' 自动填充空格至 6 位长度
F V
------------ ------
DUCK DUCK
select * from ducks where f like 'DUCK'; <<---不填充空格
no rows selected
以上结果在 9i 上有效,8i 下两者都返回行
How the CBO Evaluates the IN Operator
优化器将 IN comparison operator 条件扩展为等价的 equality comparison operators and OR logical operators 条件
How the CBO Evaluates the ANY or SOME Operator
1.列表
优化器将其扩展为等价的 comparison operators and OR logical operators 条件
salary > ANY (:first_sal, :second_sal) -> salary > :first_sal OR salary > :second_sal
2.子查询
优化器将其转化为等价的 EXISTS operator and a correlated subquery 条件
x > ANY (SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
变为
EXISTS (SELECT salary
FROM employees
WHERE job_id = 'IT_PROG'
AND x > salary)
How the CBO Evaluates the ALL Operator
1.列表
优化器将其扩展为等价的 comparison operators and AND logical operators 条件
2.子查询
优化器将其转化为等价的 ANY comparison operator and a complementary comparison operator 条件
x > ALL (SELECT salary
FROM employees
WHERE department_id = 50)
变为
NOT (x <= ANY (SELECT salary
FROM employees
WHERE department_id = 50) )
然后再进一步根据 ANY Operator 的转换规则再将其转换:
NOT EXISTS (SELECT salary
FROM employees
WHERE department_id = 50
AND x <= salary)
How the CBO Evaluates the BETWEEN Operator
优化器总是将 BETWEEN 条件用 >= and <= 条件来代替
How the CBO Evaluates the NOT Operator
优化器使用除去 NOT logical operator 并使用相反的 comparison operator 代替原来 comparison operator 的方法来简化条件,使 NOT logical operator 消除。
优化器会将 NOT 传递到子条件中,以便尽可能的简化条件,即使子条件中会产生更多的 NOTs:
NOT (salary < 1000 OR commission_pct IS NULL)
=>
NOT salary < 1000 AND commission_pct IS NOT NULL
=>
salary >= 1000 AND commission_pct IS NOT NULL
How the CBO Evaluates Transitivity
如果两个条件涉及到同一个 column,且这个 column 的其中一个条件是和 constant expressions 进行比较,那么有时候优化器会推断出一个条件,这个推断的条件可以使用 index access path,而原始的条件却不能使用:
WHERE column1 comp_oper constant
AND column1 = column2
其中:
comp_oper 为任何比较操作:=, !=, ^=, <, <>, >, <=, or >=
constant 为任何常量表达式(不能为其他 column):SQL functions, literals, bind variables, and correlation variables
这时,优化器会推断一个条件:
column2 comp_oper constant
如果 column2 上有索引,就能使用该索引
注:Transitivity 只用于 CBO
How the CBO Optimizes Common Subexpressions
公共的子表达式优化是一种启发式的优化,可以鉴别、移出、收集在各 disjunctive (OR) branches 中的公共子表达式,绝大数情况下,可以减少 join 的数量。
在满足一下情况时,可使用公共子表达式优化(从最顶层至最内层的顺序):
1.顶层条件是一个 disjunction(几个以 or 连接的条件)
2.每个 or 分支中是 simple predicate 或者 a conjunction(几个以 and 连接的条件)
3.每个 and 分支中是 simple predicate 或者 a disjunction of simple predicates
4.表达式在每个 or 分支中都出现,即公共子表达式
simple predicate 只不含有 AND or OR 连接的条件
满足以上条件的公共子表达式,优化器会将其移到最顶层,去除重复,再和被移去公共子表达式的原 disjunction 做 conjunction,这样可以减少 join 操作。
How the CBO Evaluates DETERMINISTIC Functions
某些情况,优化器不需要计算 user-written function 的值,而用以前计算的值来代替他。
这种 function 必须有一定的限制:
1.Function 的返回值不能随着 package variables、database、session parameters 的不同而改变
2.如果 function 被重定义了,那么他的返回值和以前的要保持一致
3.使用预计算结果代替执行 function 必须没有重大副作用
使用 DETERMINISTIC 关键字创建的 function 告诉 Oracle 该 function 满足以上限制,Oracle 不会去检查该 function,即使 function 很明显不满足以上限制,因此,程序员应负责检查以上限制,只有满足了才能加 DETERMINISTIC 关键字。
How the Optimizer Transforms SQL Statements
How the CBO Transforms ORs into Compound Queries
如果一个查询包含多个用 OR 连接的条件,优化器会将其转换为用 UNION ALL 连接的混合查询,如果转换后的语句执行更加高效
1.如果每个条件都可以单独使用 index access path,那么可以转换。优化器将转换后的语句生成执行计划,他们用不同的索引多次访问表,并把结果放到一起
2.如果任何一个条件使用 full table scan,那么不会转换,因为一个 full table scan 和几个 index scan 结合的效率不如直接使用一个 full table scan 效率高
3.对于 CBO,优化器会估计并比较转换前后的语句所需的 COST,并决定是否转换
4.CBO 不会转换 IN-lists 或者条在在同一列上的 OR 操作,而使用 INLIST iterator operator
How the CBO Unnests Subqueries
优化复杂语句,优化器选择下面两种方法的其中一种:
1.如果复杂语句可以转换为等同的 join 语句,那么先转换,再优化 join 语句,这样可以利用 join 语句的优势
2.如果无法转换,那么优化复杂语句本身
子查询包含 aggregate functions,比如 AVG 的复杂语句,无法转换为 join 语句
How the CBO Merges Views
merge view 的方法:
在语句中将 view 的名字用 view 基表的名字代替,将 view 中的条件加到语句的条件中去
Mergeable and Nonmergeable Views
merge 只适合 select-project-join views,即 view 中只包含 selections, projections, and joins
如果 view 中包含以下元素,不能 merge:
1.Set operators (UNION, UNION ALL, INTERSECT, MINUS)
2.A CONNECT BY clause
3.A ROWNUM pseudocolumn
4.Aggregate functions (AVG, COUNT, MAX, MIN, SUM) in the select list
当 view 中包含以下元素时,只有 Complex View Merging is enabled 的时候才能 merge:
1.A GROUP BY clause
2.A DISTINCT operator in the select list
如果 view 中包含多个基表,那么当该 view 在 outer join 语句的右边时,无法 merge,如果只有一个基表,那么可以使用 complex view merging,即使 an expression in the view can return a nonnull value for a NULL.
如果一个查询语句包含 CURSOR expression,那么即使 view 可以被正常 merge 优化器也不会将它 merge
Complex View Merging
如果 complex view merging is enabled 的,那么包含 GROUP BY clause or DISTINCT 的 view 可以被 merge
Complex merging 还可以用于 merge an IN subquery,只要 subquery 是不相关的
Complex merging 不是 cost-based 的,必须用 OPTIMIZER_FEATURES_ENABLE or the MERGE hint 开启才能使用,如果没有 hint or parameter setting,优化器会使用另外一种方法:pushing predicates
How the CBO Pushes Predicates
优化器可以将访问 nonmergeable view 的 query block 通过 pushing the query block's predicates inside the view's query 来转换
How the CBO Applies an Aggregate Function to the View
优化器可以转换包含 aggregate function 的 query,通过将 aggregate function 应用到 view's query
How the CBO Executes Views in Outer Joins
如果 view 在一个 outer join 的右边:
1.如果 view 只有一个基表,优化器使用 view merging
2.如果 view 有多个基表,优化器可以 push the join predicate into the view
How the CBO Accesses the View's Rows with the Original Statement
如果优化器无法将访问 view 的语句转换为等价的访问基表的语句,比如 view 中包含 ROWNUM pseudocolumn,view 不能被 merge,也不能 push predicate,那么 Oracle 执行 view 中的语句,获得结果集,original statement 将其当作一个表来处理。
How the CBO Executes Compound Queries
为了为混合查询选择执行计划,优化器首先为混合查询的每个部分选择执行计划,然后用 set operator 联合各 resulting row sources
转引自: http://www.heysky.net/archives/2006/08/optimizer_operations_notes.html
Posted by eygle at 11:34 PM
| Comments (0)
Introduction to the Optimizer
Overview of SQL Processing
1. parser 进行语意和语法分析
2. Optimizer 利用RBO,CBO等方法决定产生查询结果的最有效路径
3. Row Source Generator 从2中接受优化后的方案,并产生SQL的Execution Plan
4. SQL Execution Engine运行该执行计划,并产生查询结果
Features that Require the CBO
1. Partitioned tables and indexes
2. Index-organized tables
3. Reverse key indexes
4. Function-based indexes
5. SAMPLE clauses in a SELECT statement
6. Parallel query and parallel DML
7. Star transformations and star joins
8. Extensible optimizer
9. Query rewrite with materialized views
10. Enterprise Manager progress meter
11. Hash joins
12. Bitmap indexes and bitmap join indexes
13. Index skip scans
即使OPTIMIZER_MODE=rule,这些features仍然会使用CBO
Components of the CBO
Query Transformer
数据来自于parse后的SQL,是一系列的query block。其目标是测定SQL的形式是否有利于产生好的query plan。有以下4种:
1. View Merging
SQL 中的view 被扩展到单独的query block中。Optimizer会单独分析view query block,这样通常会导致在整体优化上得不到最优的结果。因此query transformer会将大部分view和其他的query block 合并,这样可以在整体上统一优化。
2. Predicate Pushing
针对没有被merge的view, push the relevant predicates from the containing query block into the view query block, which can be used either to access indexes or to act as filters
3. Subquery Unnesting
子查询是nested在主查询中的,这样很难得到好的优化结果。所以将他们unnested,变成join
4. Query Rewrite with Materialized Views
如果查询与某个物化视图符合的化,则会按照物化视图重写这个查询,因为物化视图的结果都是事先计算好的。
Estimator
产生 3 种度量标准:
1. Selectivity
表示有多少 rows 可以通过谓词被选择出来,大小介于 0.0~1.0,0 表示没有 row 被选择出来。
如果没有 statistics,estimator 会使用一个默认的 selectivity 值,这个值根据谓词的不同而异。比如 '=' 的 selectivity 小于 '<'。
如果有 statistics,比如对于 last_name = 'Smith',estimator 使用 last_name 列的 distinct 值的倒数(注:是指表中所有 last_name 的 distinct 值),作为 selectivity。
如果 last_name 列上有 histogram,则使用 histogram 根据 last_name 值的分布情况产生的 selectivity 作为 selectivity。Histogram 在当列有数据倾斜时可以大大帮助 CBO 产生好的 selectivity。
2. Cardinality
表示一个 row set 的行数。
Base cardinality:base table 的行数。如果表分析过了,则直接使用分析的统计信息。如果没有,则使用表 extents 的数量来估计。
Effective cardinality:有效行集,指从基表中选择出来的行数。是 Base cardinality 和表上所有谓词的组合 Selectivity 的乘积。如果表上没有谓词,那么 Effective cardinality = Base cardinality。
Join cardinality:两表 join 后产生的行数。是两表 cardinality 的乘积(Cartesian)乘以 Join 谓词的 selectivity。
Distinct cardinality:列上 distinct 值的行数。
Group cardinality:GROUP BY 操作之后 row set 的行数。由 grouping columns 的 distinct cardinality 和整个 row set 的行数决定。
group cardinality lies between max ( dist. card. colx , dist. card. coly )
and min ( (dist. card. colx * dist. card. coly) ,
num rows in row set )
3. Cost
Cost 表现了 Disk I/O, CPU usage, Memory usage 资源单位的使用数量(units of work or resource used)。
Access path 决定从 base table 获得数据所需的 units of work 的数量。也就是说Access path 决定 Cost 的值。Access path 可以是 table scan, fast full index scan, index scan。
Clustering Factor:
Index 的一种属性,表示被索引的行在数据块中的分布情况,表征表中数据的存储顺序和某索引字段顺序的符合程度。直接影响使用 rowid 找到 row 的cost。大小介于 block 数和 rownum 之间。
(以下来自biti_rainy http://blog.itpub.net/post/330/2970 )
Oracle 按照索引块中存储的 rowid 来识别相临的索引中记录在表 block 中是否为相同块,如果索引中存在记录 rowid a,b,c,d......,若b 和 a 是同一个block,则比较 c 和 b,若这时不是同一个block,则 clustering_factor + 1 ,然后比较 d 和 c,若还不是同一个 block,则clustering_factor + 1......
若 clustering_factor 接近表 block 数量,则说明表中数据具有比较好的跟索引字段一样排序顺序的存储,通过索引进行 range scan 的代价比较小(需要读取的表块可能比较少),若 clustering_factor 接近 row 数量,则说明表中数据和索引字段排序顺序差异很大,杂乱无张。则通过索引进行 range scan 的代价比较大(需要读取的表块可能更多)。
当然,在 oracle 920 开始,对于cluster_factor 比较接近表块数量的根据索引的大范围查询做了特别的处理,不再是读一个索引记录去搜索一个表记录了,而是成批处理(通过索引块一批 rowid 一次去表块中获得一批记录),这样就大大节约了读的成本(consistent gets)。
Join Cost:
表征了做 join 的两个 row sets 分别 cost 的组合。
Nested loop join:
outer row set 的每行遍历 inner row set 的所有行,寻找匹配的行。
cost = outer access cost + (inner access cost * outer cardinality)
Sort merge join:
做 join 的两个 row sets 根据 join keys 进行排序,如果他们不是按照 join keys 的顺序的话。
cost = outer access cost + inner access cost + sort costs (outer and inner, if sort is used)
Hash join:
cost = (outer access cost * # of hash partitions) + inner access cost
首先理解 hash table 的数据结构:
可以把 hash table 看做一个 2 维数组 a[200][100],现有 1000 个无序数字用来被查询。我们考虑把这 1000 个数字除以 200,根据其余数放在 a[200][100] 中,余数就是数组的第一维下标。这样平均一个 a[i] 只放5个数字。当查询的时候,对数字除以 200(这就是一个简单的 hash 算法),根据余数 i 去 a[i] 中查找,大约遍历 5 次就能找到。
Inner row(小表)被 hash 在内存中,并且通过 join key 建立 hash table(作为第一个下标),然后 scan outer table,到 hash table 中查找 joined rows(通过 hash 算法)。
hash table 会按照 multiblock_IO 决定分成几个 partitions。如果 hash table 太大超出了 hash_area_size,则将超出部分的 partitions 放到 temporary segments 中。
可以通过 10104 events 查看 hash join 的 statistics:
ALTER SESSION SET EVENTS '10104 trace name context forever, level 10'; 比如:
Total number of partitions:
Number of partitions which could fit in memory:
如果后者大于前者,则说明一些 partitions 因为超出了 hash_area_size,要被放置到临时表空间中。
Plan Generator
作用是尝试各种可能的执行计划,选择 cost 最低的一种。
Plan Generator 会先为 nested subqueries and nonmerged views 产生 subplans,并且从 innermost query block 开始往外优化。
Plan Generator 会使用 internal cutoff 来减少 plan 的尝试数量。internal cutoff 基于现有的最优计划的 cost。如果很大,那么会尝试较多的计划;如果很小,那么会很快结束尝试。
如果 plan generator 从一个接近最优的 initial join order 开始,那么 internal cutoff 可以很好的工作。Plan Generator 根据 join items 的 effective cardinality 来确定 initial join order,小的在前面,大的在后面。
Understanding Execution Plans
Execution Plan:
为了执行 SQL 语句,Oracle 会执行很多步骤,这些步骤的综合叫做 execution plan,包括 access path 和 join order。
Understanding Access Paths for the CBO
Access paths:
从数据库获得数据的方式。
Full Table Scans
表中所有在 HWM 以下的 blocks 都被扫描一遍,确定符合 where 条件的行。
块的读取范围从 1 到 DB_FILE_MULTIBLOCK_READ_COUNT。Multiblock reads 可以提高执行效率,当访问表中大量块时 full table scans 比 index range scans 效率高。
优化器选择 Full Table Scans 的情况:
Lack of Index
Large Amount of Data
Small Table --大小表的区分由 _small_table_threshold 隐含参数决定,默认为 db_cache_size 的 2%。 http://www.eygle.com/archives/2006/05/oracle_long_short_table.html
High Degree of Parallelism
Full Table Scan Hints:/*+ FULL(table alias) */
Rowid Scans
获得一行数据的最快方法。
一般要先通过 index scan 获得 Rowid,如果需要的列不在 index 中,再进行 Rowid Scans 获得相应的行,如果在 index 中,则不需要 Rowid Scans。
Index Scans
Index Unique Scans
最多返回一个 rowid,用于 Unique Index 且 index cols 在条件中使用"等于"。
Index Range Scans
返回的数据按照 index columns 升序排列,index column 为同一个值的多行按照行 rowid 的升序排列。如果 order by/group by 的顺序和 Index Range Scans 返回的 row set 的顺序相同就不需要再 sort 了,否则还需要再对 row set 进行 sort。
Unique index 中的 < > 条件,以及 nonunique indexe 的 < = > 条件,都会引起 Index Range Scans。如果进行 wild-card searches,% 不能放最前面,否则不会进行 Index Range Scans。
如果某列上有索引,该列有 skewed distribution,且具有 histograms,但当时用 bind variable 时,Oracle 不知道该变量具体是什么值,而无法使用 histograms,导致选择 full table scan,这种情况下可以通过使用 hints 进行调整。
Index Range Scans Descending
和 Index Range Scans 相同,只是用于降序返回结果,或者返回小于某特定值的结果。
HINT:INDEX_DESC(table_alias index_name)
Index Skip Scans
用于前导列没有出现在查询中(skiped)时使用索引。它将 composite index 拆分成若干个小的逻辑子索引。子索引的个数由前导列的 distinct 值决定。适用于前导列 distinct 值很少(子索引就少了),非前导列 distinct 值很多的情况。
Full Scans
适用于:
1.A predicate references one of the columns in the index. The predicate does not need to be an index driver.
2.No predicate,并且:
A.查询中引用的列都在 index 中
B.只少有一个索引列不为空。
它是先定位到索引的 root block,然后到 branch block(如果有的话),再定位到第一个 leaf block,然后根据 leaf block 的双向链表顺序读取。它所读取的块都是有顺序的,也是经过排序的。
Fast Full Index Scans
和 Full Scans 适用于:查询的所有列都在索引中出现,且至少有一个索引列具有 NOT NULL 约束。区别在于 它是从段头开始,读取包含位图块,root block,所有的branch block,leaf block,读取的顺序完全有物理存储位置决定,并采取多块读,没次读取db_file_multiblock_read_count个块。(更详细的说明参见汪海的《Index Full Scan vs Index Fast Full Scan 》 http://www.dbanotes.net/Oracle/Index_full_scan_vs_index_fast_full_scan.htm)
Fast Full Index Scans 可以利用多块读和并行读,只能用于 CBO,不能在 bitmap indexes 上使用。
当需要排序时,Oracle 会使用 Full Index Scans,因为他的结果已经排好序;当不排序时,会使用 Fast Full Index Scans,因为能使用多块读,速度更快。
在 rebuild index 时使用的就是 Fast Full Index Scans,所以 rebuild index 需要排序。(参见汪海的 《Rebuild Index与 Sort》http://www.dbanotes.net/Oracle/Rebuild_Index_vs_Sort.htm)
HINT:INDEX_FFS(table_alias index_name)
Fast Full Index Scan 限制:
索引列中至少有一列有 NOT NULL 约束
如果要用并行 fast full index scan 必须在创建索引时单独指定 parallel clause,不能从索引所在的表上继承
必须分析索引,否则优化器可能不会使用它
Index Joins
他是一个有若干个 indexes 组成的 hash join,包含查询中需要的所有列。
他无法 eliminate a sort operation,必须在 CBO 中使用。
HINT:INDEX_JOIN
Bitmap Joins
A bitmap join uses a bitmap for key values and a mapping function that converts each bit position to a rowid. Bitmaps can efficiently merge indexes that correspond to several conditions in a WHERE clause, using Boolean operations to resolve AND and OR conditions.
只能使用于 CBO,且需要企业版。
Cluster Scans
用于从存放于 indexed cluster 中的表中获得相同 cluster key 值的数据。具有相同 cluster key 值的所有数据存放于同一个 BLOCK。通过扫描 cluster index 获得相应的 rowid,再通过 rowid 定位到所需的行。
Hash Scans
用于从存放于 hash cluster 中的表中获得相同 hash value 值的数据。具有相同 hash value 值的所有数据存放于同一个 BLOCK。通过将 hash function 应用于 cluster key 值上,获得 hash value,再通过 hash value 定位到所需的行上。
Sample Table Scans
从表中获得 a random sample of data。
SAMPLE clause:从表中随机获得指定百分比的行数据。
SAMPLE BLOCK clause:从表中随机获得指定百分比的块数据。
限制:
查询不能包含 a join or a remote table
需要使用 CBO
How the CBO Chooses an Access Path
1.语句所有可用的 access paths
2.使用每种 access paths 或者 combination of paths 时,估计的 cost 值
影响 CBO 的因素:
1.Optimizer Hints
hints 会覆盖可用的 access paths,除非包含 SAMPLE or SAMPLE BLOCK
2.Old Statistics
影响 cost 的估计
Understanding Joins
How the CBO Executes Join Statements
决定一下几个参数:
Access Paths
Join Method(nested loop, sort merge, cartesian, and hash joins)
Join Order
How the CBO Chooses the Join Method
估计每个 join method 的 cost,选择 cost 最少的那种 join method。
如果 join 返回大量行(一般来说,大于 10000 行),考虑以下因素:
1.nested loop join 是低效的,优化器不会使用它
nested loop join cost= access cost of A + (access cost of B * number of rows from A)
2.CBO 中,hash join 是最高效的
hash join cost= (access cost of A * number of hash partitions of B) + access cost of B
3.RBO 中,merge join 是最高效的
merge join cost= access cost of A + access cost of B +(sort cost of A + sort cost of B)
(如果数据是预先排序好的,sort cost 为 0)
How the CBO Chooses Execution Plans for Join Types
CBO,RBO 都适用的:
1.优化器通过 UNIQUE and PRIMARY KEY 约束找到最多返回一行的表,如果这样的表存在,就把它放在连接顺序的第一位,再处理连接中的其他表。
2.For join statements with outer join conditions, the table with the outer join operator must come after the other table in the condition in the join order. The optimizer does not consider join orders that violate this rule.
CBO:
估计各种 join orders, join methods, and available access paths 的 cost,选择 cost 最低的
其他因素:
1.较小的 sort area size 会增加 sort merge join 的 cost,因为需要更多的 CPU time and I/O
2.较大的多块读相对于 nested loop join 来说,会减少 sort merge join 的 cost。
CBO 中 join orders 的选择会被 ORDERED hint 覆盖,但如果 HINT 和 outer join 的规则冲突,那么 HINT 会被忽略。
Nested Loop Joins
当 small subsets of data 被连接,并且 join condition 对于 inner table 来说是一种高效的访问方式时,nested loop joins 是非常有用的。
必须保证 inner table is driven from (dependent on) the outer table,否则性能很差,这种情况适用 hash joins 更好。
HINT:USE_NL(table1_alias table2_alias)
Hash Joins
Hash joins 适用于连接 large data sets。优化器选择较小的 data source 通过 join key 建立一个 hash table 存放在内存中。通过扫描大表,查询 hash table 找到所需的数据。
当 hash table 太大无法放到内存中,他会被拆分,一部分放到 temporary segments 中,这时 temporary extent sizes 影响 I/O 性能。这种情况下,性能很差。
当连接使用 equijoin,并且以下任何一种情况下,会使用 hash join:
1. A large amount of data needs to be joined.
2. A large fraction of the table needs to be joined.
Execution Expain 中在上面的是先被扫描的小表,用作建立 hash table,在下的是大表。
HINT:USE_HASH(table1_alias table2_alias)
当使用 Hash Joins 时碰到问题时,应该注意 HASH_AREA_SIZE and HASH_JOIN_ENABLED 参数。
Sort Merge Joins
Sort Merge Join 没有驱动表的概念,他的执行步骤:
1.Sort join operation: 两个表分别按照 join key 排序 (如果已经按照 join key 排序,这步省略)
2.Merge join operation: 将排好序的结果 merge together.
性能比较:
Sort Merge Join 适用于两个 independent sources。一般来说 Hash join 比 Sort Merge Join 性能好,除非以下两个条件同时满足
1.row sources 已经被排序
2.排序操作不需要再进行
如果 Sort Merge Join 选择了 slower access method,比如全表扫描,他的优势就失去了。
当两个表通过 <, <=, >, or >= 连接时,Sort merge join 是很有用的,在进行两个大 data sets 连接时,他比 nested loop join 性能好,hash join 适合用 = 连接。
当两个大数据量的 data sets 连接时,优化器何时选择 sort merge join 而不选择 hash join:
1.连接条件不是 equi-join,而是 <, <=, >, or >= (but not a nonequality)
2.OPTIMIZER_MODE is set to RULE,hash join 需要 CBO
3.HASH_JOIN_ENABLED is false.
4.连接的表已经排好序
5.评估 HASH_AREA_SIZE and SORT_AREA_SIZE 大小之后,优化器认为 hash join 的 cost 较高
HINT:USE_MERGE(table1_alias table2_alias) 可能还需要指定相应的 access path
Cartesian Joins
当两个表连接时,没有指定连接条件,就会导致 Cartesian Join,一般是由于 poor SQL 造成的。
HINT:ORDERED,By specifying a table before its join table is specified, the optimizer does a Cartesian join.
Outer Joins
返回一个表满足连接条件的所有行以及另一个表的全部或者部分行,不管这些行符不符合连接条件。
Nested Loop Outer Joins
返回 outer (preserved) table 的所有行,即使 inner (optional) table 没有符合条件的行。
Nested Loop Outer Join 时,外部表永远是驱动表,不根据 cost 来决定哪个是驱动表。
在以下条件下,优化器选择 Nested Loop Outer Join
1.外部表驱动内部表是可能的
2.数据量小到使得 nested loop 效率较高
Hash Join Outer Joins
当连接的表的数据量大到使用 hash join 效率更高,或者外部表无法驱动内部表时,优化器选择 Hash Join Outer Joins。
表的连接顺序也不按照 cost 来决定,外部表先进行处理,用它构建 hash table。
Sort Merge Outer Joins
当外表不能驱动内表,无法使用 hash join or nested loop joins 时,那么使用 Sort Merge Outer Joins。
由于数据量或者表已经经过排序操作,使得 Sort Merge Outer Joins 效率更高时,优化器选择 Sort Merge Outer Joins。
Full Outer Joins
Left and right outer joins 的联合。
Setting Cost-Based Optimizer Parameters
Enabling CBO Features
OPTIMIZER_FEATURES_ENABLE
后面跟版本号,设置 Oracle 允许哪些 CBO 相关的特征被使用,只允许被设置了的版本的 CBO 特征,其他的不允许,在升级版本之后,为了执行计划的稳定性和向后兼容可以使用,否则不需要设置。
Peeking of User-Defined Bind Variables
在第一次 invocation of a cursor 的时候,Oracle peeks at 用户定义绑定变量的值,来决定所有 where 条件的 selectivity,即使没有使用绑定变量。在这之后的 invocations of the cursor 就不用再 peek 了,cursor 被共享,即使绑定变量的值不同。
使用绑定变量假设 cursor sharing 是故意的,并且假设不同的 invocations 使用相同的执行计划,如果没有使用相同的执行计划,那么绑定变量的使用可能不正确。
Controlling the Behavior of the CBO
CURSOR_SHARING
将语句中的 literal values 转为绑定变量,提高 cursor sharing 并且影响语句的执行计划,生成的执行计划将基于绑定变量而不是 actual literal values。
DB_FILE_MULTIBLOCK_READ_COUNT
Full table scan or index fast full scan 时,一次 I/O 读取的块数。用于估计 full table scans and index fast full scans 的 cost。大的 DB_FILE_MULTIBLOCK_READ_COUNT 值使得 full table scans 的 cost 较低,从而选择 full table scans 而不是 index scan。
HASH_AREA_SIZE
用于 hash joins 的内存大小(bytes),越大 hash join 的 cost 越低。
HASH_JOIN_ENABLED
是否使用 hash joins
OPTIMIZER_INDEX_CACHING
控制 an index probe in conjunction with a nested loop 的 cost。范围 0~100,表明索引块在 buffer cache 中的百分比。他影响优化器对 index caching for nested loops and IN-list iterators 的假设。100 表示 100% 的索引块在 buffer cache 中能找到,这将影响优化器对 an index probe or nested loop cost 的调整。
OPTIMIZER_INDEX_COST_ADJ
用于调整 index probe 的 cost。范围 0~10000,默认值 100,表示 indexe 是基于 normal costing model 的 access path;如果设为 10,表示 index 的 cost 是一般 index access path 的 cost 的 1/10。
OPTIMIZER_MAX_PERMUTATIONS
用于控制 CBO 对带有连接的 SQL 语句产生的执行计划数。范围 4 to 80000,80000 相当于无限。当将他设置成小于 1000 可以保证 parse times 降到几秒甚者更少。这个参数可以用来减少多表连接语句的 parse times,但是可能会丢失最优的执行计划。
OPTIMIZER_MODE
设置优化器的模式:RULE, CHOOSE, ALL_ROWS, FIRST_ROWS_n, and FIRST_ROWS
PARTITION_VIEW_ENABLED
是否使用 partition view pruning。如果设置成 true,CBO 只扫描需要的 partitions,根据 view predicates or filters。
QUERY_REWRITE_ENABLED
是否使用 query rewrite 的特性。Query rewrite 是和 materialized views 一起工作的。如果设置为 true,Oracle 会考虑使用 query rewrite 来查询 materialized views 而不是原始的大表(参见 D.C.B.A 对 query rewrite 的解释 http://www.anysql.net/2005/12/queryrewrite01.html)。另外该参数还用来控制是否使用 function-based indexes。
SORT_AREA_SIZE
执行 sort 所使用的内存大小(bytes)。如果 sort 的数据超过该值,那么超过的部分会放到 temporary tablespace 中。CBO 用该值估量 sort 的 cost,包括 sort merge joins。
STAR_TRANSFORMATION_ENABLED
This parameter, if set to true, enables the CBO to cost a star transformation for star queries. The star transformation combines the bitmap indexes on the various fact table columns rather than using a Cartesian approach.(D.C.B.A 对该功能的测试:http://www.anysql.net/2006/03/dw_star_transform.html)
Overview of the Extensible Optimizer
The extensible optimizer is part of the CBO. It allows the authors of user-defined functions and domain indexes to control the three main components that the CBO uses to select an execution plan: statistics, selectivity, and cost evaluation.
转引自:http://www.heysky.net/archives/2006/08/9iperformancetuningguide.html
Posted by eygle at 11:30 PM
| Comments (0)
asynchronous I/O
Independent I/O, in which there is no timing requirement for transmission, and other processes can be started before the transmission has finished.
Autotrace
Generates a report on the execution path used by the SQL optimizer and the statement execution statistics. The report is useful to monitor and tune the performance of DML statements.
bind variable
A variable in a SQL statement that must be replaced with a valid value, or the address of a value, in order for the statement to successfully execute.
block
A unit of data transfer between main memory and disk. Many blocks from one section of memory address space form a segment.
bottleneck
The delay in transmission of data, typically when a system's bandwidth cannot support the amount of information being relayed at the speed it is being processed. There are, however, many factors that can create a bottleneck in a system.
buffer
A main memory address in which the buffer manager caches currently and recently used data read from disk. Over time, a buffer can hold different blocks. When a new block is needed, the buffer manager can discard an old block and replace it with a new one.
buffer pool
A collection of buffers.
cache
Also known as buffer cache. All buffers and buffer pools.
cache recovery
The part of instance recovery where Oracle applies all committed and uncommitted changes in the redo log files to the affected data blocks. Also known as the rolling forward phase of instance recovery.
Cartesian product
A join with no join condition results in a Cartesian product, or a cross product. A Cartesian product is the set of all possible combinations of rows drawn one from each table. In other words, for a join of two tables, each row in one table is matched in turn with every row in the other. A Cartesian product for more than two tables is the result of pairing each row of one table with every row of the Cartesian product of the remaining tables. All other kinds of joins are subsets of Cartesian products effectively created by deriving the Cartesian product and then excluding rows that fail the join condition.
CBO
Cost-based optimizer. Generates a set of potential execution plans for SQL statements, estimates the cost of each plan, calls the plan generator to generate the plan, compares the costs, and chooses the plan with the lowest cost. This approach is used when the data dictionary has statistics for at least one of the tables accessed by the SQL statements. The CBO is made up of the query transformer, the estimator, and the plan generator.
compound query
A query that uses set operators (UNION, UNION ALL, INTERSECT, or MINUS) to combine two or more simple or complex statements. Each simple or complex statement in a compound query is called a component query.
contention
When some process has to wait for a resource that is being used by another process.
dictionary cache
A collection of database tables and views containing reference information about the database, its structures, and its users. Oracle accesses the data dictionary frequently during the parsing of SQL statements. Two special locations in memory are designated to hold dictionary data. One area is called the data dictionary cache, also known as the row cache because it holds data as rows instead of buffers (which hold entire blocks of data). The other area is the library cache. All Oracle user processes share these two caches for access to data dictionary information.
distributed statement
A statement that accesses data on two or more distinct nodes/instances of a distributed database. A remote statement accesses data on one remote node of a distributed database.
dynamic performance views
The views database administrators create on dynamic performance tables (virtual tables that record current database activity). Dynamic performance views are called fixed views because they cannot be altered or removed by the database administrator.
enqueue
This is another term for a lock.
equijoin
A join condition containing an equality operator.
estimator
Uses statistics to estimate the selectivity, cardinality, and cost of execution plans. The main goal of the estimator is to estimate the overall cost of an execution plan.
EXPLAIN PLAN
A SQL statement that enables examination of the execution plan chosen by the optimizer for DML statements. EXPLAIN PLAN causes the optimizer to choose an execution plan and then to put data describing the plan into a database table.
instance recovery
The automatic application of redo log records to Oracle uncommitted data blocks after a crash or system failure.
join
A query that selects data from more than one table. A join is characterized by multiple tables in the FROM clause. Oracle pairs the rows from these tables using the condition specified in the WHERE clause and returns the resulting rows. This condition is called the join condition and usually compares columns of all the joined tables.
latch
A simple, low-level serialization mechanism to protect shared data structures in the System Global Area.
library cache
A memory structure containing shared SQL and PL/SQL areas. The library cache is one of three parts of the shared pool.
LIO
Logical I/O. A block read which may or may not be satisfied from the buffer cache.
literal
A constant value, written at compile-time and read-only at run-time. Literals can be accessed quickly, and are used when modification is not necessary.
MTBF
Mean time between failures. A common database statistic important to tuning I/O.
mirroring
Maintaining identical copies of data on one or more disks. Typically, mirroring is performed on duplicate hard disks at the operating system level, so that if one of the disks becomes unavailable, the other disk can continue to service requests without interruptions.
nonequijoin
A join condition containing something other than an equality operator.
optimizer
Determines the most efficient way to execute SQL statements by evaluating expressions and translating them into equivalent, quicker expressions. The optimizer formulates a set of execution plans and picks the best one for a SQL statement. See CBO.
Oracle Trace
Used by the Oracle Server to collect performance and resource utilization data, such as SQL parse, execute, fetch statistics, and wait statistics. Oracle Trace provides several SQL scripts that can be used to access server event tables, collects server event data and stores it in memory, and allows data to be formatted while a collection is occurring.
outer join
A join condition using the outer join operator (+) with one or more columns of one of the tables. Oracle returns all rows that meet the join condition. Oracle also returns all rows from the table without the outer join operator for which there are no matching rows in the table with the outer join operator.
paging
A technique for increasing the memory space available by moving infrequently-used parts of a program's working memory from main memory to a secondary storage medium, usually a disk. The unit of transfer is called a page.
parse
A hard parse occurs when a SQL statement is executed, and the SQL statement is either not in the shared pool, or it is in the shared pool but it cannot be shared. A SQL statement is not shared if the metadata for the two SQL statements is different. This can happen if a SQL statement is textually identical as a preexisting SQL statement, but the tables referred to in the two statements resolve to physically different tables, or if the optimizer environment is different.
A soft parse occurs when a session attempts to execute a SQL statement, and the statement is already in the shared pool, and it can be used (that is, shared). For a statement to be shared, all data, (including metadata, such as the optimizer execution plan) pertaining to the existing SQL statement must be equally applicable to the current statement being issued.
parse call
A call to Oracle to prepare a SQL statement for execution. This includes syntactically checking the SQL statement, optimizing it, and building (or locating) an executable form of that statement.
parser
Performs syntax analysis and semantic analysis of SQL statements, and expands views (referenced in a query) into separate query blocks.
PGA
Program Global Area. A nonshared memory region that contains data and control information for a server process, created when the server process is started.
PIO
Physical I/O. A block read which could not be satisfied from the buffer cache, either because the block was not present or because the I/O is a direct I/O (and bypasses the buffer cache).
plan generator
Tries out different possible plans for a given query so that the CBO can choose the plan with the lowest cost. It explores different plans for a query block by trying out different access paths, join methods, and join orders.
predicate
A WHERE condition in SQL.
query transformer
Decides whether to rewrite a user query to generate a better query plan, merges views, and performs subquery unnesting.
RAID
Redundant arrays of inexpensive disks. RAID configurations provide improved data reliability with the option of striping (manually distributing data). Different RAID configurations (levels) are chosen based on performance and cost, and are suited to different types of applications, depending on their I/O characteristics.
RBO
Rule-based optimizer. Chooses an execution plan for SQL statements based on the access paths available and the ranks of these access paths (if there is more than one way, then the RBO uses the operation with the lowest rank). The RBO is used if no statistics are available, otherwise the CBO is used.
row source generator
Receives the optimal plan from the optimizer and outputs the execution plan for the SQL statement. A row source is an iterative control structure that processes a set of rows in an iterated manner and produces a row set.
segment
A set of extents allocated for a specific type of database object such as a table, index, or cluster.
simple statement
An INSERT, UPDATE, DELETE, or SELECT statement that involves only a single table.
simple query
A SELECT statement that references only one table and does not make reference to GROUP BY functions.
SGA
System Global Area. A memory region within main memory used to store data for fast access. Oracle uses the shared pool to allocate SGA memory for shared SQL and PL/SQL procedures.
SQL Compiler
Compiles SQL statements into a shared cursor. The SQL Compiler is made up of the parser, the optimizer, and the row source generator.
SQL statements (identical)
Textually identical SQL statements do not differ in any way.
SQL statements (similar)
Similar SQL statements differ only due to changing literal values. If the literal values were replaced with bind variables, then the SQL statements would be textually identical.
SQL Trace
A basic performance diagnostic tool to help monitor and tune applications running against the Oracle server. SQL Trace lets you assess the efficiency of the SQL statements an application runs and generates statistics for each statement. The trace files produced by this tool are used as input for TKPROF.
SQL*Loader
Reads and interprets input files. It is the most efficient way to load large amounts of data.
Statspack
A set of SQL, PL/SQL, and SQL*Plus scripts that allow the collection, automation, storage, and viewing of performance data. Statspack supersedes the traditional UTLBSTAT/UTLESTAT tuning scripts.
striping
The interleaving of a related block of data across disks. Proper striping reduces I/O and improves performance.
- Stripe depth is the size of the stripe, sometimes called stripe unit.
- Stripe width is the product of the stripe depth and the number of drives in the striped set.
TKPROF
A diagnostic tool to help monitor and tune applications running against the Oracle Server. TKPROF primarily processes SQL trace output files and translates them into readable output files, providing a summary of user-level statements and recursive SQL calls for the trace files. It can also assess the efficiency of SQL statements, generate execution plans, and create SQL scripts to store statistics in the database.
transaction recovery
The part of instance recovery where Oracle applies the rollback segments to undo the uncommitted changes. Also known as the rolling back phase of instance recovery.
UGA
User Global Area. A memory region in the large pool used for user sessions.
wait events
Statistics that are incremented by a server process/thread to indicate that it had to wait for an event to complete before being able to continue processing. Wait events are one of the first places for investigation when performing reactive performance tuning.
wait events (idle)
These events indicate that the server process is waiting because it has no work. These events should be ignored when tuning, because they do not indicate the nature of the performance bottleneck.
work area
A private allocation of memory used for sorts, hash joins, and other operations that are memory-intensive. A sort operator uses a work area (the sort area) to perform the in-memory sort of a set of rows. Similarly, a hash-join operator uses a work area (the hash area) to build a hash table from its left input.
Posted by eygle at 11:14 PM
| Comments (1)
March 10, 2008
引言
正如您所知道的,AIX® 具有无数的命令,使您能够执行大量的任务。取决于您需要完成的任务,您可能会仅仅使用到这些命令的某个子集。这些子集随不同的用户和不同的需要而异。然而,有一些您通常要使用的核心命令。您需要这些命令来回答您自己的问题,或者为支持人员的询问提供答案。
在本文中,我将讨论这其中的一些核心命令。其目的旨在为您提供一个可用作便捷参考的列表。虽然这些命令的行为在所有 AIX 版本中都应该相同,但是仅在 AIX 5.3 下对它们进行了测试。
注意:
以下段落中讨论的 bootinfo 不是用户级别的命令,并且在 AIX 4.2 或更高版本中不受支持。
命令
内核
如何知道自己在运行 32 位内核还是 64 位内核?
要显示内核启用的是 32 位还是 64 位,可输入以下命令:
如何知道自己在运行单处理器还是多处理器内核?
/unix 是指向已启动内核的符号链接。要了解正在运行什么内核模式,可输入 ls -l /unix 并查看 /unix 链接到什么文件。下面是 ls -l /unix 命令的三种可能输出及其对应的内核:
/unix -> /usr/lib/boot/unix_up # 32 bit uniprocessor kernel
/unix -> /usr/lib/boot/unix_mp # 32 bit multiprocessor kernel
/unix -> /usr/lib/boot/unix_64 # 64 bit multiprocessor kernel
|
注意:
AIX 5L Version 5.3 不支持单处理器内核。
如何从一种内核模式更改为另一种内核模式?
在安装过程期间,会缺省启用一种适合该 AIX 版本和操作中的硬件的内核。让我们使用前一个问题中的方法并假设启用了 32 位内核。我们还假设您希望在 64 位内核模式下启动。这可以通过按顺序执行以下命令来实现:
ln -sf /usr/lib/boot/unix_64 /unix
ln -sf /usr/lib/boot/unix_64 /usr/lib/boot/unix
bosboot -ad /dev/hdiskxx
shutdown -r
|
/dev/hdiskxx 目录是启动逻辑卷 /dev/hd5 所在的位置。要弄清 hdiskxx 中有哪些 xx,可运行以下命令:
注意:
在 AIX 5.2 中,缺省安装的是 32 位内核。在 AIX 5.3 中,缺省情况下会在 64 位硬件上安装 64 位内核,在 32 位硬件上安装 32 位内核。
硬件
如何知道我的计算机是否能够运行 AIX 5L Version 5.3?
AIX 5L Version 5.3 可在当前受支持的所有基于共用硬件参考平台(Common Hardware Reference Platform,CHRP)的 POWER 硬件上运行。
如何知道我的计算机是否基于 CHRP?
运行 prtconf 命令。如果是 CHRP 计算机,则字符串 chrp 会出现在 Model Architecture 行上。
如何知道我的 System p 计算机(硬件)是 32 位还是 64 位?
要显示硬件 32 位还是 64 位,可输入以下命令:
我的计算机有多少实际内存?
要显示以 KB 为单位的实际内存,可输入以下命令之一:
lsattr -El sys0 -a realmem |
我的计算机是否可以运行 64 位内核?
需要 64 位硬件才能运行 64 位内核。
我系统中的设备属性值是什么?
要列出磁带设备 rmt0 的当前属性值,可输入以下命令:
要列出磁带设备 rmt0 的缺省属性值,可输入以下命令:
要列出 TTY 设备 tty0 的可能登录属性值,可输入以下命令:
lsattr -l tty0 -a login -R |
要显示系统级别的属性,可输入以下命令:
我的系统有多少个处理器?
要显示您系统上的处理器数量,可输入以下命令:
我的系统上有多少个硬盘,当前正在使用哪些硬盘?
要显示系统上的硬盘数量,可输入以下命令:
如何列出有关特定物理卷的信息?
举例来说,若要了解有关 hdisk1 的详细信息,可运行如下命令:
如何获得系统的详细配置?
输入以下命令:
下列选项可以提供特定的信息:
-p |
显示特定于平台的设备信息。该标志适用于 AIX 4.2.1 或更高版本。 |
-v |
显示在自定义 VPD 对象类中找到的重要产品数据库(Vital Product Database,VPD)。 |
例如,要显示有关磁带驱动器 rmt0 的详细信息,可输入以下命令:
通过运行 prtconf 命令也可以获得非常类似的信息。
如何确定芯片类型、系统名称、节点名称、型号,等等?
uname 命令可以提供关于系统的详细信息。
uname -p |
显示系统的芯片类型。例如,PowerPC。 |
uname -r |
显示操作系统的版本号。 |
uname -s |
显示系统名称。例如,AIX。 |
uname -n |
显示节点名称。 |
uname -a |
显示系统名称、节点名称、版本、计算机 ID。 |
uname -M |
显示系统型号名称。例如,IBM, 9114-275。 |
uname -v |
显示操作系统版本。 |
uname -m |
显示运行系统的硬件的计算机 ID 编号。 |
uname -u |
显示系统 ID 编号。 |
AIX
我的系统上在运行什么 AIX 主要版本、次要版本和维护级?
输入以下命令之一:
如何确定某个特定的 AIX 级别缺少哪些文件集更新?
举例来说,若要确定 5300-04 缺少哪些文件集更新,可运行以下命令:
我的系统上安装了什么 SP (Service Pack)?
要了解系统上当前安装了哪个 SP,可运行 oslevel -s 命令。对于安装了 TL4 和 SP2 的 AIX 5L Version 5.3 系统,示例输出如下:
我的系统上是否安装了 CSP (Concluding Service Pack)?
要确定系统上当前是否安装了某个 CSP,可运行 oslevel -s 命令。对于安装了 TL3 和 CSP 的 AIX 5L Version 5.3 系统,示例输出如下:
如何创建文件系统?
以下命令将在卷组 testvg 中创建一个大小为 10MB、安装点为 /fs1 的 jfs 文件系统:
crfs -v jfs -g testvg -a size=10M -m /fs1
|
以下命令将在卷组 testvg 中创建一个大小为 10MB、安装点为 /fs2 并具有只读权限的 jfs2 文件系统:
crfs -v jfs2 -g testvg -a size=10M -p ro -m /fs2
|
如何更改文件系统的大小?
若要将 /usr 文件系统的大小增加 1000000 个 512 字节的块,可输入以下命令:
chfs -a size=+1000000 /usr |
注意:
在 AIX 5.3 中,JFS2 文件系统的大小还可以收缩。
如何安装 CD?
输入以下命令:
mount -V cdrfs -o ro /dev/cd0 /cdrom |
如何安装文件系统?
以下命令将在 /test 目录中安装文件系统 /dev/fslv02:
如何安装所有缺省文件系统(/etc/filesystems 文件中标记有 mount=true 属性的所有标准文件系统)?
以下命令将安装所有此类文件系统:
如何卸载文件系统?
输入以下命令可以卸载 /test 文件系统:
如何显示已安装的文件系统?
输入以下命令可以显示有关所有当前已安装的文件系统的信息:
如何删除文件系统?
输入以下命令可以删除 /test 文件系统:
如何对文件系统进行碎片整理?
可以使用 defragfs 命令来改善或报告文件系统中的连续空间状态。例如,若要对文件系统 /home 进行碎片整理,可以使用以下命令:
哪个文件集包含某个特定的二进制文件?
若要显示 /usr/bin/vmstat 包含 bos.acct,可输入以下命令:
或者若要显示 bos.perf.tools 包含 /usr/bin/svmon,可输入以下命令:
如何显示有关系统上已安装文件集的信息?
输入以下命令:
如何确定我的系统上是否安装了所有维护级文件集?
输入以下命令:
如何确定我的系统上是否安装了某个修复程序?
若要确定是否安装了 IY24043,可输入以下命令:
如何按 APAR 安装单独的修复程序?
举例来说,若要从 /dev/cd0 安装 APAR IY73748,可输入以下命令:
instfix -k IY73748 -d /dev/cd0
|
如何验证文件集是否有必需的先决条件和是否已完全安装?
要显示需要安装或纠正哪些文件集,可输入以下命令:
如何获得符号表示中的 loader 节头和符号条目的转储?
输入以下命令:
如何确定已分配和使用的分页空间量?
输入以下命令:
如何增加分页空间?
可以使用 chps -s 命令来动态增加分页空间的大小。例如,如果希望将 hd6 的大小增加 3 个逻辑分区,您可以执行以下命令:
如何减少分页空间?
可以使用 chps -d 命令来动态减少分页空间的大小。例如,如果希望将 hd6 的大小减少四个逻辑分区,您可以执行以下命令:
如何知道我的系统是否能够使用同步多线程(Simultaneous Multi-threading,SMT)?
如果您的系统是运行 AIX 5L Version 5.3 的基于 POWER5 的系统,则它就能使用 SMT。
如何知道我的系统是否启用了 SMT?
如果不带任何选项运行 smtctl 命令,它将告诉您是否启用了 SMT。
32 位内核是否支持 SMT?
是的,32 位和 64 位内核都支持 SMT。
如何启用或禁用 SMT?
可以通过运行 smtctl 命令来启用或禁用 SMT。下面是该命令的语法:
smtctl [ -m off | on [ -w boot | now]] |
可以使用以下选项:
-m off |
将 SMT 模式设置为禁用。 |
-m on |
将 SMT 模式设置为启用。 |
-w boot |
如果在下一次系统重新启动前运行 bosboot 命令,则此选项使 SMT 模式更改在下一次和后续重新启动时生效。 |
-w now |
使 SMT 模式更改立即生效,但不会延续到下一次重新启动以后。 |
如果既没有指定 -w boot 也没有指定 -w now 选项,则模式更改立即生效。如果在下一次系统重新启动前运行 bosboot 命令,所做的更改将延续到后续重新启动以后。
如何获得特定于分区的信息和统计信息?
lparstat 命令可以提供分区信息和利用率统计信息报告。此命令还可以显示 Hypervisor 信息。
卷组和逻辑卷
如何知道我的卷组是常规、大容量还是可扩展的?
对该卷组运行 lsvg 命令并查看 MAX PVs 的值。该值为 32 表示常规、128 表示大容量、1024 表示可扩展的卷组。
如何创建卷组?
可以使用以下命令,其中 s partition_size 设置每个物理分区中的兆字节 (MB) 数,并且 partition_size 是以 MB 为单位、从 1 到 1024 的值(对于 AIX 5.3 是从 1 到 131072)。partition_size 变量必须等于 2 的幂(例如:1、2、4、8)。标准和大容量卷组的缺省值是保持在"每个物理卷最多只能有 1016 个物理分区"限制内的最低值。可扩展卷组的缺省值为每个物理卷容纳 2040 个物理分区的最低值。
mkvg -y name_of_volume_group -s
partition_size
list_of_hard_disks
|
如何更改卷组的特征?
可以使用以下命令来更改卷组的特征:
如何创建逻辑卷?
输入以下命令:
mklv -y name_of_logical_volume
name_of_volume_group
number_of_partition
|
如何增加逻辑卷的大小?
举例来说,若要将 lv05 目录所表示的逻辑卷增加三个逻辑分区,可输入以下命令:
如何显示属于某个卷组(例如,rootvg)的所有逻辑卷?
可以通过输入以下命令来显示属于 rootvg 的所有逻辑卷:
如何列出有关逻辑卷的信息?
可运行以下命令来显示有关逻辑卷 lv1 的信息:
如何删除逻辑卷?
可以运行以下命令来删除逻辑卷 lv7:
rmlv 命令仅删除逻辑卷,但不删除其他实体,例如使用该逻辑卷的文件系统或分页空间。
如何镜像逻辑卷?
- mklvcopy LogicalVolumeName Numberofcopies
- syncvg VolumeGroupName
如何删除逻辑卷的副本?
可以使用 rmlvcopy 命令来删除逻辑卷的逻辑分区副本。若要减少属于逻辑卷 testlv 的每个逻辑分区的副本数量,可输入以下命令:
现在该逻辑卷中每个逻辑分区最多只有两个物理分区。
有关卷组的问题
要显示系统中的卷组,可输入以下命令:
要显示 rootvg 的所有特征,可输入以下命令:
要显示 rootvg 所使用的磁盘,可输入以下命令:
如何将磁盘添加到卷组?
输入以下命令:
extendvg VolumeGroupName hdisk0 hdisk1 ... hdiskn
|
如何确定我的硬盘所支持的最大逻辑磁道组 (LTG) 大小?
可以带 -M 标志使用 lquerypv 命令。此命令的输出给出以 KB 为单位的 LTG 大小。例如,在下面的示例中,hdisk0 的 LTG 大小为 256 KB。
/usr/sbin/lquerypv -M hdisk0
256
|
还可以在硬盘上运行 lspv 并查看 MAX REQUEST 的值。
syncvg 命令是做什么用的?
syncvg 命令用于同步过时的物理分区。它接受逻辑卷、物理卷或卷组名称作为参数。
例如,若要同步位于物理卷 hdisk6 和 hdisk7 上的物理分区,可以使用以下命令:
若要同步卷组 testvg 中的所有物理分区,可以使用以下命令:
如何替换某个磁盘?
extendvg VolumeGroupName hdisk_new
migratepv hdisk_bad hdisk_new
reducevg -d VolumeGroupName hdisk_bad
如何克隆 rootvg(创建其副本)?
您可以运行 alt_disk_copy 命令来将当前 rootvg 复制到某个替代磁盘。下面的示例演示了如何将 rootvg 克隆到 hdisk1。
网络
如何显示或设置网络参数值?
no 命令设置或显示网络优化参数的当前或下一次启动时的值。
如何获得我计算机的 IP 地址?
输入以下命令之一:
ifconfig -a
host Fully_Qualified_Host_Name
|
例如,输入主机 cyclop.austin.ibm.com。
如何确定服务器上的网络接口?
以下两个命令中的任何一个都将显示网络接口:
若要获得有关某个特定网络接口(例如,tr0)的信息,可以运行以下命令:
如何激活网络接口?
若要激活网络接口 tr0,可以运行以下命令:
如何禁用网络接口?
举例来说,若要禁用网络接口 tr0,可以运行以下命令:


|
olor="#5c81a7">回页首 | |
结束语
不可否认,像这样的列表对于快速回答您自己的某些问题是非常有帮助的。然而,它并没有涵盖您可能需要的一切。您可以添加一些回答这里未讨论的其他问题的命令,从而使得此类列表更加有用。
参考资料
学习
获得产品和技术
- IBM 试用软件:使用 IBM 软件开发您的下一个项目,可直接从 developerWorks 下载这些试用软件。
讨论
关于作者
 |
|
|
 |
Shiv Dutta 是 IBM Systems and Technology Group 的一名技术顾问,他帮助独立软件供应商在 IBM System p 服务器上启用他们的应用程序。Shiv 有作为软件开发人员、系统管理员和讲师的丰富经验。他在 AIX 的系统管理、问题确定、性能调优和规模指导方面提供支持。Shiv 在 AIX 诞生之时就从事这方面的工作。您可以通过 sdutta@us.ibm.com 与 Shiv 联系。 |
Posted by eygle at 1:39 PM
| Comments (0)
用法说明:这个 nmon 工具并未受到正式支持。没有提供或隐含任何保证,并且您无法从 IBM 获取相关的帮助。
nmon 工具运行于:
- AIX® 4.1.5、4.2.0、4.3.2 和 4.3.3(nmon Version 9a:该版本的功能已经确定,并且不会对其进行进一步的开发。)
- AIX 5.1、5.2 和 5.3(nmon Version 10:该版本现在支持 AIX 5.3 和基于 POWER5™ 处理器的计算机,并且提供了 SMT 和共享 CPU 微分区的支持。)
- pSeries® p5 和 OpenPower™ 上的 Linux™ SUSE SLES 9、Red Hat EL 3 和 4、Debian
- Linux SUSE、Red Hat 和许多最新的 x86(32 位模式的 Intel 和 AMD)上的发布版
- zSeries® 或 mainframe 上的 Linux SUSE 和 Red Hat
nmon 工具大约每六个月更新一次,或者在可用的新的操作系统发布版中对其进行更新。要将您的名字放入到请求更新的电子邮件列表中,请与 Nigel Griffiths 联系。
这个工具可以与 nmon 分析程序一同使用,后者将加载 nmon 的输出文件并自动地创建大量的图形。
引言
nmon 工具可以为 AIX 和 Linux 性能专家提供监视和分析性能数据的功能,其中包括:
- CPU 使用率
- 内存使用情况
- 内核统计信息和运行队列信息
- 磁盘 I/O 速度、传输和读/写比率
- 文件系统中的可用空间
- 磁盘适配器
- 网络 I/O 速度、传输和读/写比率
- 页面空间和页面速度
- CPU 和 AIX 规范
- 消耗资源最多的进程
- IBM HTTP Web 缓存
- 用户自定义的磁盘组
- 计算机详细信息和资源
- 异步 I/O,仅适用于 AIX
- 工作负载管理器 (WLM),仅适用于 AIX
- IBM TotalStorage® Enterprise Storage Server® (ESS) 磁盘,仅适用于 AIX
- 网络文件系统 (NFS)
- 动态 LPAR (DLPAR) 更改,仅适用于面向 AIX 或 Linux 的 pSeries p5 和 OpenPower
还包括一个用来从 nmon 的输出生成图形并创建可以在 Web 站点显示的 .gif 文件的新工具。
有关详细信息,请参阅自述文件。
该工具的作用
nmon 工具可以帮助在一个屏幕上显示所有重要的性能优化信息,并动态地对其进行更新。这个高效的工具可以工作于任何哑屏幕、telnet 会话、甚至拨号线路。另外,它并不会消耗大量的 CPU 周期,通常低于百分之二。在更新的计算机上,其 CPU 使用率将低于百分之一。
使用哑屏幕,在屏幕上对数据进行显示,并且每隔两秒钟对其进行更新。然而,您可以很容易地将这个时间间隔更改为更长或更短的时间段。如果您拉伸窗口,并在 X Windows、VNC、PuTTY 或类似的窗口中显示这些数据,nmon 工具可以同时输出大量的信息。
nmon 工具还可以将相同的数据捕获到一个文本文件,便于以后对报告进行分析和绘制图形。输出文件采用电子表格的格式 (.csv)。
安装该工具
该工具是一个独立的二进制文件(不同的 AIX 或 Linux 版本中该文件也有所不同),您可以在五秒钟内完成该工具的安装,如果您的输入速度更快的话,也许时间更短。安装过程非常简单:
- 将
nmonXXX.tar.Z 文件复制到计算机。如果使用 FTP,请记住使用二进制模式。
注意:示例中的 XXX 由实际的版本代替。
- 要解压该文件,可以运行
uncompress nmonXX.tar.Z。
- 要提取该文件,可以运行
tar xvf nmonXX.tar。
- 阅读自述文件。
- 要启动
nmon 工具,输入 nmon。
- 如果您是 root 用户,可能需要输入
./nmon。
使用 nmon 9 的附加说明,仅适用于 AIX 4
- 必须是 root 用户,或者通过输入下面的命令允许一般用户读取 /dev/kmem 文件(作为 root 用户):
- 如