求助关于 OPTIMIZER_FEATURES_ENABLE的设定会影响sql执行报错

dercyzzp 2018-04-21 09:10:52
oracle版本 11
OPTIMIZER_FEATURES_ENABLE = 10.2
如下sql
select
to_date(col1,'yyyymmdd')
from (
select
to_char(table1.CUR_MON, 'YYYYMM') || '01' as col1
from
table1
where
table1.CUR_MON is not null
)

table1.CUR_MON 是 date 类型,, 有null值的数据,
现在的问题是在客户环境,执行sql 会报错 ora-01840 ,,

如果在客户环境 把 OPTIMIZER_FEATURES_ENABLE 改成 9.2, 就不会报错了.

想请教各位 为什么会报错,条件里已经去除null的数据了
而且这段sql 我换成测试环境 这个错误是无法再现的...只有在客户环境才会出错.
公司测试环境和客户环境的数据库版本是一样的

如果不修改sql,,, 从oracle优化策略角度,比如做表分析什么的 可不可以解决这个错误,,总是感觉这个错误很奇怪,,不应该发生.

因为客户环境 暂时无法访问,所以不能去试验,,现在客户那边想知道 错误原因和解决办法(不修改sql)


另外说下关于 ora-01840 错误,,,可以执行这段sql select to_date('01','YYYYMMDD') from dual;

...全文
1389 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
minsic78 2018-04-25
  • 打赏
  • 举报
回复
为了一句SQL,让CBO跨两个大版本降级,是作死的行为…… 同意2#的说法:仔细查查数据是否有问题,另外可以尝试修改SQL绕过这个问题
dercyzzp 2018-04-24
  • 打赏
  • 举报
回复
引用 2 楼 jdsnhan 的回复:
OPTIMIZER_FEATURES_ENABLE 会影响查询优化器的执行,但抛出异常,没遇到过。 我建议从数据层再分析一次,看是否有异常的数据
谢谢你的回复, 数据层面没有问题,,date类型的数据除了合法日期值,就是null了,所以数据是没问题的. 这里应该是涉及到 优化器和优化模式的选择,, 在oracle9i版本里 optimize_mode是CHOOSE,根据表是否有统计信息来决定选择CBO还是RBO优化. 如果没有统计信息,并且optimize_mode是RULE的时候 sql执行就报错了,,我只分析到这里,至于更深的原因我也不知道了. 不知道还有没有人需要这种问题.
jdsnhan 2018-04-23
  • 打赏
  • 举报
回复
OPTIMIZER_FEATURES_ENABLE 会影响查询优化器的执行,但抛出异常,没遇到过。 我建议从数据层再分析一次,看是否有异常的数据
dercyzzp 2018-04-22
  • 打赏
  • 举报
