当前位置:网站首页>SQL调优指南笔记17:Importing and Exporting Optimizer Statistics
SQL调优指南笔记17:Importing and Exporting Optimizer Statistics
2022-06-12 21:30:00 【dingdingfish】
本文为SQL Tuning Guide第17章“Importing and Exporting Optimizer Statistics”的笔记。
您可以将优化器统计数据从数据字典导出和导入到用户定义的统计表。 您还可以将统计数据从一个数据库复制到另一个数据库。
17.1 About Transporting Optimizer Statistics
当您在数据库之间传输优化器统计信息时,您必须使用 DBMS_STATS 将统计信息复制到登台表和从登台表复制统计信息,并使用工具使目标数据库可以访问表内容。
17.1.1 Purpose of Transporting Optimizer Statistics
导入和导出对于使用生产统计数据测试应用程序特别有用。
开发人员通常希望在部署应用程序之前在真实环境中调整查询计划。 一个典型的场景是使用 DBMS_STATS.EXPORT_SCHEMA_STATS 将模式统计信息从生产数据库导出到测试数据库。
17.1.2 How Transporting Optimizer Statistics Works
典型的传输操作使用 DBMS_STATS 和文件传输实用程序的组合。
下图说明了使用 Oracle 数据泵和 ftp 的过程。
基本步骤如下:
- 在生产数据库中,使用 DBMS_STATS.EXPORT_SCHEMA_STATS 将数据字典中的统计信息复制到临时表。
- 使用 Oracle Data Pump 将临时表中的统计信息导出到 .dmp 文件。
- 使用 ftp 等传输工具将 .dmp 文件从生产主机传输到测试主机。
- 在测试数据库中,使用 Oracle 数据泵将 .dmp 文件中的统计信息导入临时表。
- 使用 DBMS_STATS.IMPORT_SCHEMA_STATS 将统计信息从登台表复制到数据字典。
17.1.3 User Interface for Importing and Exporting Optimizer Statistics
DBMS_STATS 提供了用于导入和导出模式和表的统计信息的接口。
DBMS_STATS 中的以下子程序使您能够导出模式和不同类型的表。
表 17-1 用于导出模式和表统计信息的子程序
| 子程序 | 描述 |
|---|---|
| EXPORT_DATABASE_STATS | 此过程导出数据库中所有对象的统计信息,并将它们存储在由 statown.stattab 标识的用户统计信息表中。 |
| EXPORT_DICTIONARY_STATS | 此过程导出所有数据字典模式(SYS、SYSTEM 和 RDBMS 组件模式)的统计信息,并将它们存储在 stattab 标识的用户统计信息表中。 |
| EXPORT_FIXED_OBJECT_STATS | 此过程导出固定表的统计信息并将它们存储在由 stattab 标识的用户统计信息表中。 |
| EXPORT_SCHEMA_STATS | 此过程导出由 ownname 标识的模式中的所有对象的统计信息,并将它们存储在由 stattab 标识的用户统计信息表中。 默认情况下,stat_category 参数包括实时统计期间收集的统计信息。 REALTIME_STATS 值仅指定在线统计信息。 |
| EXPORT_TABLE_STATS | 此过程导出指定表的统计信息(包括关联的索引统计信息)并将它们存储在 stattab 标识的用户统计信息表中。 默认情况下,stat_category 参数包括实时统计期间收集的统计信息。 REALTIME_STATS 值仅指定在线统计信息。 |
DBMS_STATS 中的以下子程序使您能够导入模式和不同类型的表。
- IMPORT_DATABASE_STATS
- IMPORT_DICTIONARY_STATS
- IMPORT_FIXED_OBJECT_STATS
- IMPORT_SCHEMA_STATS
- IMPORT_TABLE_STATS
17.2 Transporting Optimizer Statistics to a Test Database: Tutorial
您可以使用 Oracle 数据泵将模式统计信息从生产数据库传输到测试数据库。
先决条件和限制
准备导出优化器统计信息时,请注意以下几点:
- 在导出统计信息之前,您必须创建一个表来保存统计信息。 过程 DBMS_STATS.CREATE_STAT_TABLE 创建统计表。
- 优化器不使用存储在用户拥有的表中的统计信息。 优化器使用的唯一统计信息是存储在数据字典中的统计信息。 要使优化器在用户定义的表中使用统计信息,请使用 DBMS_STATS 导入过程将这些统计信息导入数据字典。
- 数据泵导出和导入实用程序从数据库中导出和导入优化器统计信息以及表。 当列具有系统生成的名称时,原始导出 (exp) 不会将统计信息与数据一起导出,但此限制不适用于数据泵导出。
假设
本教程假定以下内容:
- 您希望在生产数据库上生成有代表性的 sh 模式统计数据,并使用 DBMS_STATS 将它们导入测试数据库。
- 管理用户 dba1 存在于生产和测试数据库中。
- 您打算创建表 opt_stats 来存储模式统计信息。
- 您打算使用 Oracle Data Pump 导出和导入表 opt_stats。
要生成模式统计信息并将其导入单独的数据库
-- 在生产系统,执行以下 PL/SQL 程序创建用户统计表 opt_stats
BEGIN
DBMS_STATS.CREATE_STAT_TABLE (
ownname => 'dba1'
, stattab => 'opt_stats'
);
END;
/
-- 收集模式的统计信息。
-- generate representative workload
EXEC DBMS_STATS.GATHER_SCHEMA_STATS('SH');
-- 检索模式统计信息并将它们存储在先前创建的 opt_stats 表中
BEGIN
DBMS_STATS.EXPORT_SCHEMA_STATS (
ownname => 'dba1'
, stattab => 'opt_stats'
);
END;
/
-- 使用 Oracle Data Pump 导出统计表的内容
expdp dba1 DIRECTORY=dpump_dir1 DUMPFILE=stat.dmp TABLES=opt_stats
-- 登录测试主机,然后使用Oracle Data Pump 导入统计表的内容。
impdp dba1 DIRECTORY=dpump_dir1 DUMPFILE=stat.dmp TABLES=opt_stats
-- 使用 DBMS_STATS 从用户统计表中导入统计数据并将它们存储在数据字典中。
BEGIN
DBMS_STATS.IMPORT_SCHEMA_STATS(
ownname => 'dba1'
, stattab => 'opt_stats'
);
END;
/
边栏推荐
- Jdbctemplate inserts and returns the primary key
- The service did not report any errors MySQL
- What's a good gift for the goddess Festival? Gift recommendation for the goddess Festival on March 8
- Sorting out the knowledge points of primary and secondary indicators
- gzip压缩解压缩
- 一级指针&二级指针知识点梳理
- (4) Pyqt designs and implements the [factory production management system] order page - add, delete, modify and query (including source code analysis)
- Ubuntu 16.04 installing mysql5.6
- 大一下学年学期总结
- ORM implements the mapping relationship between classes and tables, class attributes and fields
猜你喜欢

Smart management of green agriculture: a visual platform for agricultural product scheduling

leetcode:210. 課程錶 II
![[target detection] |dive detector into box for object detection new training method based on fcos](/img/ac/c54c2733dceffea086b772f35f128a.png)
[target detection] |dive detector into box for object detection new training method based on fcos

Sorting out the knowledge points of primary and secondary indicators

The ifeq, filter and strip of makefile are easy to use

What's a good gift for the goddess Festival? Gift recommendation for the goddess Festival on March 8

makefile 的ifeq,filter,strip 简单使用

Data visualization - Calendar chart

Lake shore PT-100 platinum resistance temperature sensor

MySql主从复制
随机推荐
Can tonghuashun open an account? Can the security of securities companies be directly opened on the app? How to open an account for securities accounts
jsonUtils
JUC并发工具包使用指南
Pytoch distributed training error
Libmysqlclient A static library
Data visualization - Calendar chart
Research Report on hydraulic injection machine industry - market status analysis and development prospect forecast
好数对的求解
selenium操作元素遇到的异常
torch. unique()
Can flush open an account? Can you directly open the security of securities companies on the app
zgc的垃圾收集的主要阶段
Structure knowledge points all in
初步了解认识正则表达式(Regex)
有向图深拷贝
MySql主从复制
Lintcode:127. Topology sorting
同花顺能开户吗,在APP上可以直接开通券商安全吗
How to design a message box through draftjs
Solve one-dimensional array prefix sum