回复
ding i xia
Oracle9i初始化参数中文说明 Blank_trimming: 说明: 如果值为TRUE, 即使源长度比目标长度 (SQL92 兼容) 更长, 也允许分配数据。 值范围: TRUE | FALSE 默认值: FALSE serializable: 说明: 确定查询是否获取表级的读取锁, 以防止在包含该查询的事务处理被提交之前更新任何对象读取。这种操作模式提供可重复的读取, 并确保在同一事务处理种对相同数据的两次查询看到的是相同的值。 值范围: TRUE | FALSE 默认值: FALSE row_locking: 说明: 指定在表已更新或正在更新时是否获取行锁。如果设置为 ALWAYS, 只有在表被更新后才获取行锁。如果设置为 INTENT, 只有行锁将用于SELECT FOR UPDATE, 但在更新时将获取表锁。 值范围: ALWAYS | DEFAULT | INTENT 默认值: ALWAYS shared_servers 说明 : 指定在启动例程后, 要为共享服务器环境创建的服务器进程的数量。 值范围: 根据操作系统而定。 默认值 : 1 circuits: 说明 : 指定可用于入站和出站网络话的虚拟电路总数。 该参数是构成某个例程的总 SGA 要求的若干参数之一。 默认值 : 派生: SESSIONS 参数的值 (如果正在使用共享服务器体系结构); 否则为 0。 Mts_multiple_listeners: 说明: 指定多个监听程序的地址是分别指定的, 还是用一个 ADDRESS_LIST 字符串指定。如果该值为 TRUE, MTS_LISTENER_ADDRESS 参数可被指定为: (ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(PORT=5000)(HOST=zeus)) (ADDRESS=(PROTOCOL=decnet)(OBJECT=outa)(NODE=zeus)) 此参数在 8.1.3 版中已废弃。 值范围: TRUE | FALSE 默认值: FALSE mts_servers: 说明 : 指定在启动例程后, 要为共享服务器环境创建的服务器进程的数量。 值范围: 根据操作系统而定。 默认值 : 1 mts_service: 说明 : 一个共享服务器参数, 用于指定已在调度程序上注册, 用来建立数据库连接的唯一服务名。如果要在没有调度程序的情况下仍能连接到数据库, 请将该值设置为与例程名相同。此参数自 8.1.3 版起已废弃。 值范围: 根据操作系统而定。 默认值 :0 mts_sessions: 说明 : 指定允许的共享服务器体系结构用户话的总数。设置此参数可为专用服务器保留一些用户话。 值范围: 0 到 SESSIONS - 5 默认值 : 派生: MTS_CIRCUITS 和 SESSIONS - 5 两者中的较小值 shared_server_sessions: 说明 : 指定允许的共享服务器体系结构用户话的总数。设置此参数可为专用服务器保留一些用户话。 值范围: 0 到 SESSIONS - 5 默认值 : 派生: MTS_CIRCUITS 和 SESSIONS - 5 两者中的较小值 mts_max_dispatchers 说明 : 指定在一个共享服务器环境中可同时运行的调度程序进程的最大数量。 值范围: 根据操作系统而定。 默认值 : 如果已配置了调度程序, 则默认值为大于 5 的任何数目或配置的调度程序的数目 mts_max_servers: 说明 : 指定在一个共享服务器环境中可同时运行的共享服务器进程的最大数量。 值范围: 根据操作系统而定。 默认值 : 20 dispatchers: 说明 : 为设置使用共享服务器的共享环境而设置调度程序的数量和类型。可以为该参数指定几个选项。有关详细信息, 请参阅“Oracle8i 管理员指南”和“Oracle Net Administrator's Guide”。这是字符串值的一个示例: '(PROTOCOL=TCP)(DISPATCHERS=3)'。 值范围: 参数的有效指定值。 默认值 : NULL max_shared_servers: 说明 : 指定在一个共享服务器环境中可同时运行的共享服务器进程的最大数量。 值范围: 根据操作系统而定。 默认值 : 20 mts_circuits: 说明 : 指定可用于入站和出站网络话的虚拟电路总数。 该参数是构成某个例程的总 SGA 要求的若干参数之一。 默认值 : 派生: SESSIONS 参数的值 (如果正在使用共享服务器体系结构); 否则为 0。 Mts_listener_address: 说明 : 指定共享服务器的监听程序配置。监听程序进程需要一个监听地址, 以便处理系统所用的各个网络协议的连接请求。 除非 MTS_MULTIPLE_LISTENERS=TRUE, 否则每个条目都必须有一个独立的相邻值。此参数自 8.1.3 版起已废弃 语法 : (ADDRESS=(PROTOCOL=tcp)(HOST=myhost)(PORT=7002)) 默认值 : NULL mts_dispatchers: 说明 : 为设置使用共享服务器的共享环境而设置调度程序的数量和类型。可以为该参数指定几个选项。有关详细信息, 请参阅“Oracle8i 管理员指南”和“Oracle Net Administrator's Guide”。这是字符串值的一个示例: '(PROTOCOL=TCP)(DISPATCHERS=3)'。 值范围: 参数的有效指定值。 默认值 : NULL max_dispatchers: 说明 : 指定在一个共享服务器环境中可同时运行的调度程序进程的最大数量。 值范围: 根据操作系统而定。 默认值 : 如果已配置了调度程序, 则默认值为大于 5 的任何数目或配置的调度程序的数目 nls_nchar_conv_excp: 说明: (如果值为 TRUE) 当在隐式转换中丢失数据时返回错误的参数。 值范围: FALSE | TRUE 默认值: TRUE nls_numeric_characters: 说明: 指定将用作组分隔符和小数位的字符。组分隔符就是用来分隔整数位组 (如千, 百万等等) 的字符。小数分隔符用来将一个数字的整数部分与小数部分分隔开。其格式是 。 值范围: 任何单字节字符, '+', '-', '<', '>' 除外。 默认值: 从 NLS_TERRITORY 中获得 nls_sort: 说明: 指定 ORDER BY 查询的比较顺序。对于二进制排序, ORDER BY 查询的比较顺序是以数值为基础的。对于语言排序, 则需要进行全表扫描, 以便将数据按照所定义的语言排序进行整理。 值范围: BINARY 或有效的语言定义名。 默认值: 从 NLS_LANGUAGE 中获得 nls_territory: 说明: 为以下各项指定命名约定, 包括日期和星期的编号, 默认日期格式, 默认小数点字符和组分隔符, 以及默认的 ISO 和本地货币符号。可支持的区域包括美国, 法国和日本。有关所有区域的信息, 请参阅 Oracle8i National Language Support Guide。 值范围: 任何有效的地区名。 默认值: 根据操作系统而定 nls_timestamp_format: 说明: 与 NLS_TIME_FORMAT 相似, 只不过它设置的是 TIMESTAMP 数据类型的默认值, 该数据类型既存储YEAR, MONTH 和 DAY 这几个日期值, 也存储 HOUR, MINUTE 和 SECOND 这几个时间值。 语法: TIMESTAMP '1997-01-31 09:26:50.10' (将值存储为 11 个字节)。 默认值: 从 NLS_TERRITORY 中获得 nls_time_format: 说明: 指定一个字符串值, 设置 TIME 数据类型的默认值, 该数据类型包含 HOUR, MINUTE 和 SECOND 这几个日期时间字段。 语法: TIME '09:26:50' (将值存储为 7 个字节)。 默认值: 从 NLS_TERRITORY 中获得 nls_time_tz_format: 说明: 指定一对值 (UTC,TZD), 设置 TIME WITH TIME ZONE 数据类型的默认值, 该数据类型包含 HOUR, MINUTE, SECOND, TIMEZONE_HOUR 和 TIMEZONE_MINUTE 这几个日期时间字段。UTC 是世界时而 TZD 是当地时区。 语法: TIME '09:26:50.20+ 02:00' (将值存储为 9 个字节)。 默认值: 从 NLS_TERRITORY 中获得 nls_length_semantics: 说明: 使用字节或码点语义来指定新列的创建, 如 char, varchar2, clob, nchar, nvarchar2, nclob 列。各种字符集对字符都有各自的定义。在客户机和服务器上使用同一字符集时, 应以该字符集所定义的字符来衡量字符串。现有的列将不受影响。 值范围: BYTE 或 CHAR。 默认值: nls_length_semantics 的数据库字符集的字符所使用的度量单位。BYTE。 nls_date_format: 说明: 指定与 TO_CHAR 和 TO_DATE 函数一同使用的默认日期格式。该参数的默认值由 NLS_TERRITORY 确定。该参数的值可以是包含在双引号内的任何有效的日期格式掩码。例如: ''MMM/DD/YYYY''。 值范围: 任何有效的日期格式掩码, 但不得超过一个固定长度。 默认值: 派生 nls_timestamp_tz_format: 说明: 与 NLS_TIME_TZ_FORMAT 相似, 其中的一对值指定 TIMESTAMP 数据类型的默认值, 该类型除存储 YEAR, MONTH 和 DAY 日期值, HOUR, MINUTE 和 SECOND 时间值, 还存储 TIMEZONE_HOUR 和 TIMEZONE_MINUTE。 语法: TIMESTAMP '1997- 01- 31 09:26:50+ 02:00' (将值存储为 13 个字节)。 默认值: 从 NLS_TERRITORY 中获得 nls_language: 说明: 指定数据库的默认语言, 该语言将用于消息, 日期和月份名, AD, BC, AM 和 PM 的符号, 以及默认的排序机制。可支持的语言包括英语, 法语和日语等等。 值范围: 任何有效的语言名。 默认值: 根据操作系统而定 nls_comp: 说明: 在 SQL 语句中, 应避免使用繁琐的 NLS_SORT 进程。正常情况下, WHERE 子句中进行的比较是二进制的, 但语言比较则需要 NLSSORT 函数。可以使用 NLS_COMP 指定必须根据NLS_SORT 话参数进行语言比较。 值范围: Oracle8i National Language Support Guide 中指定的任何有效的10 字节字符串。 默认值: BINARY nls_currency: 说明: 为 L 数字格式元素指定用作本地货币符号的字符串。该参数的默认值由 NLS_TERRITORY 确定。 值范围: Oracle8i National Language Support Guide 中指定的任何有效的10 字节字符串。 默认值: 从 NLS_TERRITORY 中获得 nls_date_language: 说明: 指定拼写日期名, 月名和日期缩写词 (AM, PM, AD, BC) 的语言。该参数的默认值是由 NLS_LANGUAGE指定的语言。 值范围: 任何有效的 NLS_LANGUAGE 值。 默认值: NLS_LANGUAGE 的值 nls_dual_currency: 说明: 用于覆盖 NLS_TERRITORY 中定义的默认双重货币符号。如果不设置该参数, 就使用默认的双重货币符号; 否则就启动一个值为双重货币符号的新话。 值范围: 任何有效的格式名。。 默认值: 双重货币符号 nls_iso_currency: 说明: 为 C 数字格式元素指定用作国际货币符号的字符串。该参数的默认值由 NLS_TERRITORY 确定。 值范围: 任何有效的 NLS_TERRITORY 值。 默认值: 从 NLS_TERRITORY 中获得 nls_calendar: 说明: 指定 Oracle 使用哪种日历系统作为日期格式。例如, 如果 NLS_CALENDAR 设置为 'Japanese Imperial', 那么日期格式为 'E YY-MM-DD'。即: 如果日期是 1997 年 5 月 15 日, 那么 SYSDATE 显示为 'H 09-05-15'。 值范围: Arabic Hijrah, English Hijrah, Gregorian, Japanese Imperial, Persian, ROC Official (Republic of China) 和 Thai Buddha。 默认值: Gregorian plsql_native_c_compiler: 说明: 指定用于将生成的 C 文件编译为目标文件的 C 编译程序的完整路径名。此参数是可选的。随每个平台附带的特有的 make 文件中包含此参数的默认值。如果为此参数指定了一个值, 则该值将覆盖 make 文件中的默认值。 值范围: C 编译程序的完整路径。 默认值: 无 remote_dependencies_mode: 说明: 用于指定数据库为远程 PL/SQL 存储的过程处理被依赖对象的方式。如果设置为 TIMESTAMP, 只有在服务器与本地时间戳相匹配的情况下, 才能执行该过程。如果设置为 SIGNATURE, 在签名安全的情况下即可执行该过程。 值范围: TIMESTAMP | SIGNATURE 默认值: TIMESTAMP utl_file_dir: 说明: 允许数据库管理员指定 PL/SQL 文件 I/O 许可的目录。使用多个 UTL_FILE_DIR 参数即可指定多个目录。请注意所有用户均可读取或写入 UTL_FILE_DIR 参数中指定的所有文件。 值范围: 任何有效的目录路径。 默认值: 无 plsql_v2_compatibility: 说明: 设置 PL/SQL 兼容级。如果设置为 FALSE, 将执行 PL/SQL V3 行为, 而不允许 V2 行为; 否则在运行 PL/SQL V3 时将接受某些 PL/SQL V2 行为。 值范围: TRUE | FALSE 默认值: FALSE plsql_native_make_utility: 说明: 指定 make 实用程序 (如 UNIX 中的 make 或 gmake, 即 GNU make) 的完整路径名。要从生成的 C 源中生成共享对象或 DLL, 需要使用 make 实用程序。 值范围: make 实用程序的完整路径名。 默认值: 无 plsql_native_library_dir: 说明: 由 PL/SQL 编译程序使用。它指定目录名, 其中存储了本机编译程序生成的共享对象。 范围值: 目录名。 默认值: 无 plsql_compiler_flags: 说明: 由 PL/SQL 编译程序使用。它将编译程序标志列表指定为一个用逗号分隔的字符串列表。 值范围: native (PL/SQL 模块将按本机代码来编译。), interpreted (然后 PL/SQL 模块将被编译为 PL/SQL 字节代码格式), debug (PL/SQL 模块将用探测调试符号来编译), non_debug。 默认值: " interpreted, non_debug " plsql_native_linker: 说明: 此参数指定链接程序 (如: UNIX 中的 ld, 或用于将目标文件链接到共享对象或 DLL 的 GNU ld) 的完整路径名。此参数是可选的。随每个平台附带的特有的 make 文件中包含此参数的默认值。如果为此参数指定了一个值, 则该值将覆盖 make 文件中的默认值。 值范围: 链接程序的完整路径名。 默认值: 无 plsql_native_make_file_name: 说明: 指定 make 文件的完整路径名。make 实用程序 (由 PLSQL_NATIVE_MAKE_UTILITY 指定) 使用此 make 文件生成共享对象或 DLL。每个平台附带有端口专用的 make 文件, 该文件包含使用 make 实用程序在该平台上生成 DLL 时要遵循的规则。 值范围: make 文件的完整路径名。 默认值: 无 plsql_v2_compatibility: 说明: 设置 PL/SQL 兼容级。如果设置为 FALSE, 将执行 PL/SQL V3 行为, 而不允许 V2 行为; 否则在运行 PL/SQL V3 时将接受某些 PL/SQL V2 行为。 值范围: TRUE | FALSE 默认值: FALSE remote_dependencies_mode: 说明: 用于指定数据库为远程 PL/SQL 存储的过程处理被依赖对象的方式。如果设置为 TIMESTAMP, 只有在服务器与本地时间戳相匹配的情况下, 才能执行该过程。如果设置为 SIGNATURE, 在签名安全的情况下即可执行该过程。 值范围: TIMESTAMP | SIGNATURE 默认值: TIMESTAMP shared_memory_address: 说明: SHARED_MEMORY_ADDRESS 和 HI_SHARED_MEMORY_ADDRESS 指定运行时 SGA 的起始地址。许多平台在链接时间指定 SGA 起始地址, 在这类平台上这些参数将被忽略。如果两个参数都设置为 0 或 NULL, 那么地址将根据平台而定。 值范围: 任何整数值。 默认值: 0 lock_sga: 说明: 用于将整个 SGA 锁定在物理内存中。在不支持这种功能的平台上, 该值将被忽略。 值范围: TRUE | FALSE 默认值: FALSE hi_shared_memory_address: 说明: 指定系统全局区 (SGA) 的运行时起始地址。在指定 SGA 连接时起始地址的平台上, 该值被忽略。在 64 位平台上, 请使用该值来指定高 32 位和低 32 位。如果不指定该值, 默认值是平台指定的位置。 值范围: 任何整数值。 默认值: 0 pre_page_sga: 说明: 一个根据平台而定的参数, 如果该参数为 TRUE, 将把所有 SGA 页装载到内存中, 以便使该例程迅速达到最佳性能状态。这将增加例程启动和用户登录的时间, 但在内存充足的系统上能减少缺页故障的出现。 值范围: TRUE | FALSE 默认值: FALSE sga_max_size: 说明: 指定例程存活期间所占用的系统全局区的最大大小。 值范围: 0 到各操作系统所允许的最大值。请注意, 由于该参数值的最小值在启动时已经调整完毕, 因而它无关紧要。 默认值: 如果未指定值, sga_max_size 的默认值将与启动时 SGA 的最初大小 (比如说 X) 相同。该大小取决于 SGA 中各种池的大小, 如缓冲区高速缓存, 共享池, 大型池等。如果指定的值小于 X, 则所使用的 sga_max_size 的值将为 X。也就是说, 它是 X 与用户指定的 sga_max_size 值两者之间的较大值。 Fast_start_parallel_rollback: 说明: 执行并行回退时确定进程的最大数量。在多数事务处理的运行时间都较长的系统上, 该值很有用。 值范围: FALSE | LOW | HIGH 默认值: LOW (2 * CPU_COUNT) transaction_auditing: 说明: 确定事务处理层是否生成一个特殊的重做记录, 其中包含用户登录名, 用户名, 话 ID, 部分操作系统信息以及客户机信息。在使用某一重做日志分析工具时, 这些记录可能很有用。 值范围: TRUE | FALSE 默认值: TRUE transactions: 说明: 指定并行事务处理的最大数量。如果将该值设置得较大, 将增加 SGA 的大小, 并可增加例程启动过程中分配的回退段的数量。默认值大于 SESSIONS, 以实现递归事务处理。 值范围: 一个数值。 默认值: 派生 (1.1 * SESSIONS) enqueue_resources: 说明: 入队可使并行进程能够共享资源。例如, Oracle 允许一个进程以共享模式锁定一个表, 以共享更新模式锁定另一个表。 值范围: 10 - 65535 (7.3) 或 10 - 无限制 (8.1)。 默认值: 派生 (该值大于 DML_LOCKS + 20 即已足够) dml_locks: 说明: 所有用户获取的表锁的最大数量。对每个表执行 DML 操作均需要一个 DML 锁。例如, 如果 3 个用户修改 2 个表, 就要求该值为 6。 值范围: 0 或 20 到无限制。 默认值: 4 * TRANSACTIONS (派生) hash_join_enabled: 说明: 如果设置为 TRUE, 优化程序将在计算最有效的联接方法时考虑散列联接。Oracle 建议数据仓库应用程序应使用 TRUE值。 值范围: TRUE | FALSE 默认值: TRUE optimizer_features_enable: 说明: 允许更改 init.ora 参数, 该参数控制着优化程序的行为。受此影响的参数包括 PUSH_JOIN_PREDICATE, FAST_FULL_SCAN_ENABLED, COMPLEX_VIEW_MERGING 和 B_TREE_BITMAP_PLANS。 值范围: 8.0.0; 8.0.3; 8.0.4; 8.1.3。 默认值: 8.0.0 query_rewrite_integrity: 说明: Oracle Server 执行的查询重写的程度。如果设置为 ENFORCED, Oracle 将保证其一致性和完整性。如果设置为 TRUSTED, 将使用明确声明的关系来允许重写。如果设置为 STALE_TOLERATED, 即使实体化视图与基础数据不一致, 也仍可以进行重写。 值范围: ENFORCED, TRUSTED, STALE_TOLERATED 默认值: ENFORCED query_rewrite_enabled 说明: 启用或禁用对实体化视图的查询重写。一个特定实体化视图只在如下条件下启用: 话参数和单独实体化视图均已启用, 并且基于成本的优化已启用。 值范围: TRUE | FALSE 默认值: FALSE partition_view_enabled: 说明: 如果将 PARTITION_VIEW_ENABLED 设置为 TRUE, 该优化程序将剪除 (或跳过) 分区视图中不必要的表访问。该参数还能更改基于成本的优化程序从基础表统计信息计算分区视图统计信息的方式。 值范围: TRUE | FALSE 默认值: FALSE optimizer_max_permutations: 说明: 对带有大量联接的查询进行语法分析时, 优化程序将考虑限制表的交换数。这有助于确保对查询进行语法分析的时间保持在可接受的限制范围内, 但代价是无法找到最佳计划。如果该值小于 1000, 就应该可以确保每次查询的时间仅为几秒钟或更短。 值范围: 4-2^32 (~4.3 G)。 默认值: 80,000 optimizer_index_cost_adj: 说明: 在考虑太多或太少索引访问路径的情况下, 可以用来优化优化程序的性能。该值越低, 优化程序越容易选择一个索引。也就是说, 如果将该值设置为 50%, 索引访问路径的成本就是正常情况下的一半。 值范围: 1 -10000 默认值: 100 (一个索引访问路径的常规成本) star_transformation_enabled: 说明: 确定基于成本的查询转换是否将被应用到星型查询中。如果设置为 TRUE, 优化程序将考虑将基于成本的转换应用于星型查询中; 如果设置为 FALSE, 将不使用任何转换; 如果设置为 TEMP_DISABLE, 将考虑查询转换, 但不使用临时表。 值范围: TRUE | FALSE | TEMP_DISABLE 默认值: FALSE optimizer_mode: 说明: 指定优化程序的行为。如果设置为 RULE, 就使用基于规则的优化程序, 除非查询含有提示。如果设置为 CHOOSE, 就使用基于成本的优化程序, 除非语句中的表不包含统计信息。ALL_ROWS 或 FIRST_ROWS 始终使用基于成本的优化程序。 值范围: RULE | CHOOSE | FIRST_ROWS | ALL_ROWS 默认值: CHOOSE optimizer_index_caching: 说明: 调整基于成本的优化程序的假定值, 即在缓冲区高速缓存中期望用于嵌套循环联接的索引块的百分比。它将影响使用索引的嵌套循环联接的成本。将该参数设置为一个较高的值, 可以使嵌套循环联接相对于优化程序来说成本更低。 值范围: 0 - 100 %。 默认值: 0 job_queue_processes: 说明: 只用于复制环境。它指定每个例程的 SNP 作业队列进程的数量 (SNP0, ... SNP9, SNPA, ... SNPZ)。要自动更新表快照或执行由 DBMS_JOB 创建的请求, 请将该参数设置为 1 或更大的值。 值范围: 0 到 36 默认值: 0 max_transaction_branches: 说明: 控制分布式事务处理中分支的数量。将 MAX_TRANSACTION_BRANCHES 设置为较低的值, 可以根据 MAX_TRANSACTION_BRANCHES * DISTRIBUTED_TRANSACTIONS * 72 字节, 略微减少共享池的空间量。此参数在 8.1.3 版中已废弃。 值范围: 1 - 32 默认值: 8 compatible: 说明: 允许您使用一个新的发行版, 同时保证与先前版本的向后兼容性。 值范围: 默认为当前发行版。 默认值: 由发行版确定 archive_lag_target: 说明: 此参数与基于时间的线程高级功能相关联。 值范围: 0 或 [60, 7200] 中的任意整数。 默认值: 0 为默认值, 此时将禁用基于时间的线程高级功能。否则, 值将代表秒数 aq_tm_processes: 说明: 如果大于零, 就启用对队列消息的时间监视。该时间值可用于指定消息的延迟和失效属性 (用于应用程序的开发)。 值范围: 0 - 10 默认值: 0 tracefile_identifier: spfile: 说明: 指定当前使用的服务器参数文件的名称。 值范围: 静态参数 默认值: SPFILE 参数可在客户端 PFILE 中定义, 以指明要使用的服务器参数文件的名称。服务器使用默认服务器参数文件时, SPFILE 的值要由服务器在内部设置。 Logmnr_max_persistent_sessions: Standby_file_management: Trace_enabled: Ifile: 说明: 用于在当前参数文件中嵌入其他参数文件。您可以在一个参数文件的多个行上多次使用该参数, 但最多只能有三级嵌套。 值范围: 任何有效的参数文件名 (语法是 IFILE = parameter_file_name)。 默认值: NULL remote_listener: global_context_pool_size: 说明: 从 SGA 分配的用于存储和管理全局应用程序环境的内存量。 值范围: 任意整数值。 默认值: 1 M plsql_native_library_subdir_count: fixed_date: 说明: SYSDATE 返回的数据。对于必须始终返回固定日期而非系统日期的测试, 该值很有用。使用双引号或不使用引号。请勿使用单引号。 值范围: YYYY-MM-DD-HH24:MI:SS (或默认的 Oracle 日期格式)。 默认值: NULL db_name: 说明: 一个数据库标识符, 应与 CREATE DATABASE 语句中指定的名称相对应。 值范围: 任何有效名称最多可有 8 个字符。 默认值: 无 (但应指定) cluster_database: cluster_interconnects: cluster_database_instances: sql_version: replication_dependency_tracking: 说明: 跟踪相关性对复制服务器以并行方式传播所作的更改至关重要。如果设置为 FALSE, 数据库上的读/写操作将运行得更快, 但无法为复制服务器产生并行传播的相关性信息。 值范围: TRUE | FALSE 默认值: TRUE (即启用读/写相关性跟踪) remote_os_roles: 说明: 将 REMOTE_OS_ROLES 设置为 TRUE, 允许由远程客户机的操作系统来分配角色。如果设置为 FALSE, 则由远程客户机的数据库来识别和管理角色。 值范围: TRUE | FALSE 默认值: FALSE remote_os_authent: 说明: 将 REMOTE_OS_AUTHENT 设置为 TRUE, 允许使用 OS_AUTHENT_PREFIX 的值来验证远程客户机。 值范围: TRUE | FALSE 默认值: FALSE open_links: 说明: 指定在一次话中同时打开的与远程数据库的连接的最大数量。该值应等于或超过一个引用多个数据库的单个 SQL 语句中引用的数据库的数量, 这样才能打开所有数据库以便执行该语句。 值范围: 0 - 255 (如果为 0, 不允许分布式事务处理)。 默认值: 4 open_links_per_instance: 说明: 指定 XA 应用程序中可移植的打开连接的最大数量。XA 事务处理使用可移植的打开的连接, 以便在提交一个事务处理后能将这些连接高速缓存。如果创建连接的用户就是拥有事务处理的用户, 各事务处理则可共享连接。 值范围: 0 - UB4MAXVAL 默认值: 4 remote_login_passwordfile: 说明: 指定操作系统或一个文件是否检查具有权限的用户的口令。如果设置为 NONE, Oracle 将忽略口令文件。如果设置为 EXCLUSIVE, 将使用数据库的口令文件对每个具有权限的用户进行验证。如果设置为 SHARED, 多个数据库将共享 SYS 和 INTERNAL 口令文件用户。 值范围:NONE | SHARED | EXCLUSIVE 默认值: NONE hs_autoregister: 说明: 启用或禁用“异构服务 (HS)”代理的自动自注册。如果启用, 信息将被上载到数据字典中, 以便在通过同一代理建立后续连接时降低开销。 值范围: TRUE | FALSE 默认值: TRUE global_names: 说明: 指定是否要求数据库链接与所连接的数据库同名。如果该值为 FALSE, 则不执行检查。要使分布式处理中的命名约定一致, 请将该参数设置为 TRUE。 值范围: TRUE | FALSE 默认值: TRUE distributed_transactions: 说明: 一个数据库一次可参与的分布式事务处理的最大数量。如果由于网络故障异常频繁而减少该值, 将造成大量未决事务处理。 值范围: 0 - TRANSACTIONS 参数值。 默认值: 根据操作系统而定 commit_point_strength: 说明: 一个用于确定分布式事务处理中提交点的位置的值。 值范围: 0 -255 默认值: 根据操作系统而定 db_domain: 说明: 指定数据库名的扩展名 (例如:US.ORACLE.COM) 为使一个域中创建的数据库名唯一, 建议指定该值。 值范围: 由句点分隔的任何字符串, 最长可以有 128 个字符。 默认值: WORLD dblink_encrypt_login: 说明: 在连接到其他 Oracle Server 时, 数据库链接是否使用加密口令。 值范围: TRUE | FALSE 默认值: FALSE backup_tape_io_slaves: 说明: 一个恢复管理器参数, 用于确定读取或写入磁带是否要使用服务器进程或一个附加的 I/O 从属。 值范围: TRUE | FALSE 默认值: FALSE tape_asynch_io: 说明: 用于控制对顺序设备的 I/O 操作 (例如, 将 Oracle 数据备份或复原到磁带上, 或从磁带上备份或复原 Oracle 数据) 是否异步。只有在您的平台支持对顺序设备的异步 I/O 操作的情况下, 将该值设置为 TRUE 才有效; 如果异步 I/O 的执行情况不稳定, 请将该值设置为 FALSE。 值范围: TRUE | FALSE 默认值: FALSE log_file_name_convert: 说明: 将主数据库上的一个日志文件的文件名转换为备用数据库上对等的路径和文件名。将一个日志文件添加到一个主数据库后, 必须将一个相应的文件添加到备用数据库中。该参数替代 Oracle7 中的 LOG_FILE_NAME_CONVERT 参数。 值范围: 任何格式为 ''主体日志文件的路径/文件名'' 和 ''备用日志文件的路径/文件名'' 的有效路径/文件名 默认值: NULL fal_server: 说明: 指定此备用数据库的 FAL 服务器。该值是一个 Oracle Net 服务名。此 Oracle Net 服务名被假定为已在备用数据库系统上正确配置, 可指向期望的 FAL 服务器。 值范围: Oracle Net 服务名的字符串值。 Fal_client: 说明: 指定供 FAL 服务 (通过 FAL_SERVER 参数配置) 来引用 FAL 客户机的 FAL 客户机名称。该参数的值是一个 Oracle Net 服务名。此 Oracle Net 服务名被假定为已在 FAL 服务器系统上正确配置, 可指向 FAL 客户机 (即: 此备用数据库)。 值范围: Oracle Net 服务名的字符串值。 Drs_start: 说明: 使 Oracle 可以确定是否应启动 DRMON 进程。DRMON 是一种不导致致命错误的 Oracle 后台进程, 只要例程存在, 该进程就存在。 值范围: TRUE | FALSE。 默认值: FALSE remote_archive_enable: 说明: 控制是否可向远程目标执行重做日志文件归档操作。必须将该参数值设置为 "TRUE", 以便 Oracle 数据库例程对重做日志文件进行远程归档, 并且/或者接收远程归档的重做日志文件。 值范围: FALSE | TRUE 默认值: TRUE standby_preserves_names: 说明: 表明备用数据库上的文件名是否与主数据库上的文件名相同。 值范围: TRUE 或 FALSE。注: 如果将值设置为 True, 且备用数据库与主数据库位于同一系统上, 则主数据库文件可能被覆盖。 默认值: FALSE。 Standby_archive_dest: 说明: 指定来自一个主例程的归档日志的到达位置。STANDBY_ARCHIVE_DEST 和 LOG_ARCHIVE_FORMAT 用于在备用位置上虚拟完全合格的归档日志文件名。备用数据库上的 RFS 服务器将使用该值, 而不是 ARCHIVE_LOG_DEST。 值范围: NULL 字符串或非 RAW 类型的有效路径/设备名。 默认值: NULL db_file_name_convert: 说明: 将主数据库上的一个新数据文件的文件名转换为备用数据库上的文件名。 值范围: 一个有效的主/备用目录和文件名对。 默认值: 无 max_enable_roles: 说明: 指定一个用户可以启用的数据库角色 (包括子角色) 的最大数量。用户可启用的角色的实际数量是 2 加上 MAX_ENABLED_ROLES 的值, 因为每个用户都有两个附加的角色: PUBLIC 和用户自己的角色。 值范围: 0 -148 默认值: 20 O7_DICTIONARY_ACCESSIBILITY: 说明: 主要用于从 Oracle7 移植到 Oracle8i。如果该值为 TRUE, SYSTEM 权限 (如 SELECT ANY TABLE) 将不限制对 SYS 方案中各对象的访问 (Oracle7 行为)。如果该值为 FALSE, 只有被授予了 SELECT_CATALOG_ROLE, EXECUTE_CATALOG_ROLE 或 DELETE_CATALOG_ROLE 权限的用户才能访问 SYS 方案中的各对象。 值范围: TRUE | FALSE 默认值: TRUE sql92_security: 说明: 指定要执行一个更新或删除引用表列的值是否需要具有表级的 SELECT 权限。 值范围: TRUE | FALSE 默认值: FALSE audit_trail: 说明: 启用或禁用数据库审计。如果该参数为 TRUE 或 DB, 审计记录将被写入 SYS.AUD$ 表中; 如果参数为 OS, 则写入一个操作系统文件。 值范围: NONE | FALSE | DB | TRUE | OS 默认值: NONE rdbms_server_dn: 说明: RDBMS 服务器的唯一判别名。它用于在一个企业目录服务中检索企业角色。有关详细信息, 请参阅“Oracle Advanced Security Administrator's Guide”。 值范围: 所有 X.500 唯一判别名格式值。 默认值: 无 os_roles: 说明: 确定操作系统或数据库是否为每个用户标识角色。如果设置为 TRUE, 将由操作系统完全管理对所有数据库用户的角色授予。否则, 角色将由数据库标识和管理。 值范围: TRUE | FALSE 默认值: FALSE os_authent_prefix: 说明: 使用用户的操作系统帐户名和口令来验证连接到服务器的用户。该参数的值与各用户的操作系统帐户连接在一起。要去除 OS 帐户前缀, 请指定空值。 值范围: 任何标识符。 默认值: 根据操作系统而定 (通常是 'OPS$') object_cache_max_size_percent: 说明: 指定话对象的高速缓存增长可超过最佳高速缓存大小的百分比, 最大大小等于最佳大小加上该百分比与最佳大小的乘积。如果高速缓存大小超过了这个最大大小, 系统就尝试将高速缓存缩小到最佳大小。 值范围: 0% 到根据操作系统而定的最大值。 默认值: 10% object_cache_optimal_size: 说明: 指定在高速缓存超过最大大小的情况下, 话对象高速缓存将被缩小到的大小。 值范围: 10K 到根据操作系统而定的最大值。 默认值: 100K session_max_open_files: 说明: 指定可在任一给定话中打开的 BFILE 的最大数量。一旦达到这个数量, 此后将无法在该话中打开更多文件。该参数还取决于操作系统参数 MAX_OPEN_FILES。 值范围: 1 - 至少为 (50, OS 级上的 MAX_OPEN_FILES)。 默认值: 10 parallel_execution_message_size: 说明: 指定并行执行 (并行查询, PDML, 并行恢复和复制) 消息的大小。如果值大于 2048 或 4096, 就需要更大的共享池。如果 PARALLEL_AUTOMATIC_TUNING = TRUE, 将在大存储池之外指定消息缓冲区。 值范围: 2148 - 无穷大。 默认值: 如果 PARALLEL_AUTOMATIC_TUNING 为 FALSE, 通常值为 2148; 如果 PARALLEL_AUTOMATIC_TUNING 为 TRUE , 则值为 4096 (根据操作系统而定)。 Paralle_min_percent: 说明: 指定并行执行要求的线程的最小百分比。设置该参数, 可以确保并行执行在没有可用的恰当查询从属进程时, 显示一个错误消息, 并且该查询因此而不予执行。 值范围: 0 -100 默认值: 0, 表示不使用该参数。 Parallel_automatic_tuning: 说明: 如果设置为 TRUE, Oracle 将为控制并行执行的参数确定默认值。除了设置该参数外, 你还必须为系统中的表设置并行性。 值范围: TRUE | FALSE 默认值: FALSE parallel_threads_per_cpu: 说明: 说明一个 CPU 在并行执行过程中可处理的进程或线程的数量, 并优化并行自适应算法和负载均衡算法。如果计算机在执行一个典型查询时有超负荷的迹象, 应减小该数值。 值范围: 任何非零值。 默认值: 根据操作系统而定 (通常为 2) parallel_broadcast_enabled: 说明 : 通过使用一个散列联接或合并联接, 可以在将多个大结果集联接到一个小结果集 (以字节而不是行为单位来衡量大小) 时改善性能。如果该值设置为 TRUE, 优化程序可以将小结果集内的每个行都传播到大型集内的每个集群数据库处理行中。 值范围: TRUE | FALSE 默认值 : FALSE parallel_adaptive_multi_user: 说明: 启用或禁用一个自适应算法, 旨在提高使用并行执行方式的多用户环境的性能。通过按系统负荷自动降低请求的并行度, 在启动查询时实现此功能。当 PARALLEL_AUTOMATIC_TUNING = TRUE 时, 其效果最佳。 值范围: TRUE | FALSE 默认值: 如果 PARALLEL_AUTOMATIC_TUNING = TRUE, 则该值为 TRUE; 否则为 FALSE parallel_max_servers: 说明: 指定一个例程的并行执行服务器或并行恢复进程的最大数量。如果需要, 例程启动时分配的查询服务器的数量将增加到该数量。 值范围: 0 -256 默认值: 由 CPU_COUNT, PARALLEL_AUTOMATIC_TUNING 和 PARALLEL_ADAPTIVE_MULTI_USER 确定 parallel_min_servers 说明: 指定为并行执行启动例程后, Oracle 创建的查询服务器进程的最小数量。 值范围: 0 - PARALLEL_MAX_SERVERS。 默认值: 0 log_archive_dest_state_3: 说明: 指定相应的归档日志目标参数 (仅 LOG_ARCHIVE_DEST_3) 的可用性状态。如果启用, 日志目标将被归档。如果延迟, 该目标将被排除在归档操作之外直至重新启用。 值范围: ENABLE | DEFER 默认值: ENABLE log_archive_dest_state_4: 说明: 指定相应的归档日志目标参数 (仅 LOG_ARCHIVE_DEST_4) 的可用性状态。如果启用, 日志目标将被归档。如果延迟, 该目标将被排除在归档操作之外直至重新启用。 值范围: ENABLE | DEFER 默认值: ENABLE log_archive_dest_state_5: 说明: 指定相应的归档日志目标参数 (仅 LOG_ARCHIVE_DEST_5) 的可用性状态。如果启用, 日志目标将被归档。如果延迟, 该目标将被排除在归档操作之外直至重新启用。 值范围: ENABLE | DEFER 默认值: ENABLE log_archive_dest_state_6: 说明: 标识特定日志归档目标的最近的用户定义状态。 值范围: ENABLE--如果目标属性有效, 则启用归档日志目标; DEFER--即使目标属性有效, 也要延迟处理归档日志目标; 或者是 ALTERNATE--延迟处理归档日志目标, 直到另一个目标的失败导致自动启用了此目标 (前提是备用目标的属性必须有效)。 log_archive_dest_state_7: 说明: 标识特定日志归档目标的最近的用户定义状态。 值范围: ENABLE--如果目标属性有效, 则启用归档日志目标; DEFER--即使目标属性有效, 也要延迟处理归档日志目标; 或者是 ALTERNATE--延迟处理归档日志目标, 直到另一个目标的失败导致自动启用了此目标 (前提是备用目标的属性必须有效)。 log_archive_dest_state_8: 说明: 标识特定日志归档目标的最近的用户定义状态。 值范围: ENABLE--如果目标属性有效, 则启用归档日志目标; DEFER--即使目标属性有效, 也要延迟处理归档日志目标; 或者是 ALTERNATE--延迟处理归档日志目标, 直到另一个目标的失败导致自动启用了此目标 (前提是备用目标的属性必须有效)。 log_archive_dest_state_9: 说明: 标识特定日志归档目标的最近的用户定义状态。 值范围: ENABLE--如果目标属性有效, 则启用归档日志目标; DEFER--即使目标属性有效, 也要延迟处理归档日志目标; 或者是 ALTERNATE--延迟处理归档日志目标, 直到另一个目标的失败导致自动启用了此目标 (前提是备用目标的属性必须有效)。 Log_archive_start: 说明: n只在数据库处于“归档日志”模式的情况下适用。它指定重做日志是自动还是手动复制。建议值是 TRUE, 即执行自动归档; 否则就需要手动干预, 使用 ALTER SYSTEM ARCHIVE LOG ... 命令来阻止例程挂起。 值范围: TRUE | FALSE 默认值: FALSE log_archive_duplex_dest: 说明: 指定 LOG_ARCHIVE_DEST 外的另一个归档目标。在 Oracle8i 企业版中, 该参数被 LOG_ARCHIVE_DEST_n 代替。 值范围: 一个 NULL 字符串, 或者任何有效的路径或设备名, 原始分区除外。 默认值: NULL log_archive_format: 说明: LOG_ARCHIVE_FORMAT 只在数据库处于“归档日志”模式的情况下有用。文本字符串与变量 %s (日志序列号) 和 %t (线程号) 结合使用, 用于指定各归档重做日志文件的唯一文件名。该字符串被附加到 LOG_ARCHIVE_DEST 参数。 值范围: 任何有效的文件名。 默认值: 根据操作系统而定 log_archive_max_processes: 说明: 指定要求的 ARCH 进程的数量。如果 LOG_ARCHIVE_START = TRUE, 该值可以在例程启动时被评估; 也可以在通过 SQL*Plus 或 SQL 语法调用 ARCH 进程时评估。 值范围: 1 - 10 (包括端点) 的任何整数。 默认值: 1 log_archive_dest_2: 说明: 五个本地 (指定 LOCATION) 或远程 (指定 SERVICE) 目标位置中的第二个, 归档重做日志文件可以在这些目标位置上被复制。该参数只在企业版 oracle8i 数据库或更高版本的数据库中有效。 值范围: 语法为 (null_string | SERVICE=tnsnames-service | LOCATION=directory-spec)[MANDATORY | OPTIONAL][REOPEN=integer] 默认值: NULL log_archive_min_succeed_dest: 说明: 定义在可以覆盖日志文件前必须将其复制到的目标的最小数量。该值应大于或等于 LOG_ARCHIVE_DEST_n 中 MANDATORY 目标的数量。 值范围: 1 - 5 (如果与 LOG_ARCHIVE_DEST 和 LOG_ARCHIVE_DUPLEX_DEST 共同使用, 则限制在 1-2)。 默认值: 1 log_archive_trace: 说明: 控制归档日志进程生成的输出。此进程可以通过下列方式启动 ARCn 后台进程 (在输出日志中指定为 ARCn) 明确的话调用的前台进程 (在输出日志中指定为 ARCH) 或 “受管备用数据库”的远程文件服务器 (RFS) 进程。 值范围: 0: 禁用归档日志跟踪 (这是默认设置) 1: 重做日志文件的追踪归档 2: 每个归档日志目标的追踪归档状态 4: 追踪归档操作阶段 8: 追踪归档日志目标活动 16: 追踪详细的归档日志目标活动 32: 追踪归档日志目标参数修改 64: 追踪 ARCn 进程状态活动 默认值: 0 log_archive_dest_10: log_archive_dest_3: 说明: 五个本地 (指定 LOCATION) 或远程 (指定 SERVICE) 目标位置中的第三个, 归档重做日志文件可以在这些目标位置上被复制。该参数只在企业版 oracle8i 数据库或更高版本的数据库中有效。 值范围: 语法为 (null_string | SERVICE=tnsnames-service | LOCATION=directory-spec)[MANDATORY | OPTIONAL][REOPEN=integer] 默认值: NULL log_archive_dest: 说明: 五个本地 (指定 LOCATION) 或远程 (指定 SERVICE) 目标位置中的第三个, 归档重做日志文件可以在这些目标位置上被复制。该参数只在企业版 oracle8i 数据库或更高版本的数据库中有效。 值范围: 语法为 (null_string | SERVICE=tnsnames-service | LOCATION=directory-spec)[MANDATORY | OPTIONAL][REOPEN=integer] 默认值: NULL log_archive_dest_state_2: 说明: 指定相应的归档日志目标参数 (仅 LOG_ARCHIVE_DEST_2) 的可用性状态。如果启用, 日志目标将被归档。如果延迟, 该目标将被排除在归档操作之外直至重新启用。 值范围: ENABLE | DEFER 默认值: ENABLE log_archive_dest_5: 说明: 五个本地 (指定 LOCATION) 或远程 (指定 SERVICE) 目标位置中的第五个, 归档重做日志文件可以在这些目标位置上被复制。该参数只在企业版 oracle8i 数据库或更高版本的数据库中有效。 值范围: 语法为 (null_string | SERVICE=tnsnames-service | LOCATION=directory-spec)[MANDATORY | OPTIONAL][REOPEN=integer] 默认值: NULL log_archive_dest_6: log_archive_dest_1: log_archive_dest_8: log_archive_dest_9: log_archive_dest_state_1: 说明: 指定相应的归档日志目标参数 (仅 LOG_ARCHIVE_DEST_1) 的可用性状态。如果启用, 日志目标将被归档。如果延迟, 该目标将被排除在归档操作之外直至重新启用。 值范围: ENABLE | DEFER 默认值: ENABLE log_archive_dest_state_10 说明: 指定归档日志的目标。 值范围: 本地文件系统位置 (磁盘位置) 或通过 Oracle Net 服务名 (tns 服务) 指定的远程归档位置。: log_archive_dest_4: 说明: 五个本地 (指定 LOCATION) 或远程 (指定 SERVICE) 目标位置中的第四个, 归档重做日志文件可以在这些目标位置上被复制。该参数只在企业版 oracle8i 数据库或更高版本的数据库中有效。 值范围: 语法为 (null_string | SERVICE=tnsnames-service | LOCATION=directory-spec)[MANDATORY | OPTIONAL][REOPEN=integer] 默认值: NULL create_bitmap_area_size: 说明: CREATE_BITMAP_AREA_SIZE 指定为创建位图索引而分配的内存量。 值范围: 根据操作系统而定。 默认值: 8 MB pga_aggregate_target: 说明: 指定连接到例程的所有服务器进程的目标 PGA 总内存。请在启用自动设置工作区之前将此参数设置为一个正数。这部分内存不驻留在 SGA 中。数据库将此参数值用作它所使用的目标 PGA 内存量。设置此参数时, 要将 SGA 从可用于 Oracle 例程的系统内存总量中减去。然后可将剩余内存量分配给 pga_aggregate_target。 值范围: 整数加字母 K, M 或 G, 以将此限值指定为千字节, 兆字节或千兆字节。最小值为 10M, 最大值为 4000G 默认值: "未指定", 表示完全禁用对工作区的自动优化。 Sort_area_size: 说明: SORT_AREA_SIZE 以字节为单位, 指定排序所使用的最大内存量。排序完成后, 各行将返回, 并且内存将释放。增大该值可以提高大型排序的效率。如果超过了该内存量, 将使用临时磁盘段。 值范围: 相当于 6 个数据库块的值 (最小值) 到操作系统确定的值 (最大值)。 默认值: 根据操作系统而定 sort_area_retained_size 说明: 以字节为单位, 指定在一个排序运行完毕后保留的用户全局区 (UGA) 内存量的最大值。最后一行从排序空间中被提取后, 该内存将被释放回 UGA, 而不是释放给操作系统。 值范围: 从相当于两个数据库块的值到 SORT_AREA_SIZE 的值。 默认值: SORT_AREA_SIZE 的值 bitmap_merge_area_size: 说明: 指定合并从对索引的某一范围进行扫描而检索得到的位图要使用的内存量。 值范围: 根据系统而定。 默认值: 1MB workarea_size_policy: 说明: 指定调整工作区大小的策略。此参数控制优化工作区时所处的模式。 值范围: AUTO, MANUAL。 默认值: 如果设置了 PGA_AGGREGATE_TARGET, 则为 AUTO; 否则为 MANUAL。 Hash_area_size: 说明: 与并行执行操作和 DML 或 DDL 语句相关。它以字节为单位, 指定要用于散列联接的最大内存量。有关详细信息, 请参阅手册 Oracle8i Concepts。 值范围: 0 到根据操作系统而定的值。 默认值: 派生:2 * SORT_AREA_SIZE 参数值 db_create_online_log_dest_4: 说明: 设置所创建的联机日志和控制文件的默认位置。如果在创建联机日志或控制文件时未指定文件名, 则使用默认文件名。 值范围: 文件系统目录名。该目录必须已存在。该目录必须具有可让 Oracle 在其中创建文件的许可。 db_create_online_log_dest_3: 说明: 设置所创建的联机日志和控制文件的默认位置。如果在创建联机日志或控制文件时未指定文件名, 则使用默认文件名。 值范围: 文件系统目录名。该目录必须已存在。该目录必须具有可让 Oracle 在其中创建文件的许可。 Db_files: 说明: 可为该数据库打开的数据文件的最大数量。 值范围: MAXDATAFILES - 根据操作系统而定。 默认值: 根据操作系统而定 (在 Solaris 系统上为 200) db_create_online_log_dest_2: 说明: 设置所创建的联机日志和控制文件的默认位置。如果在创建联机日志或控制文件时未指定文件名, 则使用默认文件名。 值范围: 文件系统目录名。该目录必须已存在。该目录必须具有可让 Oracle 在其中创建文件的许可。 db_create_online_log_dest_1: 说明: 设置所创建的联机日志和控制文件的默认位置。如果在创建联机日志或控制文件时未指定文件名, 则使用默认文件名。 值范围: 文件系统目录名。该目录必须已存在。该目录必须具有可让 Oracle 在其中创建文件的许可。 Db_create_file_dest: 说明: 设置所创建的数据文件, 控制文件和联机日志的默认位置。 值范围: 文件系统目录名。该目录必须已存在。该目录必须具有可让 Oracle 在其中创建文件的许可。 Control_files: 说明: 指定一个或多个控制文件名。Oracle 建议对于不同设备或 OS 文件镜象使用多个文件。 值范围: 1 - 8 文件名 (带路径名)。 默认值: 根据操作系统而定 db_create_online_log_dest_5: 说明: 设置所创建的联机日志和控制文件的默认位置。如果在创建联机日志或控制文件时未指定文件名, 则使用默认文件名。 值范围: 文件系统目录名。该目录必须已存在。该目录必须具有可让 Oracle 在其中创建文件的许可。 Large_pool_size: 说明 : 指定大型池的分配堆的大小, 它可被共享服务器用作话内存, 用作并行执行的消息缓冲区以及用作 RMAN 备份和恢复的磁盘 I/O 缓冲区。 值范围: 600K (最小值); >= 20000M (最大值是根据操作系统而定的)。 默认值 : 0, 除非配置了并行执行或 DBWR_IO_SLAVES shared_pool_size: 说明: 以字节为单位, 指定共享池的大小。共享池包含如: 共享游标, 存储的过程, 控制结构和并行执行消息缓冲区等对象。较大的值能改善多用户系统的性能。 值范围:300 KB - 根据操作系统而定。 默认值: 如果是 64 位操作系统, 值为 64MB; 其他情况下, 值为 16MB。 Java_pool_size: 说明: 以字节为单位, 指定 Java 存储池的大小, 它用于存储 Java 的方法和类定义在共享内存中的表示法, 以及在调用结束时移植到 Java 话空间的 Java 对象。有关详细信息, 请参阅 Oracle8i Java Developer's Guide。 值范围: 根据操作系统而定。 默认值: 根据操作系统而定 shared_pool_reserved_size: 说明: 指定要为较大连续共享池内存请求而保留的空间, 以避免由碎片引起的性能下降。该池的大小应符合这样的条件:能存储为防止对象从共享池刷新而普遍要求的所有大型过程和程序包。 值范围: SHARED_POOL_RESERVED_MIN_ALLOC 到 SHARED_POOL_SIZE 的一半 (字节)。 默认值: SHARED_POOL_SIZE 值的 5% cursor_sharing: 说明: 控制可以终止共享相同的共享游标的 SQL 语句类型。 值范围: 强制: 强制表达方式不同但语句意思相同的语句共享一个游标。 EXACT: 只令完全相同的 SQL 语句共享一个游标。 默认值: EXACT open_cursors: 说明: 指定一个话一次可以打开的游标 (环境区域) 的最大数量, 并且限制 PL/SQL 使用的 PL/SQL 游标高速缓存的大小, 以避免用户再次执行语句时重新进行语法分析。请将该值设置得足够高, 这样才能防止应用程序耗尽打开的游标。 值范围: 1 - 操作系统限制值。 默认值: 64 serial_reuse: 说明: 指定何种类型的 SQL 游标应利用串行可重用内存功能。如果 CURSOR_SPACE_FOR_TIME = TRUE, 那么 SERIAL_REUSE 值将被忽略, 当作被设置为 DISABLE 或 NULL 的情况处理。 值范围: DISABLE | SELECT | DML | PLSQL | ALL | NULL 默认值: NULL session_cached_cursors: 说明: 指定要高速缓存的话游标的数量。对同一 SQL 语句进行多次语法分析后, 它的话游标将被移到该话的游标高速缓存中。这样可以缩短语法分析的时间, 因为游标被高速缓存, 无需被重新打开。 值范围: 0 到根据操作系统而定的值。 默认值: 0 cursor_space_for_time: 说明: 在一个游标引用共享 SQL 区时, 确定将 SQL 区保留在共享池中还是从中按过期作废处理。 值范围: TRUE | FALSE 默认值: FALSE (过期作废) rollback_segments: 说明: 指定要在例程启动过程中获取的一个或多个回退段, 即使其数量超过了 TRANSACTIONS / TRANSACTIONS_PER_ROLLBACK_SEGMENT 的值。公式为 ROLLBACK_SEGMENTS = (rbseg_name [, rbseg_name] ...) 值范围:除 SYSTEM 外, DBA_ROLLBACK_SEGS 中列出的任何回退段。 默认值: NULL (默认情况下使用公用回退段) undo_suppress_errors: 说明: 允许用户在 SMU 模式下尝试执行 RBU 操作 (如 ALTER ROLLBACK SEGMENT ONLINE) 时忽略错误。这样能让用户在将所有应用程序和脚本转换到 SMU 模式之前即可使用 SMU 功能。 值范围: True 或 False 默认值: False。 Max_rollback_segments: 说明: 指定 SGA 中高速缓存的回退段的最大大小。该数值指定一个例程中可同时保持联机状态 (即状态为 INUSE) 的回退段的最大数量。 值范围: 2 -65535 默认值: 最大值 (30, TRANSACTIONS/TRANSACTIONS_PER_ROLLBACK_SEGMENT) undo_retention: 说明: UNDO_RETENTION 参数用来指定要在数据库中保留的已提交的撤消信息总量。可在例程启动时设置该参数值。可以计算满足撤消保留要求所需的撤消空间量: UndoSpace = RD * UPS, 其中 UndoSpace 以撤消块数来表示, RD 用以秒为单位的 UNDO_RETENTION 来表示, UPS 以每秒撤消块数来表示。 值范围: 所允许的最大值为 (2 ** 32) 秒。 默认值: 30 秒。 Transactions_per_rollback_segment: 说明: 指定每个回退段允许的并行事务处理的数量。启动时获取的回退段的最小数量为 TRANSACTIONS 除以该参数值的结果。如果在参数 ROLLBACK_SEGMENTS 中命名了其他回退段, 就可以获取这些回退段。 值范围: 1 - 根据操作系统而定。 默认值: 5 undo_management: 说明: 指定系统应使用哪种撤消空间管理模式。如果设置为 AUTO, 例程将以 SMU 模式启动。否则将以 RBU 模式启动。在 RBU 模式下, 撤消空间象回退段一样在外部分配。在 SMU 模式下, 撤消空间象撤消表空间一样在外部分配。 值范围: AUTO 或 MANUAL 默认值: 如果启动第一个例程时忽略了 UNDO_MANAGEMENT 参数, 则将使用默认值 MANUAL, 并且例程将以 RBU 模式启动。如果这不是第一个例程, 则将按其他现有例程启动时使用的撤消模式来启动该例程。 Undo_tablespace: 说明: 撤消表空间仅用于存储撤消信息。UNDO_TABLESPACE 仅允许在系统管理撤消 (SMU) 模式下使用。例程将使用指定的撤消表空间, 。如果该表空间不存在, 或不是撤消表空间, 或正在由另一例程使用, 则例程 STARTUP 将失败。 默认值: 每个数据库都包含 0 个或更多的撤消表空间。在 SMU 模式下, 将为每个 ORACLE 例程分配一个 (且仅限一个) 撤消表空间。 Instance_name 说明: 在多个例程使用相同服务名的情况下, 用来唯一地标识一个数据库例程。INSTANCE_NAME 不应与 SID 混淆, 它实际上是对在一台主机上共享内存的各个例程的唯一标识。 值范围: 任何字母数字字符。 默认值: 数据库 SID service_names: 说明 : 为 Oracle Net 监听程序用来识别一个服务 (如: 复制环境中的一个特定数据库) 的例程指定服务名。如果该服务没有域, 将附加 DB_DOMAIN 参数。 语法 : SERVICE_NAMES = name1.domain, name2.domain 默认值 : DB_NAME.DB_DOMAIN (如果已定义) local_listener: 说明 : 一个 Oracle Net 地址列表, 用于标识 Oracle Net 监听程序所在的同一台计算机上的数据库例程。所有例程和调度程序都在该监听程序上注册, 以便启用客户机连接。该参数覆盖在 8.1 版本中废弃的 MTS_LISTENER_ADDRESS 和 MTS_MULTIPLE_LISTENERS 参数。 值范围: 一个有效的 Oracle Net 地址列表。 默认值: (ADDRESS_LIST=(Address=(Protocol=TCP)(Host=localhost)(Port=1521)) (Address=(Protocol=IPC)(Key=DBname))) license_sessions_warning: 说明: 指定对并行用户话数量的警告限制。达到该限制后, 其他用户仍然可以连接, 但一条消息将被写入 ALERT 文件。具有 RESTRICTED SESSION 权限的用户将收到一条警告消息, 表明系统已接近最大容量。 值范围: 0 - LICENSE_MAX_SESSIONS 默认值: 0 license_max_sessions: 说明: 指定允许同时进行的并行用户话的最大数量。达到该限制后, 只有具有 RESTRICTED SESSION 权限的用户才能连接到服务器。所有其他用户都收到一条警告消息, 表明已达到系统最大容量的限制。 值范围: 0 - 话许可的数量。 默认值: 0 license_max_users: 说明: 指定您可在该数据库中创建的用户的最大数量。并行话使用许可和用户使用许可不应被同时启用。LICENSE_MAX_SESSIONS 或 LICENSE_MAX_USERS 或这两者的值应为零。 值范围: 0 - 用户许可的数量。 默认值: 0 db_block_checksum: 说明: DBWn, ARCH 和 SQL*loader 是否为每一个数据块读或写计算或校验块的校验和。 值范围: TRUE | FALSE 默认值: FALSE shadow_core_dump: 说明: 一个针对 UNIX 的参数, 用于指定是否将 SGA 信息转储到一个生成的核心文件中。如果设置为 FULL, SGA 将被包括在核心转储中。如果设置为 PARTIAL, SGA 将不被转储。 值范围: FULL | PARTIAL 默认值: FULL db_block_checking: 说明: 用于控制是否检查事务处理管理的块有无损坏。 值范围: TRUE | FALSE 默认值: FALSE background_core_dump: 说明: 是否将 SGA 信息转储到一个生成的核心文件中 (用于 UNIX)。 值范围: FULL | PARTIAL 默认值: FULL event: 说明: 由 Oracle 技术支持人员使用, 以调试系统。一般情况下, 不应变更该值。 值范围:不可用。 默认值: 无 user_dump_dest: 说明: 为服务器将以一个用户进程身份在其中写入调试跟踪文件的目录指定路径名。例如, 该目录可这样设置: NT 操作系统上的 C:/ ORACLE/UTRC; UNIX 操作系统上的 /oracle/utrc; 或 VMS 操作系统上的 DISK$UR3:[ORACLE.UTRC]。 值范围: 一个有效的本地路径名, 目录或磁盘。 默认值: 根据操作系统而定 timed_statistics: 说明: 收集操作系统的计时信息, 这些信息可被用来优化数据库和 SQL 语句。要防止因从操作系统请求时间而引起的开销, 请将该值设置为零。将该值设置为 TRUE 对于查看长时间操作的进度也很有用。 值范围: TRUE | FALSE 默认值: FALSE timed_os_statistics: 说明 : 由系统管理员使用, 以收集操作系统统计信息。为了有效地使用资源, 请只在需要时才设置该值。对于专用服务器, 在用户连接, 断开连接以及弹出调用 (如果超出了指定的时间限制) 的情况下收集操作系统统计信息。对于共享服务器, 将为推入或弹出的调用收集统计信息。 值范围: 以秒为单位的时间。 默认值 : 0 (操作系统统计信息不被刷新) core_dump_dest: 说明: 指定核心转储位置的目录名 (用于 UNIX)。 值范围: 任何有效的目录名。 默认值: ORACLE_HOME/dbs oracle_trace_collection_name: 说明: 指定 Oracle Trace 收集名, 并在输出文件名中使用 (收集定义文件 .cdf 和数据收集文件 .dat)。如果该参数不为空, 且 ORACLE_TRACE_ENABLE = TRUE, 就启动一个默认的 Oracle Trace 收集, 直到该值再次设置为 NULL。 值范围: 一个有效的收集名, 最长可为 16 个字符 (使用 8 个字符文件名的平台除外)。 默认值: NULL oracle_trace_collection_path: 说明: 指定 Oracle Trace 收集定义文件 (.cdf) 和数据收集文件 (.dat) 所在的目录路径名。 值范围: 完整的目录路径名。 默认值: 根据操作系统而定 (通常是 ORACLE_HOME/otrace/admin/cdf) background_dump_dest: 说明: 指定在 Oracle 操作过程中为后台进程 (LGWR, DBW n 等等) 写入跟踪文件的路径名 (目录或磁盘)。它还定义记录着重要事件和消息的数据库预警文件的位置。 值范围: 任何有效的目录名。 默认值: ORACLE_HOME/rdbms/log (根据操作系统而定) oracle_trace_enable: 说明: 要为服务器启用 Oracle Trace 收集, 请将该值设置为 TRUE。如果设置为 TRUE, 该服务器就可以使用 Oracle Trace。要启动一个收集过程, 请为 ORACLE_TRACE_COLLECTION_NAME 指定一个非空值; 或者使用 Oracle Trace Manager 来启动一个收集。 值范围: TRUE | FALSE 默认值: FALSE oracle_trace_collection_size: 说明: 以字节为单位, 指定 Oracle Trace 收集文件的最大大小。一旦该收集文件的大小达到这个最大值, 收集就被禁用。如果值范围指定为零, 就表示没有大小限制。 值范围: 0 -4294967295 默认值: 5242880 oracle_trace_facility_path: 说明: 指定 Oracle TRACE 工具的定义文件 (.fdf) 所在的目录路径名。 值范围: 完整的目录路径名。 默认值: ORACLE_HOME/otrace/admin/fdf/ (根据操作系统而定) sql_trace: 说明: 禁用或启用 SQL 跟踪设备。如果设置为 TRUE, 将收集优化信息, 这些信息对改善性能很有用。由于使用 SQL 跟踪设备将引发系统开销, 只应在需要优化信息的情况下使用 TRUE。 值范围: TRUE | FALSE 默认值: FALSE oracle_trace_facility_name: 说明: 指定 Oracle Trace 产品定义文件名 (.fdf 文件名)。该文件包含可为使用 Oracle Trace 数据收集 API 的产品收集的所有事件和数据项的定义信息。Oracle 建议使用默认的文件 ORCLED.FDF。 值范围: 一个有效的设备名, 最长可有 16 个字符。 默认值: oracled max_dump_file_size: 说明: 指定每个跟踪文件的最大大小。如果您担心跟踪文件占用太多空间, 可更改该限制。如果转储文件可以达到操作系统允许的最大大小, 请将该值指定为“无限制”。 值范围: 0 - 无限制 (可以用 'K' 或 'M' 为单位) 默认值: 10000 块 resource_limit: 说明: 确定是否在数据库概要文件中实行资源限制。如果设置为 FALSE, 将禁用资源限制。如果值为 TRUE, 即启用资源限制。 值范围: TRUE | FALSE 默认值: FALSE resource_manager_plan: 说明: 如果指定该值, 资源管理器将激活计划和例程的所有子项 (子计划, 指令和使用者组)。如果不指定, 资源管理器将被禁用, 但使用 ALTER SYSTEM 命令还可以启用。 值范围: 任何有效的字符串。 默认值: NULL sessions: 说明: 指定用户话和系统话的总量。默认数量大于 PROCESSES, 以允许递归话。 值范围: 任何整数值。 默认值: 派生 (1.1 * PROCESSES + 5) java_soft_sessionspace_limit: 说明: 以字节为单位, 指定在 Java 话中使用的 Java 内存 的 '软限制'。如果用户的话持续时间 Java 状态使用过多的内存, Oracle 将生成一个警告并向跟踪文件写入一则消息。 值范围: 0 - 4GB 默认值: 0 cpu_count: 说明: Oracle 可用的 CPU 的数目 (用于计算其他参数值)。请勿更改该值。 值范围: 0 - 无限制。 默认值: 由 Oracle 自动设置 java_max_sessionspace_size: 说明: 以字节为单位, 指定可供在服务器中运行的 Java 程序所使用的最大内存量。它用于存储每次数据库调用的 Java 状态。如果用户的话持续时间 Java 状态超过了该值, 则该由于内存不足而终止。 值范围: 根据操作系统而定。 默认值: 0 processes: 说明: 指定可同时连接到一个 Oracle Server 上的操作系统用户进程的最大数量。该值应允许执行所有后台进程, 如: 作业队列 (SNP) 进程和并行执行 (Pnnn) 进程。 值范围: 6 到根据操作系统而定的一个值。 默认值: 由 PARALLEL_MAX_SERVERS 确定 control_file_record_keep_time: 说明: 控制文件中可重新使用部分中的记录必须保留的最短时间 (天数)。 值范围: 0 -365 默认值: 7 log_checkpoint_timeout: 说明: 指定距下一个检查点出现的最大时间间隔 (秒数)。将该时间值指定为 0, 将禁用以时间为基础的检查点。较低的值可以缩短例程恢复的时间, 但可能导致磁盘操作过量。 值范围: 0 - 无限制。 默认值: Oracle8i:900 秒。企业版: 1800 秒 recovery_parallelism: 说明: 指定参与例程或介质恢复的进程的数量。如果值为 0 或 1, 就表明恢复将由一个进程以串行方式执行。 值范围: 根据操作系统而定 (不能超过 PARALLEL_MAX_SERVERS)。 默认值: 根据操作系统而定 fast_start_mttr_target: 说明: 指定从单个数据库例程崩溃中恢复所需的时间 (估计秒数)。FAST_START_MTTR_TARGET 将在内部被转换为一组参数, 用于修改数据库的操作, 从而将它的恢复时间控制在总 "恢复平均时间 (MTTR)" 中的一定范围之内。只有具有 "快速启动故障恢复" 功能的版本才支持此参数。 值范围: [0, 3600]。它将计算数据缓冲区高速缓存条目数之上, 且大于最大日志中的块数的限值。 默认值: 0 log_checkpoints_to_alert: 说明: 指定将检查点信息记录到预警文件中。该参数对于确定检查点是否按所需频率出现很有用。 值范围: TRUE | FALSE 默认值: FALSE fast_start_io_target: 说明: 指定在系统崩溃或例程恢复期间需要的 I/O 数量。该值比 DB_BLOCK_MAX_DIRTY_TARGET 对恢复过程的控制更加精确。 值范围: 0 (禁用 I/O 恢复限制) 或 1000, 到高速缓存中的所有缓冲区数。 默认值: 高速缓存中的所有缓冲区数 log_checkpoint_interval: 说明: 指定在出现检查点之前, 必须写入重做日志文件中的 OS 块 (而不是数据库块) 的数量。无论该值如何, 在切换日志时都出现检查点。较低的值可以缩短例程恢复所需的时间, 但可能导致磁盘操作过量。 值范围: 无限制 (指定 0 即可禁用该参数)。 默认值: 根据操作系统而定 log_buffer: 说明: 以字节为单位, 指定在 LGWR 将重做日志条目写入重做日志文件之前, 用于缓存这些条目的内存量。重做条目保留对数据
目 录 第1章 成本的含义 1 1.1 优化器选项 2 1.2 成本的定义 3 1.3 变换和成本计算 5 1.4 所见未必即所得 8 1.5 本章小结 8 1.6 测试用例 8 第2章 表扫描 9 2.1 入门 10 2.2 提高 14 2.2.1 块大小的影响 14 2.2.2 CPU成本计算 16 2.2.3 CPU成本计算的作用 22 2.3 BCHR 24 2.4 并行执行 27 2.5 索引快速全扫描 30 2.6 分区 32 2.7 本章小结 37 2.8 测试用例 37 第3章 单表选择率 39 3.1 入门 40 3.2 空值 42 3.3 使用列表 43 3.4 区间谓词 48 3.5 双谓词 52 3.6 多谓词的相关问题 54 3.7 本章小结 56 3.8 测试用例 57 第4章 简单B树访问 59 4.1 索引成本计算的基础知识 60 4.2 入门 61 4.2.1 有效索引选择率 63 4.2.2 有效表选择率 64 4.2.3 clustering_factor 65 4.2.4 综合计算 67 4.2.5 扩展算法 68 4.2.6 3个选择率 74 4.3 CPU成本计算 78 4.4 待处理的零碎问题 80 4.5 本章小结 81 4.6 测试用例 81 第5章 群集因子 83 5.1 基本示例 84 5.1.1 减少表争用 (多个自由列表) 86 5.1.2 减少叶块的争用(反转键 索引,ReverseKey Index) 89 5.1.3 减少表的争用(ASSM) 92 5.1.4 减少RAC中的争用 (自由列表群) 95 5.2 列顺序 96 5.3 额外的列 99 5.4 校正统计信息 101 5.4.1 sys_op_countchg()技术 101 5.4.2 非正式策略 105 5.5 待处理的零碎问题 106 5.6 本章小结 107 5.7 测试用例 107 第6章 选择率的相关问题 109 6.1 不同的数据类型 110 6.1.1 日期类型 110 6.1.2 字符类型 110 6.1.3 愚蠢的数据类型 112 6.2 前导零 116 6.3 致命的默认值 117 6.4 离散数据的风险 119 6.5 令人惊奇的sysdate 123 6.6 函数表示 125 6.7 相互关联的列 126 6.7.1 动态采样 129 6.7.2 优化器配置文件 132 6.8 传递闭包 133 6.9 产生约束的谓词 136 6.10 本章小结 139 6.11 测试用例 139 第7章 直方图 141 7.1 入门 142 7.2 普通直方图 147 7.2.1 直方图和绑定变量 147 7.2.2 Oracle何时忽略直方图 149 7.3 频率直方图 152 7.3.1 伪造频率直方图 155 7.3.2 注意事项 156 7.4 “高度均衡”直方图 157 7.5 重新审视数据问题 163 7.5.1 愚蠢的数据类型 163 7.5.2 危险的默认值 166 7.6 本章小结 167 7.7 测试用例 168 第8章 位图索引 169 8.1 入门 170 8.1.1 索引组件 174 8.1.2 表组件 175 8.2 位图合并 177 8.2.1 较低的基数 179 8.2.2 空值列 182 8.3 CPU成本计算 185 8.4 一些有趣的示例 186 8.4.1 多列索引 187 8.4.2 位图连接索引 187 8.4.3 位图转换 188 8.5 本章小结 191 8.6 测试用例 192 第9章 查询变换 193 9.1 入门 194 9.2 过滤 197 9.2.1 过滤优化 200 9.2.2 标量子查询 202 9.2.3 子查询分解 208 9.2.4 复杂视图合并 213 9.2.5 推入谓词 215 9.3 一般子查询 216 9.3.1 子查询参数 218 9.3.2 分类 219 9.3.3 半连接 224 9.3.4 反连接 226 9.3.5 反连接异常 228 9.3.6 Null和Notin 229 9.3.7 有序提示 231 9.4 星型变换连接 232 9.5 星型连接 237 9.6 展望 239 9.7 本章小结 240 9.8 测试用例 241 第10章 连接基数 243 10.1 基本的连接基数 244 10.2 实际SQL的连接基数 249 10.3 扩展和异常情况 252 10.3.1 使用范围的连接 252 10.3.2 不等于 253 10.3.3 重叠 256 10.3.4 直方图 257 10.3.5 传递闭包 260 10.4 三表连接 264 10.5 空值 267 10.6 实现问题 270 10.7 困难之处 274 10.8 特性 276 10.9 另一观点 278 10.10 本章小结 279 10.11 测试用例 279 第11章 嵌套循环 281 11.1 基本机制 282 11.2 实际示例 286 11.3 完备性检查 287 11.4 本章小结 291 11.5 测试用例 291 第12章 散列连接 293 12.1 入门 294 12.1.1 最优散列连接 297 12.1.2 一遍散列连接 299 12.1.3 多遍散列连接 304 12.2 追踪文件 308 12.2.1 event 10104 308 12.2.2 event 10053 309 12.3 难点 311 12.3.1 传统成本计算 311 12.3.2 现代成本计算 312 12.4 比较 313 12.5 多表连接 318 12.6 本章小结 321 12.7 测试用例 321 第13章 排序与归并连接 323 13.1 入门 324 13.1.1 内存的使用 329 13.1.2 CPU的使用 330 13.1.3 sort_area_retained_size 333 13.1.4 pga_aggregate_target 334 13.1.5 实际I/O 337 13.2 排序的成本 339 13.3 比较 343 13.4 归并连接 346 13.4.1 归并机制 347 13.4.2 无最初排序的归并连接 351 13.4.3 笛卡尔归并连接 352 13.5 聚集及其他 354 13.5.1 索引 358 13.5.2 集合运算 359 13.6 最后一次提醒 363 13.7 本章小结 365 13.8 测试用例 366 第14章 10053 trace文件 367 14.1 查询 368 14.2 执行计划 369 14.3 环境 370 14.4 追踪文件 371 14.4.1 参数设置 372 14.4.2 查询块 375 14.4.3 存储统计信息 376 14.4.4 单表 378 14.4.5 完备性检查 379 14.4.6 一般计划 380 14.4.7 Join order[1] 380 14.4.8 Join order[2] 386 14.4.9 Join order[3] 387 14.4.10 Join order[4] 388 14.4.11 Join order[5] 388 14.4.12 Join order[6] 392 14.4.13 Join order[7] 392 14.4.14 Join order[8] 395 14.4.15 Join order[9] 397 14.4.16 Join order[10] 398 14.4.17 Join order[11] 398 14.4.18 Join order[12] 401 14.4.19 Join order[13] 404 14.4.20 Join order[14] 405 14.4.21 Join order[15] 406 14.4.22 Join order[16] 407 14.4.23 Join order[17] 407 14.4.24 Join order[18] 409 14.5 连接评估小结 410 14.6 测试用例 413 附录A 升级问题 415 A.1 dbms_stats 416 A.2 频率直方图 417 A.3 CPU成本计算 417 A.4 舍入误差 417 A.5 绑定变量窥视 418 A.6 连接间的空值 418 A.7 B树到位图的转换 418 A.8 索引跳跃扫描 419 A.9 AND-Equal 419 A.10 索引散列连接 420 A.11 修正的In-List 420 A.12 传递闭包 420 A.13 sysdate算术修正 421 A.14 对空值的索引 422 A.15 pga_aggregate_target 422 A.16 排序 422 A.17 分组 423 A.18 完备性检查 423 A.19 超出界限的情况 423 A.20 关于类型 423 A.21 optimizer_mode 424 A.22 降序索引 424 A.23 复杂视图合并 424 A.24 非嵌套子查询 424 A.25 标量和过滤子查询 425 A.26 并行查询策略的两次变化 425 A.27 动态采样 425 A.28 临时表 425 A.29 字典统计 426 附录B 优化器参数 427 B.1 optimizer_features_enable 428 B.2 10053 trace文件 430 B.3 v$sql_optimizer_env 435
Contents Module Overview 1 Lesson 1: Memory 3 Lesson 2: I/O 73 Lesson 3: CPU 111 Module 3: Troubleshooting Server Performance Module Overview Troubleshooting server performance-based support calls requires product knowledge, good communication skills, and a proven troubleshooting methodology. In this module we will discuss Microsoft® SQL Server™ interaction with the operating system and methodology of troubleshooting server-based problems. At the end of this module, you will be able to:  Define the common terms associated the memory, I/O, and CPU subsystems.  Describe how SQL Server leverages the Microsoft Windows® operating system facilities including memory, I/O, and threading.  Define common SQL Server memory, I/O, and processor terms.  Generate a hypothesis based on performance counters captured by System Monitor.  For each hypothesis generated, identify at least two other non-System Monitor pieces of information that would help to confirm or reject your hypothesis.  Identify at least five counters for each subsystem that are key to understanding the performance of that subsystem.  Identify three common myths associated with the memory, I/O, or CPU subsystems. Lesson 1: Memory What You Will Learn After completing this lesson, you will be able to:  Define common terms used when describing memory.  Give examples of each memory concept and how it applies to SQL Server.  Describe how SQL Server user and manages its memory.  List the primary configuration options that affect memory.  Describe how configuration options affect memory usage.  Describe the effect on the I/O subsystem when memory runs low.  List at least two memory myths and why they are not true. Recommended Reading  SQL Server 7.0 Performance Tuning Technical Reference, Microsoft Press  Windows 2000 Resource Kit companion CD-ROM documentation. Chapter 15: Overview of Performance Monitoring  Inside Microsoft Windows 2000, Third Edition, David A. Solomon and Mark E. Russinovich  Windows 2000 Server Operations Guide, Storage, File Systems, and Printing; Chapters: Evaluating Memory and Cache Usage  Advanced Windows, 4th Edition, Jeffrey Richter, Microsoft Press Related Web Sites  http://ntperformance/ Memory Definitions Memory Definitions Before we look at how SQL Server uses and manages its memory, we need to ensure a full understanding of the more common memory related terms. The following definitions will help you understand how SQL Server interacts with the operating system when allocating and using memory. Virtual Address Space A set of memory addresses that are mapped to physical memory addresses by the system. In a 32-bit operation system, there is normally a linear array of 2^32 addresses representing 4,294,967,269 byte addresses. Physical Memory A series of physical locations, with unique addresses, that can be used to store instructions or data. AWE – Address Windowing Extensions A 32-bit process is normally limited to addressing 2 gigabytes (GB) of memory, or 3 GB if the system was booted using the /3G boot switch even if there is more physical memory available. By leveraging the Address Windowing Extensions API, an application can create a fixed-size window into the additional physical memory. This allows a process to access any portion of the physical memory by mapping it into the applications window. When used in combination with Intel’s Physical Addressing Extensions (PAE) on Windows 2000, an AWE enabled application can support up to 64 GB of memory Reserved Memory Pages in a processes address space are free, reserved or committed. Reserving memory address space is a way to reserve a range of virtual addresses for later use. If you attempt to access a reserved address that has not yet been committed (backed by memory or disk) you will cause an access violation. Committed Memory Committed pages are those pages that when accessed in the end translate to pages in memory. Those pages may however have to be faulted in from a page file or memory mapped file. Backing Store Backing store is the physical representation of a memory address. Page Fault (Soft/Hard) A reference to an invalid page (a page that is not in your working set) is referred to as a page fault. Assuming the page reference does not result in an access violation, a page fault can be either hard or soft. A hard page fault results in a read from disk, either a page file or memory-mapped file. A soft page fault is resolved from one of the modified, standby, free or zero page transition lists. Paging is represented by a number of counters including page faults/sec, page input/sec and page output/sec. Page faults/sec include soft and hard page faults where as the page input/output counters represent hard page faults. Unfortunately, all of these counters include file system cache activity. For more information, see also…Inside Windows 2000,Third Edition, pp. 443-451. Private Bytes Private non-shared committed address space Working Set The subset of processes virtual pages that is resident in physical memory. For more information, see also… Inside Windows 2000,Third Edition, p. 455. System Working Set Like a process, the system has a working set. Five different types of pages represent the system’s working set: system cache; paged pool; pageable code and data in the kernel; page-able code and data in device drivers; and system mapped views. The system working set is represented by the counter Memory: cache bytes. System working set paging activity can be viewed by monitoring the Memory: Cache Faults/sec counter. For more information, see also… Inside Windows 2000,Third Edition, p. 463. System Cache The Windows 2000 cache manager provides data caching for both local and network file system drivers. By caching virtual blocks, the cache manager can reduce disk I/O and provide intelligent read ahead. Represented by Memory:Cache Resident bytes. For more information, see also… Inside Windows 2000,Third Edition, pp. 654-659. Non Paged Pool Range of addresses guaranteed to be resident in physical memory. As such, non-paged pool can be accessed at any time without incurring a page fault. Because device drivers operate at DPC/dispatch level (covered in lesson 2), and page faults are not allowed at this level or above, most device drivers use non-paged pool to assure that they do not incur a page fault. Represented by Memory: Pool Nonpaged Bytes, typically between 3-30 megabytes (MB) in size. Note The pool is, in effect, a common area of memory shared by all processes. One of the most common uses of non-paged pool is the storage of object handles. For more information regarding “maximums,” see also… Inside Windows 2000,Third Edition, pp. 403-404 Paged Pool Range of address that can be paged in and out of physical memory. Typically used by drivers who need memory but do not need to access that memory from DPC/dispatch of above interrupt level. Represented by Memory: Pool Paged Bytes and Memory:Pool Paged Resident Bytes. Typically between 10-30MB + size of Registry. For more information regarding “limits,” see also… Inside Windows 2000,Third Edition, pp. 403-404. Stack Each thread has two stacks, one for kernel mode and one for user mode. A stack is an area of memory in which program procedure or function call addresses and parameters are temporarily stored. In Process To run in the same address space. In-process servers are loaded in the client’s address space because they are implemented as DLLs. The main advantage of running in-process is that the system usually does not need to perform a context switch. The disadvantage to running in-process is that DLL has access to the process address space and can potentially cause problems. Out of Process To run outside the calling processes address space. OLEDB providers can run in-process or out of process. When running out of process, they run under the context of DLLHOST.EXE. Memory Leak To reserve or commit memory and unintentionally not release it when it is no longer being used. A process can leak resources such as process memory, pool memory, user and GDI objects, handles, threads, and so on. Memory Concepts (X86 Address Space) Per Process Address Space Every process has its own private virtual address space. For 32-bit processes, that address space is 4 GB, based on a 32-bit pointer. Each process’s virtual address space is split into user and system partitions based on the underlying operating system. The diagram included at the top represents the address partitioning for the 32-bit version of Windows 2000. Typically, the process address space is evenly divided into two 2-GB regions. Each process has access to 2 GB of the 4 GB address space. The upper 2 GB of address space is reserved for the system. The user address space is where application code, global variables, per-thread stacks, and DLL code would reside. The system address space is where the kernel, executive, HAL, boot drivers, page tables, pool, and system cache reside. For specific information regarding address space layout, refer to Inside Microsoft Windows 2000 Third Edition pages 417-428 by Microsoft Press. Access Modes Each virtual memory address is tagged as to what access mode the processor must be running in. System space can only be accessed while in kernel mode, while user space is accessible in user mode. This protects system space from being tampered with by user mode code. Shared System Space Although every process has its own private memory space, kernel mode code and drivers share system space. Windows 2000 does not provide any protection to private memory being use by components running in kernel mode. As such, it is very important to ensure components running in kernel mode are thoroughly tested. 3-GB Address Space 3-GB Address Space Although 2 GB of address space may seem like a large amount of memory, application such as SQL Server could leverage more memory if it were available. The boot.ini option /3GB was created for those cases where systems actually support greater than 2 GB of physical memory and an application can make use of it This capability allows memory intensive applications running on Windows 2000 Advanced Server to use up to 50 percent more virtual memory on Intel-based computers. Application memory tuning provides more of the computer's virtual memory to applications by providing less virtual memory to the operating system. Although a system having less than 2 GB of physical memory can be booted using the /3G switch, in most cases this is ill-advised. If you restart with the 3 GB switch, also known as 4-Gig Tuning, the amount of non-paged pool is reduced to 128 MB from 256 MB. For a process to access 3 GB of address space, the executable image must have been linked with the /LARGEADDRESSAWARE flag or modified using Imagecfg.exe. It should be pointed out that SQL Server was linked using the /LAREGEADDRESSAWARE flag and can leverage 3 GB when enabled. Note Even though you can boot Windows 2000 Professional or Windows 2000 Server with the /3GB boot option, users processes are still limited to 2 GB of address space even if the IMAGE_FILE_LARGE_ADDRESS_AWARE flag is set in the image. The only thing accomplished by using the /3G option on these system is the reduction in the amount of address space available to the system (ISW2K Pg. 418). Important If you use /3GB in conjunction with AWE/PAE you are limited to 16 GB of memory. For more information, see the following Knowledge Base articles: Q171793 Information on Application Use of 4GT RAM Tuning Q126402 PagedPoolSize and NonPagedPoolSize Values in Windows NT Q247904 How to Configure Paged Pool and System PTE Memory Areas Q274598 W2K Does Not Enable Complete Memory Dumps Between 2 & 4 GB AWE Memory Layout AWE Memory Usually, the operation system is limited to 4 GB of physical memory. However, by leveraging PAE, Windows 2000 Advanced Server can support up to 8 GB of memory, and Data Center 64 GB of memory. However, as stated previously, each 32-bit process normally has access to only 2 GB of address space, or 3 GB if the system was booted with the /3-GB option. To allow processes to allocate more physical memory than can be represented in the 2GB of address space, Microsoft created the Address Windows Extensions (AWE). These extensions allow for the allocation and use of up to the amount of physical memory supported by the operating system. By leveraging the Address Windowing Extensions API, an application can create a fixed-size window into the physical memory. This allows a process to access any portion of the physical memory by mapping regions of physical memory in and out of the applications window. The allocation and use of AWE memory is accomplished by  Creating a window via VirtualAlloc using the MEM_PHYSICAL option  Allocating the physical pages through AllocateUserPhysicalPages  Mapping the RAM pages to the window using MapUserPhysicalPages Note SQL Server 7.0 supports a feature called extended memory in Windows NT® 4 Enterprise Edition by using a PSE36 driver. Currently there are no PSE drivers for Windows 2000. The preferred method of accessing extended memory is via the Physical Addressing Extensions using AWE. The AWE mapping feature is much more efficient than the older process of coping buffers from extended memory into the process address space. Unfortunately, SQL Server 7.0 cannot leverage PAE/AWE. Because there are currently no PSE36 drivers for Windows 2000 this means SQL Server 7.0 cannot support more than 3GB of memory on Windows 2000. Refer to KB article Q278466. AWE restrictions  The process must have Lock Pages In Memory user rights to use AWE Important It is important that you use Enterprise Manager or DMO to change the service account. Enterprise Manager and DMO will grant all of the privileges and Registry and file permissions needed for SQL Server. The Service Control Panel does NOT grant all the rights or permissions needed to run SQL Server.  Pages are not shareable or page-able  Page protection is limited to read/write  The same physical page cannot be mapped into two separate AWE regions, even within the same process.  The use of AWE/PAE in conjunction with /3GB will limit the maximum amount of supported memory to between 12-16 GB of memory.  Task manager does not show the correct amount of memory allocated to AWE-enabled applications. You must use Memory Manager: Total Server Memory. It should, however, be noted that this only shows memory in use by the buffer pool.  Machines that have PAE enabled will not dump user mode memory. If an event occurs in User Mode Memory that causes a blue screen and root cause determination is absolutely necessary, the machine must be booted with the /NOPAE switch, and with /MAXMEM set to a number appropriate for transferring dump files.  With AWE enabled, SQL Server will, by default, allocate almost all memory during startup, leaving 256 MB or less free. This memory is locked and cannot be paged out. Consuming all available memory may prevent other applications or SQL Server instances from starting. Note PAE is not required to leverage AWE. However, if you have more than 4GB of physical memory you will not be able to access it unless you enable PAE. Caution It is highly recommended that you use the “max server memory” option in combination with “awe enabled” to ensure some memory headroom exists for other applications or instances of SQL Server, because AWE memory cannot be shared or paged. For more information, see the following Knowledge Base articles: Q268363 Intel Physical Addressing Extensions (PAE) in Windows 2000 Q241046 Cannot Create a dump File on Computers with over 4 GB RAM Q255600 Windows 2000 utilities do not display physical memory above 4GB Q274750 How to configure SQL Server memory more than 2 GB (Idea) Q266251 Memory dump stalls when PAE option is enabled (Idea) Tip The KB will return more hits if you query on PAE rather than AWE. Virtual Address Space Mapping Virtual Address Space Mapping By default Windows 2000 (on an X86 platform) uses a two-level (three-level when PAE is enabled) page table structure to translate virtual addresses to physical addresses. Each 32-bit address has three components, as shown below. When a process accesses a virtual address the system must first locate the Page Directory for the current process via register CR3 (X86). The first 10 bits of the virtual address act as an index into the Page Directory. The Page Directory Entry then points to the Page Frame Number (PFN) of the appropriate Page Table. The next 10 bits of the virtual address act as an index into the Page Table to locate the appropriate page. If the page is valid, the PTE contains the PFN of the actual page in memory. If the page is not valid, the memory management fault handler locates the page and attempts to make it valid. The final 12 bits act as a byte offset into the page. Note This multi-step process is expensive. This is why systems have translation look aside buffers (TLB) to speed up the process. One of the reasons context switching is so expensive is the translation buffers must be dumped. Thus, the first few lookups are very expensive. Refer to ISW2K pages 439-440. Core System Memory Related Counters Core System Memory Related Counters When evaluating memory performance you are looking at a wide variety of counters. The counters listed here are a few of the core counters that give you quick overall view of the state of memory. The two key counters are Available Bytes and Committed Bytes. If Committed Bytes exceeds the amount of physical memory in the system, you can be assured that there is some level of hard page fault activity happening. The goal of a well-tuned system is to have as little hard paging as possible. If Available Bytes is below 5 MB, you should investigate why. If Available Bytes is below 4 MB, the Working Set Manager will start to aggressively trim the working sets of process including the system cache.  Committed Bytes Total memory, including physical and page file currently committed  Commit Limit • Physical memory + page file size • Represents the total amount of memory that can be committed without expanding the page file. (Assuming page file is allowed to grow)  Available Bytes Total physical memory currently available Note Available Bytes is a key indicator of the amount of memory pressure. Windows 2000 will attempt to keep this above approximately 4 MB by aggressively trimming the working sets including system cache. If this value is constantly between 3-4 MB, it is cause for investigation. One counter you might expect would be for total physical memory. Unfortunately, there is no specific counter for total physical memory. There are however many other ways to determine total physical memory. One of the most common is by viewing the Performance tab of Task Manager. Page File Usage The only counters that show current page file space usage are Page File:% Usage and Page File:% Peak Usage. These two counters will give you an indication of the amount of space currently used in the page file. Memory Performance Memory Counters There are a number of counters that you need to investigate when evaluating memory performance. As stated previously, no single counter provides the entire picture. You will need to consider many different counters to begin to understand the true state of memory. Note The counters listed are a subset of the counters you should capture. *Available Bytes In general, it is desirable to see Available Bytes above 5 MB. SQL Servers goal on Intel platforms, running Windows NT, is to assure there is approximately 5+ MB of free memory. After Available Bytes reaches 4 MB, the Working Set Manager will start to aggressively trim the working sets of process and, finally, the system cache. This is not to say that working set trimming does not happen before 4 MB, but it does become more pronounced as the number of available bytes decreases below 4 MB. Page Faults/sec Page Faults/sec represents the total number of hard and soft page faults. This value includes the System Working Set as well. Keep this in mind when evaluating the amount of paging activity in the system. Because this counter includes paging associated with the System Cache, a server acting as a file server may have a much higher value than a dedicated SQL Server may have. The System Working Set is covered in depth on the next slide. Because Page Faults/sec includes soft faults, this counter is not as useful as Pages/sec, which represents hard page faults. Because of the associated I/O, hard page faults tend to be much more expensive. *Pages/sec Pages/sec represent the number of pages written/read from disk because of hard page faults. It is the sum of Memory: Pages Input/sec and Memory: Pages Output/sec. Because it is counted in numbers of pages, it can be compared to other counts of pages, such as Memory: Page Faults/sec, without conversion. On a well-tuned system, this value should be consistently low. In and of itself, a high value for this counter does not necessarily indicate a problem. You will need to isolate the paging activity to determine if it is associated with in-paging, out-paging, memory mapped file activity or system cache. Any one of these activities will contribute to this counter. Note Paging in and of itself is not necessarily a bad thing. Paging is only “bad” when a critical process must wait for it’s pages to be in-paged, or when the amount of read/write paging is causing excessive kernel time or disk I/O, thus interfering with normal user mode processing. Tip (Memory: Pages/sec) / (PhysicalDisk: Disk Bytes/sec * 4096) yields the approximate percentage of paging to total disk I/O. Note, this is only relevant on X86 platforms with a 4 KB page size. Page Reads/sec (Hard Page Fault) Page Reads/sec is the number of times the disk was accessed to resolve hard page faults. It includes reads to satisfy faults in the file system cache (usually requested by applications) and in non-cached memory mapped files. This counter counts numbers of read operations, without regard to the numbers of pages retrieved by each operation. This counter displays the difference between the values observed in the last two samples, divided by the duration of the sample interval. Page Writes/sec (Hard Page Fault) Page Writes/sec is the number of times pages were written to disk to free up space in physical memory. Pages are written to disk only if they are changed while in physical memory, so they are likely to hold data, not code. This counter counts write operations, without regard to the number of pages written in each operation. This counter displays the difference between the values observed in the last two samples, divided by the duration of the sample interval. *Pages Input/sec (Hard Page Fault) Pages Input/sec is the number of pages read from disk to resolve hard page faults. It includes pages retrieved to satisfy faults in the file system cache and in non-cached memory mapped files. This counter counts numbers of pages, and can be compared to other counts of pages, such as Memory:Page Faults/sec, without conversion. This counter displays the difference between the values observed in the last two samples, divided by the duration of the sample interval. This is one of the key counters to monitor for potential performance complaints. Because a process must wait for a read page fault this counter, read page faults have a direct impact on the perceived performance of a process. *Pages Output/sec (Hard Page Fault) Pages Output/sec is the number of pages written to disk to free up space in physical memory. Pages are written back to disk only if they are changed in physical memory, so they are likely to hold data, not code. A high rate of pages output might indicate a memory shortage. Windows NT writes more pages back to disk to free up space when physical memory is in short supply. This counter counts numbers of pages, and can be compared to other counts of pages, without conversion. This counter displays the difference between the values observed in the last two samples, divided by the duration of the sample interval. Like Pages Input/sec, this is one of the key counters to monitor. Processes will generally not notice write page faults unless the disk I/O begins to interfere with normal data operations. Demand Zero Faults/Sec (Soft Page Fault) Demand Zero Faults/sec is the number of page faults that require a zeroed page to satisfy the fault. Zeroed pages, pages emptied of previously stored data and filled with zeros, are a security feature of Windows NT. Windows NT maintains a list of zeroed pages to accelerate this process. This counter counts numbers of faults, without regard to the numbers of pages retrieved to satisfy the fault. This counter displays the difference between the values observed in the last two samples, divided by the duration of the sample interval. Transition Faults/Sec (Soft Page Fault) Transition Faults/sec is the number of page faults resolved by recovering pages that were on the modified page list, on the standby list, or being written to disk at the time of the page fault. The pages were recovered without additional disk activity. Transition faults are counted in numbers of faults, without regard for the number of pages faulted in each operation. This counter displays the difference between the values observed in the last two samples, divided by the duration of the sample interval. System Working Set System Working Set Like processes, the system page-able code and data are managed by a working set. For the purpose of this course, that working set is referred to as the System Working Set. This is done to differentiate the system cache portion of the working set from the entire working set. There are five different types of pages that make up the System Working Set. They are: system cache; paged pool; page-able code and data in ntoskrnl.exe; page-able code, and data in device drivers and system-mapped views. Unfortunately, some of the counters that appear to represent the system cache actually represent the entire system working set. Where noted system cache actually represents the entire system working set. Note The counters listed are a subset of the counters you should capture. *Memory: Cache Bytes (Represents Total System Working Set) Represents the total size of the System Working Set including: system cache; paged pool; pageable code and data in ntoskrnl.exe; pageable code and data in device drivers; and system-mapped views. Cache Bytes is the sum of the following counters: System Cache Resident Bytes, System Driver Resident Bytes, System Code Resident Bytes, and Pool Paged Resident Bytes. Memory: System Cache Resident Bytes (System Cache) System Cache Resident Bytes is the number of bytes from the file system cache that are resident in physical memory. Windows 2000 Cache Manager works with the memory manager to provide virtual block stream and file data caching. For more information, see also…Inside Windows 2000,Third Edition, pp. 645-650 and p. 656. Memory: Pool Paged Resident Bytes Represents the physical memory consumed by Paged Pool. This counter should NOT be monitored by itself. You must also monitor Memory: Paged Pool. A leak in the pool may not show up in Pool paged Resident Bytes. Memory: System Driver Resident Bytes Represents the physical memory consumed by driver code and data. System Driver Resident Bytes and System Driver Total Bytes do not include code that must remain in physical memory and cannot be written to disk. Memory: System Code Resident Bytes Represents the physical memory consumed by page-able system code. System Code Resident Bytes and System Code Total Bytes do not include code that must remain in physical memory and cannot be written to disk. Working Set Performance Counter You can measure the number of page faults in the System Working Set by monitoring the Memory: Cache Faults/sec counter. Contrary to the “Explain” shown in System Monitor, this counter measures the total amount of page faults/sec in the System Working Set, not only the System Cache. You cannot measure the performance of the System Cache using this counter alone. For more information, see also…Inside Windows 2000,Third Edition, p. 656. Note You will find that in general the working set manager will usually trim the working sets of normal processes prior to trimming the system working set. System Cache System Cache The Windows 2000 cache manager provides a write-back cache with lazy writing and intelligent read-ahead. Files are not written to disk immediately but differed until the cache manager calls the memory manager to flush the cache. This helps to reduce the total number of I/Os. Once per second, the lazy writer thread queues one-eighth of the dirty pages in the system cache to be written to disk. If this is not sufficient to meet the needs, the lazy writer will calculate a larger value. If the dirty page threshold is exceeded prior to lazy writer waking, the cache manager will wake the lazy writer. Important It should be pointed out that mapped files or files opened with FILE_FLAG_NO_BUFFERING, do not participate in the System Cache. For more information regarding mapped views, see also…Inside Windows 2000,Third Edition, p. 669. For those applications that would like to leverage system cache but cannot tolerate write delays, the cache manager supports write through operations via the FILE_FLAG_WRITE_THROUGH. On the other hand, an application can disable lazy writing by using the FILE_ATTRIBUTE_TEMPORARY. If this flag is enabled, the lazy writer will not write the pages to disk unless there is a shortage of memory or the file is closed. Important Microsoft SQL Server uses both FILE_FLAG_NO_BUFFERING and FILE_FLAG_WRITE_THROUGH Tip The file system cache is not represented by a static amount of memory. The system cache can and will grow. It is not unusual to see the system cache consume a large amount of memory. Like other working sets, it is trimmed under pressure but is generally the last thing to be trimmed. System Cache Performance Counters The counters listed are a subset of the counters you should capture. Cache: Data Flushes/sec Data Flushes/sec is the rate at which the file system cache has flushed its contents to disk as the result of a request to flush or to satisfy a write-through file write request. More than one page can be transferred on each flush operation. Cache: Data Flush Pages/sec Data Flush Pages/sec is the number of pages the file system cache has flushed to disk as a result of a request to flush or to satisfy a write-through file write request. Cache: Lazy Write Flushes/sec Represents the rate of lazy writes to flush the system cache per second. More than one page can be transferred per second. Cache: Lazy Write Pages/sec Lazy Write Pages/sec is the rate at which the Lazy Writer thread has written to disk. Note When looking at Memory:Cache Faults/sec, you can remove cache write activity by subtracting (Cache: Data Flush Pages/sec + Cache: Lazy Write Pages/sec). This will give you a better idea of how much other page faulting activity is associated with the other components of the System Working Set. However, you should note that there is no easy way to remove the page faults associated with file cache read activity. For more information, see the following Knowledge Base articles: Q145952 (NT4) Event ID 26 Appears If Large File Transfer Fails Q163401 (NT4) How to Disable Network Redirector File Caching Q181073 (SQL 6.5) DUMP May Cause Access Violation on Win2000 System Pool System Pool As documented earlier, there are two types of shared pool memory: non-paged pool and paged pool. Like private memory, pool memory is susceptible to a leak. Nonpaged Pool Miscellaneous kernel code and structures, and drivers that need working memory while at or above DPC/dispatch level use non-paged pool. The primary counter for non-paged pool is Memory: Pool Nonpaged Bytes. This counter will usually between 3 and 30 MB. Paged Pool Drivers that do not need to access memory above DPC/Dispatch level are one of the primary users of paged pool, however any process can use paged pool by leveraging the ExAllocatePool calls. Paged pool also contains the Registry and file and printing structures. The primary counters for monitoring paged pool is Memory: Pool Paged Bytes. This counter will usually be between 10-30MB plus the size of the Registry. To determine how much of paged pool is currently resident in physical memory, monitor Memory: Pool Paged Resident Bytes. Note The paged and non-paged pools are two of the components of the System Working Set. If a suspected leak is clearly visible in the overview and not associated with a process, then it is most likely a pool leak. If the leak is not associated with SQL Server handles, OLDEB providers, XPROCS or SP_OA calls then most likely this call should be pushed to the Windows NT group. For more information, see the following Knowledge Base articles: Q265028 (MS) Pool Tags Q258793 (MS) How to Find Memory Leaks by Using Pool Bitmap Analysis Q115280 (MS) Finding Windows NT Kernel Mode Memory Leaks Q177415 (MS) How to Use Poolmon to Troubleshoot Kernel Mode Memory Leaks Q126402 PagedPoolSize and NonPagedPoolSize Values in Windows NT Q247904 How to Configure Paged Pool and System PTE Memory Areas Tip To isolate pool leaks you will need to isolate all drivers and third-party processes. This should be done by disabling each service or driver one at a time and monitoring the effect. You can also monitor paged and non-paged pool through poolmon. If pool tagging has been enabled via GFLAGS, you may be able to associate the leak to a particular tag. If you suspect a particular tag, you should involve the platform support group. Process Memory Counters Process _Total Limitations Although the rollup of _Total for Process: Private Bytes, Virtual Bytes, Handles and Threads, represent the key resources being used across all processes, they can be misleading when evaluating a memory leak. This is because a leak in one process may be masked by a decrease in another process. Note The counters listed are a subset of the counters you should capture. Tip When analyzing memory leaks, it is often easier to a build either a separate chart or report showing only one or two key counters for all process. The primary counter used for leak analysis is private bytes, but processes can leak handles and threads just as easily. After a suspect process is located, build a separate chart that includes all the counters for that process. Individual Process Counters When analyzing individual process for memory leaks you should include the counters listed.  Process: % Processor Time  Process: Working Set (includes shared pages)  Process: Virtual Bytes  Process: Private Bytes  Process: Page Faults/sec  Process: Handle Count  Process: Thread Count  Process: Pool Paged Bytes  Process: Pool Nonpaged Bytes Tip WINLOGON, SVCHOST, services, or SPOOLSV are referred to as HELPER processes. They provide core functionality for many operations and as such are often extended by the addition of third-party DLLs. Tlist –s may help identify what services are running under a particular helper. Helper Processes Helper Processes Winlogon, Services, and Spoolsv and Svchost are examples of what are referred to as HELPER processes. They provide core functionality for many operations and, as such, are often extended by the addition of third-party DLLs. Running every service in its own process can waste system resources. Consequently, some services run in their own processes while others share a process with other services. One problem with sharing a process is that a bug in one service may cause the entire process to fail. The resource kit tool, Tlist when used with the –s qualifier can help you identify what services are running in what processes. WINLOGON Used to support GINAs. SPOOLSV SPOOLSV is responsible for printing. You will need to investigate all added printing functionality. Services Service is responsible for system services. Svchost.exe Svchost.exe is a generic host process name for services that are run from dynamic-link libraries (DLLs). There can be multiple instances of Svchost.exe running at the same time. Each Svchost.exe session can contain a grouping of services, so that separate services can be run depending on how and where Svchost.exe is started. This allows for better control and debugging. The Effect of Memory on Other Components Memory Drives Overall Performance Processor, cache, bus speeds, I/O, all of these resources play a roll in overall perceived performance. Without minimizing the impact of these components, it is important to point out that a shortage of memory can often have a larger perceived impact on performance than a shortage of some other resource. On the other hand, an abundance of memory can often be leveraged to mask bottlenecks. For instance, in certain environments, file system cache can significantly reduce the amount of disk I/O, potentially masking a slow I/O subsystem. Effect on I/O I/O can be driven by a number of memory considerations. Page read/faults will cause a read I/O when a page is not in memory. If the modified page list becomes too long the Modified Page Writer and Mapped Page Writer will need to start flushing pages causing disk writes. However, the one event that can have the greatest impact is running low on available memory. In this case, all of the above events will become more pronounced and have a larger impact on disk activity. Effect on CPU The most effective use of a processor from a process perspective is to spend as much time possible executing user mode code. Kernel mode represents processor time associated with doing work, directly or indirectly, on behalf of a thread. This includes items such as synchronization, scheduling, I/O, memory management, and so on. Although this work is essential, it takes processor cycles and the cost, in cycles, to transition between user and kernel mode is expensive. Because all memory management and I/O functions must be done in kernel mode, it follows that the fewer the memory resources the more cycles are going to be spent managing those resources. A direct result of low memory is that the Working Set Manager, Modified Page Writer and Mapped Page Writer will have to use more cycles attempting to free memory. Analyzing Memory Look for Trends and Trend Relationships Troubleshooting performance is about analyzing trends and trend relationships. Establishing that some event happened is not enough. You must establish the effect of the event. For example, you note that paging activity is high at the same time that SQL Server becomes slow. These two individual facts may or may not be related. If the paging is not associated with SQL Servers working set, or the disks SQL is using there may be little or no cause/affect relationship. Look at Physical Memory First The first item to look at is physical memory. You need to know how much physical and page file space the system has to work with. You should then evaluate how much available memory there is. Just because the system has free memory does not mean that there is not any memory pressure. Available Bytes in combination with Pages Input/sec and Pages Output/sec can be a good indicator as to the amount of pressure. The goal in a perfect world is to have as little hard paging activity as possible with available memory greater than 5 MB. This is not to say that paging is bad. On the contrary, paging is a very effective way to manage a limited resource. Again, we are looking for trends that we can use to establish relationships. After evaluating physical memory, you should be able to answer the following questions:  How much physical memory do I have?  What is the commit limit?  Of that physical memory, how much has the operating system committed?  Is the operating system over committing physical memory?  What was the peak commit charge?  How much available physical memory is there?  What is the trend associated with committed and available? Review System Cache and Pool Contribution After you understand the individual process memory usage, you need to evaluate the System Cache and Pool usage. These can and often represent a significant portion of physical memory. Be aware that System Cache can grow significantly on a file server. This is usually normal. One thing to consider is that the file system cache tends to be the last thing trimmed when memory becomes low. If you see abrupt decreases in System Cache Resident Bytes when Available Bytes is below 5 MB you can be assured that the system is experiencing excessive memory pressure. Paged and non-paged pool size is also important to consider. An ever-increasing pool should be an indicator for further research. Non-paged pool growth is usually a driver issue, while paged pool could be driver-related or process-related. If paged pool is steadily growing, you should investigate each process to see if there is a specific process relationship. If not you will have to use tools such as poolmon to investigate further. Review Process Memory Usage After you understand the physical memory limitations and cache and pool contribution you need to determine what components or processes are creating the pressure on memory, if any. Be careful if you opt to chart the _Total Private Byte’s rollup for all processes. This value can be misleading in that it includes shared pages and can therefore exceed the actual amount of memory being used by the processes. The _Total rollup can also mask processes that are leaking memory because other processes may be freeing memory thus creating a balance between leaked and freed memory. Identify processes that expand their working set over time for further analysis. Also, review handles and threads because both use resources and potentially can be mismanaged. After evaluating the process resource usage, you should be able to answer the following:  Are any of the processes increasing their private bytes over time?  Are any processes growing their working set over time?  Are any processes increasing the number of threads or handles over time?  Are any processes increasing their use of pool over time?  Is there a direct relationship between the above named resources and total committed memory or available memory?  If there is a relationship, is this normal behavior for the process in question? For example, SQL does not commit ‘min memory’ on startup; these pages are faulted in into the working set as needed. This is not necessarily an indication of a memory leak.  If there is clearly a leak in the overview and is not identifiable in the process counters it is most likely in the pool.  If the leak in pool is not associated with SQL Server handles, then more often than not, it is not a SQL Server issue. There is however the possibility that the leak could be associated with third party XPROCS, SP_OA* calls or OLDB providers. Review Paging Activity and Its Impact on CPU and I/O As stated earlier, paging is not in and of itself a bad thing. When starting a process the system faults in the pages of an executable, as they are needed. This is preferable to loading the entire image at startup. The same can be said for memory mapped files and file system cache. All of these features leverage the ability of the system to fault in pages as needed The greatest impact of paging on a process is when the process must wait for an in-page fault or when page file activity represents a significant portion of the disk activity on the disk the application is actively using. After evaluating page fault activity, you should be able to answer the following questions:  What is the relationship between PageFaults/sec and Page Input/sec + Page Output/Sec?  What is the relationship if any between hard page faults and available memory?  Does paging activity represent a significant portion of processor or I/O resource usage? Don’t Prematurely Jump to Any Conclusions Analyzing memory pressure takes time and patience. An individual counter in and of it self means little. It is only when you start to explore relationships between cause and effect that you can begin to understand the impact of a particular counter. The key thoughts to remember are:  With the exception of a swap (when the entire process’s working set has been swapped out/in), hard page faults to resolve reads, are the most expensive in terms its effect on a processes perceived performance.  In general, page writes associated with page faults do not directly affect a process’s perceived performance, unless that process is waiting on a free page to be made available. Page file activity can become a problem if that activity competes for a significant percentage of the disk throughput in a heavy I/O orientated environment. That assumes of course that the page file resides on the same disk the application is using. Lab 3.1 System Memory Lab 3.1 Analyzing System Memory Using System Monitor Exercise 1 – Troubleshooting the Cardinal1.log File Students will evaluate an existing System Monitor log and determine if there is a problem and what the problem is. Students should be able to isolate the issue as a memory problem, locate the offending process, and determine whether or not this is a pool issue. Exercise 2 – Leakyapp Behavior Students will start leaky app and monitor memory, page file and cache counters to better understand the dynamics of these counters. Exercise 3 – Process Swap Due To Minimizing of the Cmd Window Students will start SQL from command line while viewing SQL process performance counters. Students will then minimize the window and note the effect on the working set. Overview What You Will Learn After completing this lab, you will be able to:  Use some of the basic functions within System Monitor.  Troubleshoot one or more common performance scenarios. Before You Begin Prerequisites To complete this lab, you need the following:  Windows 2000  SQL Server 2000  Lab Files Provided  LeakyApp.exe (Resource Kit) Estimated time to complete this lab: 45 minutes Exercise 1 Troubleshooting the Cardinal1.log File In this exercise, you will analyze a log file from an actual system that was having performance problems. Like an actual support engineer, you will not have much information from which to draw conclusions. The customer has sent you this log file and it is up to you to find the cause of the problem. However, unlike the real world, you have an instructor available to give you hints should you become stuck. Goal Review the Cardinal1.log file (this file is from Windows NT 4.0 Performance Monitor, which Windows 2000 can read). Chart the log file and begin to investigate the counters to determine what is causing the performance problems. Your goal should be to isolate the problem to a major area such as pool, virtual address space etc, and begin to isolate the problem to a specific process or thread. This lab requires access to the log file Cardinal1.log located in C:\LABS\M3\LAB1\EX1  To analyze the log file 1. Using the Performance MMC, select the System Monitor snap-in, and click the View Log File Data button (icon looks like a disk). 2. Under Files of type, choose PERFMON Log Files (*.log) 3. Navigate to the folder containing Cardinal1.log file and open it. 4. Begin examining counters to find what might be causing the performance problems. When examining some of these counters, you may notice that some of them go off the top of the chart. It may be necessary to adjust the scale on these. This can be done by right-clicking the rightmost pane and selecting Properties. Select the Data tab. Select the counter that you wish to modify. Under the Scale option, change the scale value, which makes the counter data visible on the chart. You may need to experiment with different scale values before finding the ideal value. Also, it may sometimes be beneficial to adjust the vertical scale for the entire chart. Selecting the Graph tab on the Properties page can do this. In the Vertical scale area, adjust the Maximum and Minimum values to best fit the data on the chart. Lab 3.1, Exercise 1: Results Exercise 2 LeakyApp Behavior In this lab, you will have an opportunity to work with a partner to monitor a live system, which is suffering from a simulated memory leak. Goal During this lab, your goal is to observe the system behavior when memory starts to become a limited resource. Specifically you will want to monitor committed memory, available memory, the system working set including the file system cache and each processes working set. At the end of the lab, you should be able to provide an answer to the listed questions.  To monitor a live system with a memory leak 1. Choose one of the two systems as a victim on which to run the leakyapp.exe program. It is recommended that you boot using the \MAXMEM=128 option so that this lab goes a little faster. You and your partner should decide which server will play the role of the problematic server and which server is to be used for monitoring purposes. 2. On the problematic server, start the leakyapp program. 3. On the monitoring system, create a counter that logs all necessary counters need to troubleshoot a memory problem. This should include physicaldisk counters if you think paging is a problem. Because it is likely that you will only need to capture less than five minutes of activity, the suggested interval for capturing is five seconds. 4. After the counters have been started, start the leaky application program 5. Click Start Leaking. The button will now change to Stop Leaking, which indicates that the system is now leaking memory. 6. After leakyapp shows the page file is 50 percent full, click Stop leaking. Note that the process has not given back its memory, yet. After approximately one minute, exit. Lab 3.1, Exercise 2: Questions After analyzing the counter logs you should be able to answer the following: 1. Under which system memory counter does the leak show up clearly? Memory:Committed Bytes 2. What process counter looked very similar to the overall system counter that showed the leak? Private Bytes 3. Is the leak in Paged Pool, Non-paged pool, or elsewhere? Elsewhere 4. At what point did Windows 2000 start to aggressively trim the working sets of all user processes? <5 MB Free 5. Was the System Working Set trimmed before or after the working sets of other processes? After 6. What counter showed this? Memory:Cache Bytes 7. At what point was the File System Cache trimmed? After the first pass through all other working sets 8. What was the effect on all the processes working set when the application quit leaking? None 9. What was the effect on all the working sets when the application exited? Nothing, initially; but all grew fairly quickly based on use 10. When the server was running low on memory, which was Windows spending more time doing, paging to disk or in-paging? Paging to disk, initially; however, as other applications began to run, in-paging increased Exercise 3 Minimizing a Command Window In this exercise, you will have an opportunity to observe the behavior of Windows 2000 when a command window is minimized. Goal During this lab, your goal is to observe the behavior of Windows 2000 when a command window becomes minimized. Specifically, you will want to monitor private bytes, virtual bytes, and working set of SQL Server when the command window is minimized. At the end of the lab, you should be able to provide an answer to the listed questions.  To monitor a command window’s working set as the window is minimized 1. Using System Monitor, create a counter list that logs all necessary counters needed to troubleshoot a memory problem. Because it is likely that you will only need to capture less than five minutes of activity, the suggested capturing interval is five seconds. 2. After the counters have been started, start a Command Prompt window on the target system. 3. In the command window, start SQL Server from the command line. Example: SQL Servr.exe –c –sINSTANCE1 4. After SQL Server has successfully started, Minimize the Command Prompt window. 5. Wait approximately two minutes, and then Restore the window. 6. Wait approximately two minutes, and then stop the counter log. Lab 3.1, Exercise 3: Questions After analyzing the counter logs you should be able to answer the following questions: 1. What was the effect on SQL Servers private bytes, virtual bytes, and working set when the window was minimized? Private Bytes and Virtual Bytes remained the same, while Working Set went to 0 2. What was the effect on SQL Servers private bytes, virtual bytes, and working set when the window was restored? None; the Working Set did not grow until SQL accessed the pages and faulted them back in on an as-needed basis SQL Server Memory Overview SQL Server Memory Overview Now that you have a better understanding of how Windows 2000 manages memory resources, you can take a closer look at how SQL Server 2000 manages its memory. During the course of the lecture and labs you will have the opportunity to monitor SQL Servers use of memory under varying conditions using both System Monitor counters and SQL Server tools. SQL Server Memory Management Goals Because SQL Server has in-depth knowledge about the relationships between data and the pages they reside on, it is in a better position to judge when and what pages should be brought into memory, how many pages should be brought in at a time, and how long they should be resident. SQL Servers primary goals for management of its memory are the following:  Be able to dynamically adjust for varying amounts of available memory.  Be able to respond to outside memory pressure from other applications.  Be able to adjust memory dynamically for internal components. Items Covered  SQL Server Memory Definitions  SQL Server Memory Layout  SQL Server Memory Counters  Memory Configurations Options  Buffer Pool Performance and Counters  Set Aside Memory and Counters  General Troubleshooting Process  Memory Myths and Tips SQL Server Memory Definitions SQL Server Memory Definitions Pool A group of resources, objects, or logical components that can service a resource allocation request Cache The management of a pool or resource, the primary goal of which is to increase performance. Bpool The Bpool (Buffer Pool) is a single static class instance. The Bpool is made up of 8-KB buffers and can be used to handle data pages or external memory requests. There are three basic types or categories of committed memory in the Bpool.  Hashed Data Pages  Committed Buffers on the Free List  Buffers known by their owners (Refer to definition of Stolen) Consumer A consumer is a subsystem that uses the Bpool. A consumer can also be a provider to other consumers. There are five consumers and two advanced consumers who are responsible for the different categories of memory. The following list represents the consumers and a partial list of their categories  Connection – Responsible for PSS and ODS memory allocations  General – Resource structures, parse headers, lock manager objects  Utilities – Recovery, Log Manager  Optimizer – Query Optimization  Query Plan – Query Plan Storage Advanced Consumer Along with the five consumers, there are two advanced consumers. They are  Ccache – Procedure cache. Accepts plans from the Optimizer and Query Plan consumers. Is responsible for managing that memory and determines when to release the memory back to the Bpool.  Log Cache – Managed by the LogMgr, which uses the Utility consumer to coordinate memory requests with the Bpool. Reservation Requesting the future use of a resource. A reservation is a reasonable guarantee that the resource will be available in the future. Committed Producing the physical resource Allocation The act of providing the resource to a consumer Stolen The act of getting a buffer from the Bpool is referred to as stealing a buffer. If the buffer is stolen and hashed for a data page, it is referred to as, and counted as, a Hashed buffer, not a stolen buffer. Stolen buffers on the other hand are buffers used for things such as procedure cache and SRV_PROC structures. Target Target memory is the amount of memory SQL Server would like to maintain as committed memory. Target memory is based on the min and max server configuration values and current available memory as reported by the operating system. Actual target calculation is operating system specific. Memory to Leave (Set Aside) The virtual address space set aside to ensure there is sufficient address space for thread stacks, XPROCS, COM objects etc. Hashed Page A page in pool that represents a database page. SQL Server Memory Layout Virtual Address Space When SQL Server is started the minimum of physical ram or virtual address space supported by the OS is evaluated. There are many possible combinations of OS versions and memory configurations. For example: you could be running Microsoft Windows 2000 Advanced Server with 2 GB or possibly 4 GB of memory. To avoid page file use, the appropriate memory level is evaluated for each configuration. Important Utilities can inject a DLL into the process address space by using HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Windows\AppInit_DLLs When the USER32.dll library is mapped into the process space, so, too, are the DLLs listed in the Registry key. To determine what DLL’s are running in SQL Server address space you can use tlist.exe. You can also use a tool such as Depends from Microsoft or HandelEx from http://ww.sysinternals.com. Memory to Leave As stated earlier there are many possible configurations of physical memory and address space. It is possible for physical memory to be greater than virtual address space. To ensure that some virtual address space is always available for things such as thread stacks and external needs such as XPROCS, SQL Server reserves a small portion of virtual address space prior to determining the size of the buffer pool. This address space is referred to as Memory To Leave. Its size is based on the number of anticipated tread stacks and a default value for external needs referred to as cmbAddressSave. After reserving the buffer pool space, the Memory To Leave reservation is released. Buffer Pool Space During Startup, SQL Server must determine the maximum size of the buffer pool so that the BUF, BUFHASH and COMMIT BITMAP structures that are used to manage the Bpool can be created. It is important to understand that SQL Server does not take ‘max memory’ or existing memory pressure into consideration. The reserved address space of the buffer pool remains static for the life of SQL Server process. However, the committed space varies as necessary to provide dynamic scaling. Remember only the committed memory effects the overall memory usage on the machine. This ensures that the max memory configuration setting can be dynamically changed with minimal changes needed to the Bpool. The reserved space does not need to be adjusted and is maximized for the current machine configuration. Only the committed buffers need to be limited to maintain a specified max server memory (MB) setting. SQL Server Startup Pseudo Code The following pseudo code represents the process SQL Server goes through on startup. Warning This example does not represent a completely accurate portrayal of the steps SQL Server takes when initializing the buffer pool. Several details have been left out or glossed over. The intent of this example is to help you understand the general process, not the specific details.  Determine the size of cmbAddressSave (-g)  Determine Total Physical Memory  Determine Available Physical Memory  Determine Total Virtual Memory  Calculate MemToLeave maxworkterthreads * (stacksize=512 KB) + (cmbAddressSave = 256 MB)  Reserve MemToLeave and set PAGE_NOACCESS  Check for AWE, test to see if it makes sense to use it and log the results • Min(Available Memory, Max Server Memory) > Virtual Memory • Supports Read Scatter • SQL Server not started with -f • AWE Enabled via sp_configure • Enterprise Edition • Lock Pages In Memory user right enabled  Calculate Virtual Address Limit VA Limit = Min(Physical Memory, Virtual Memory – MemtoLeave)  Calculate the number of physical and virtual buffers that can be supported AWE Present Physical Buffers = (RAM / (PAGESIZE + Physical Overhead)) Virtual Buffers = (VA Limit / (PAGESIZE + Virtual Overhead)) AWE Not Present Physical Buffers = Virtual Buffers = VA Limit / (PAGESIZE + Physical Overhead + Virtual Overhead)  Make sure we have the minimum number of buffers Physical Buffers = Max(Physical Buffers, MIN_BUFFERS)  Allocate and commit the buffer management structures  Reserve the address space required to support the Bpool buffers  Release the MemToLeave SQL Server Startup Pseudo Code Example The following is an example based on the pseudo code represented on the previous page. This example is based on a machine with 384 MB of physical memory, not using AWE or /3GB. Note CmbAddressSave was changed between SQL Server 7.0 and SQL Server 2000. For SQL Server 7.0, cmbAddressSave was 128. Warning This example does not represent a completely accurate portrayal of the steps SQL Server takes when initializing the buffer pool. Several details have been left out or glossed over. The intent of this example is to help you understand the general process, not the specific details.  Determine the size of cmbAddressSave (No –g so 256MB)  Determine Total Physical Memory (384)  Determine Available Physical Memory (384)  Determine Total Virtual Memory (2GB)  Calculate MemToLeave maxworkterthreads * (stacksize=512 KB) + (cmbAddressSave = 256 MB) (255 * .5MB + 256MB = 384MB)  Reserve MemToLeave and set PAGE_NOACCESS  Check for AWE, test to see if it makes sense to use it and log the results (AWE Not Enabled)  Calculate Virtual Address Limit VA Limit = Min(Physical Memory, Virtual Memory – MemtoLeave) 384MB = Min(384MB, 2GB – 384MB)  Calculate the number of physical and virtual buffers that can be supported AWE Not Present 48664 (approx) = 384 MB / (8 KB + Overhead)  Make sure we have the minimum number of buffers Physical Buffers = Max(Physical Buffers, MIN_BUFFERS) 48664 = Max(48664,1024)  Allocate and commit the buffer management structures  Reserve the address space required to support the Bpool buffers  Release the MemToLeave Tip Trace Flag 1604 can be used to view memory allocations on startup. The cmbAddressSave can be adjusted using the –g XXX startup parameter. SQL Server Memory Counters SQL Server Memory Counters The two primary tools for monitoring and analyzing SQL Server memory usage are System Monitor and DBCC MEMORYSTATUS. For detailed information on DBCC MEMORYSTATUS refer to Q271624 Interpreting the Output of the DBCC MEMORYSTAUS Command. Important Represents SQL Server 2000 Counters. The counters presented are not the same as the counters for SQL Server 7.0. The SQL Server 7.0 counters are listed in the appendix. Determining Memory Usage for OS and BPOOL Memory Manager: Total Server memory (KB) - Represents all of SQL usage Buffer Manager: Total Pages - Represents total bpool usage To determine how much of Total Server Memory (KB) represents MemToLeave space; subtract Buffer Manager: Total Pages. The result can be verified against DBCC MEMORYSTATUS, specifically Dynamic Memory Manager: OS In Use. It should however be noted that this value only represents requests that went thru the bpool. Memory reserved outside of the bpool by components such as COM objects will not show up here, although they will count against SQL Server private byte count. Buffer Counts: Target (Buffer Manager: Target Pages) The size the buffer pool would like to be. If this value is larger than committed, the buffer pool is growing. Buffer Counts: Committed (Buffer Manager: Total Pages) The total number of buffers committed in the OS. This is the current size of the buffer pool. Buffer Counts: Min Free This is the number of pages that the buffer pool tries to keep on the free list. If the free list falls below this value, the buffer pool will attempt to populate it by discarding old pages from the data or procedure cache. Buffer Distribution: Free (Buffer Manager / Buffer Partition: Free Pages) This value represents the buffers currently not in use. These are available for data or may be requested by other components and mar
Contents Acknowledgments xiii About the Authors xv Part I Web Development Is a Blood Sport—Don't Wander onto the Field Without a Helmet 1 Chapter 1 Security Is a Server Issue and Other Myths 3 Reality Check 3 Security Is a Server Issue 5 Hackers Gain Control Through Insecure Applications 5 Programmers Can Harden Their Own Applications 6 Security Through Obscurity 7 Native Session Management Provides Plenty of Security 9 “My Application Isn’t Major Enough to Get Hacked” 9 The “Barbarians at the Gate” Syndrome 10 Wrapping It Up 10 Part II Is That Hole Really Big Enough to Drive a Truck Through? 11 Chapter 2 Error Handling 13 The Guestbook Application 13 Program Summary 13 Primary Code Listing 14 From the Library of Lee Bogdanoff CONTENTS vi Users Do the Darnedest Things . . . 15 I Wonder What Will Happen If I Do This? 15 Expecting the Unexpected 18 Building an Error-Handling Mechanism 19 Test for Unexpected Input 20 Decide What to Do with Erroneous Data 23 Make the System Mind-Numbingly Easy to Use 24 Wrapping It Up 26 Chapter 3 System Calls 27 Navigating the Dangerous Waters of exec(),system(), and Backticks 27 Using System Binaries with the SUID Bit and sudo 28 Using System Resources 29 Usingescapeshellcmd() and escapeshellarg() to Secure System Calls 30 escapeshellcmd() 30 escapeshellarg() 30 Create an API to Handle All System Calls 31 Why Not Just Escape the Arguments and Be Done? 31 Validate User Input 32 Patch the Guestbook Application 32 ThemoveFile()Function 32 Changes to the Application 34 Wrapping It Up 34 Part III What's In a Name? More Than You Expect 35 Chapter 4 Buffer Overflows and Variable Sanitation 37 What Is a Buffer, How Does It Overflow, and Why Should You Care? 37 Buffers, Stacks, Heaps, and Memory Allocation 39 Consequences of a Buffer Overflow 42 Memory Allocation and PHP 42 Pay Attention to the Latest Security Alerts 44 Prevent Buffer Overflows by Sanitizing Variables 46 Premise: Data Is Guilty Until Proven Innocent, Especially If It Comes from Outside the Application 46 Where Does Data Come From? 48 How to Sanitize Data to Prevent Buffer Overflows 48 Patch the Application 49 Verify That We’re Running the Latest Stable Versions 49 Check Variable Sanitation 51 Wrapping It Up 52 Chapter 5 Input Validation 53 New Feature: Allow Users to Sign Their Guestbook Comments 53 From the Library of Lee Bogdanoff CONTENTS vii The Problem: Users Who Give You More Than You Asked For 54 Spammers 55 Injection Attacks 55 Assumptions: You Know What Your Data Looks Like 55 Database Constraints 56 Logical Constraints 56 The Solution: Regular Expressions to Validate Input 57 Tainted Data 57 Regexes 101 58 That Greedy, Lazy . . . Regex! 62 Common Input Validation Patterns 65 Wrapping It Up 67 Chapter 6 Filesystem Access: Accessing the Filesystem for Fun and Profit 69 Opening Files 69 Local Filesystem Access 69 Remote Filesystem Access 71 Preventing Remote Filesystem Exploits 72 Creating and Storing Files 73 Allowing File Uploads 73 Storing Files Safely 75 Changing File Properties Safely 76 Changing File Permissions in UNIX, Linux, and Mac OS X 76 Changing Windows File Permissions 77 Changing File Permissions in PHP 87 Patching the Application to Allow User-Uploaded Image Files 88 Modify the API 88 Create the Upload Form 90 Wrapping It Up 90 Part IV “Aw come on man, you can trust me” 93 Chapter 7 Authentication 95 What Is User Authentication? 95 Usernames and Passwords 97 Image Recognition 99 Privileges 100 How to Authenticate Users 101 Directory-Based Authentication 101 User Database 114 Storing Usernames and Passwords 115 Encryption 115 Password Strength 116 Assess Your Vulnerability 117 From the Library of Lee Bogdanoff CONTENTS viii Patching the Application to Authenticate Users 117 Add User Database Table and Double-Check Database Security 118 Create Authentication API 119 Wrapping It Up 120 Chapter 8 Encryption 121 What Is Encryption? 121 Choosing an Encryption Type 123 Algorithm Strength 123 Speed Versus Security 124 Use of the Data 124 Password Security 125 Patching the Application to Encrypt Passwords 125 Modifying the User Table 126 Create the Encryption and Salting Functions 126 Modify the Password Validation System 127 Wrapping It Up 128 Chapter 9 Session Security 129 What Is a Session Variable? 129 Major Types of Session Attacks 129 Session Fixation 130 Session Hijacking 131 Session Poisoning 133 Patching the Application to Secure the Session 133 Wrapping It Up 136 Chapter 10 Cross-Site Scripting 137 What Is XSS? 137 Reflected XSS 137 Stored XSS 138 Patching the Application to Prevent XSS Attacks 138 Wrapping It Up 139 Part V Locking Up for the Night 141 Chapter 11 Securing Apache and MySQL 143 Programming Languages, Web Servers, and Operating Systems Are Inherently Insecure 143 Securing a UNIX, Linux, or Mac OS X Environment 144 Update the Operating System 145 Securing Apache 147 Upgrade or Install the Latest Stable Version of Apache 147 Give Apache Its Own User and Group 149 From the Library of Lee Bogdanoff CONTENTS ix Hide the Version Number and Other Sensitive Information 151 Restrict Apache to Its Own Directory Structure 152 Disable Any Options You Don’t Explicitly Need 153 Install and Enable ModSecurity 154 Securing MySQL 159 Upgrade or Install the Latest Version 159 Disable Remote Access 163 Change Admin Username and Password 163 Delete Default Database Users and Create New Accounts for Each Application 164 Delete the Sample Databases 165 Wrapping It Up 166 Chapter 12 Securing IIS and SQL Server 167 Securing a Windows Server Environment 167 Update the Operating System 168 Securing IIS 177 Reduce the Server’s Footprint 177 Secure the Web Root 179 Securing SQL Server 187 Install or Upgrade to the Latest Version 187 Secure Microsoft SQL Server 200 Wrapping It Up 205 Chapter 13 Securing PHP on the Server 207 Using the Latest Version of PHP 207 Examining the Zend Framework and Zend Optimizer 208 Finding the Latest Stable Version of PHP 212 Using the Suhosin Patch and Extension 213 Using the Security Features Built into PHP and Apache 213 safe_mode 213 SuEXEC 214 Using ModSecurity 215 Hardening php.ini 216 Wrapping It Up 218 Chapter 14 Introduction to Automated Testing 219 Why Are We Talking About Testing in a Security Book? 219 Testing Framework 220 Types of Tests 222 Unit Tests 222 System Tests 223 Choosing Solid Test Data 223 Wrapping It Up 224 From the Library of Lee Bogdanoff CONTENTS x Chapter 15 Introduction to Exploit Testing 225 What Is Exploit Testing? 225 Fuzzing 226 Installing and Configuring PowerFuzzer 227 Using PowerFuzzer 231 Testing Toolkits 233 Obtaining CAL9000 234 Using CAL9000 235 Proprietary Test Suites 246 Benefits and Features of a Proprietary Test Suite 246 Using a Proprietary Test Suite to Scan Your Application 247 Wrapping It Up 254 Part VI “Don’t Get Hacked” Is Not a Viable Security Policy 255 Chapter 16 Plan A: Designing a Secure Application from the Beginning 257 Before You Sit Down at the Keyboard . . . 257 Concept Summary 257 Workflow and Actors Diagram 260 Data Design 260 Infrastructure Functions 267 Identifying Points of Failure 269 Login and Logout 269 File Upload 270 User Input 270 Filesystem Access 271 Wrapping It Up 271 Chapter 17 Plan B: Plugging the Holes in Your Existing Application 273 Set Up Your Environment 273 Using a Three-Stage Deployment 273 Using Version Control 275 Application Hardening Checklist 276 Check Your Server Security 276 Find the Vulnerabilities in Your Code 276 Fix the Most Obvious Problems 277 Have Your Code Peer-Reviewed 278 Wrapping It Up 278 Epilogue Security Is a Lifestyle Choice: Becoming a Better Programmer 279 Avoid Feature Creep 279 Write Self-Documenting Code 280 Use the Right Tools for the Job 282 Have Your Code Peer-Reviewed 283 Wrapping It Up 284 From the Library of Lee Bogdanoff CONTENTS xi Appendix Additional Resources 285 PEAR 285 Books 286 Web Sites 287 Tools 288 Integrated Development Environments (IDE) and Frameworks 288 Exploit Testing Tools 288 Automated Testing Tools 288 Glossary 289 Index 293

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