• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Techgoeasy

Techgoeasy

Learn Oracle, PHP, HTML,CSS,Perl,UNIX shell scripts

  • Home
  • Oracle
    • Oracle database
    • Oracle Ebusiness Suite
    • Oracle weblogic
    • Oracle Performance Tuning
    • Oracle Hyperion
    • Oracle Cloud Tutorials
  • SQL
  • interview questions
  • Linux
  • PHP and HTML
  • Downloads
  • General
Home » Oracle » Oracle Database » How to gather Statistics with DBMS_STATS Procedures

How to gather Statistics with DBMS_STATS Procedures

April 10, 2023 by techgoeasy Leave a Comment

Table of Contents

  • What is DBMS_STATS
  • What are the procedures to collect statistics?
  • How to collect table statistics
  • How to collect schema statistics
  • How to collect Database statistics

What is DBMS_STATS

The DBMS_STATS package was introduced in Oracle 8i and is Oracle’s preferred method of gathering object statistics.

DBMS_STATS is a package in Oracle Database that provides procedures to manage statistics for database objects. Statistics are essential for the optimizer to make efficient execution plans for SQL statements. The package offers procedures to gather, export, import, and delete statistics for objects such as tables, indexes, partitions, and columns.

The primary benefits of using it are

  • parallel execution
  • long-term storage of statistics
  • Ability to import/export statistics
  • Able to manually modify statistics
  • Ability to modify, view, export, import, and delete statistics.

The DBMS_STATS package can gather statistics on tables and indexes, as well as individual columns and partitions of tables.

When we generate statistics for a table, column, or index, if the data dictionary already contains statistics for the object, then Oracle updates the existing statistics. The older statistics are saved and can be restored later if necessary.

It is recommended to gather statistics regularly, especially after significant changes to the data or schema, to ensure optimal query performance. The DBMS_STATS package offers a variety of options for managing statistics efficiently in an Oracle database.

What are the procedures to collect statistics?

How to collect table statistics

It is done using gather_table_stats

It takes the default value from dbms_stats.get_parms whichever option is not given while executing gather table stats

Example

EXEC DBMS_STATS.GATHER_TABLE_STATS('SCOTT','EMP');
EXEC DBMS_STATS.GATHER_TABLE_STATS('SCOTT','EMP',ESTIMATE_PERCENT=>15);

How to collect schema statistics

It is done using gather_table_stats

It takes the default value from dbms_stats.get_parms whichever option is not given while executing gather table stats

Examples

EXEC DBMS_STATS.GATHER_SCHEMA_STATS(OWNNAME=>'SCOTT',OPTIONS=>'GATHER AUTO');
EXEC DBMS_STATS.GATHER_SCHEMA_STATS(OWNNAME=>'HR',CASCADE=>TRUE);

How to collect Database statistics

Examples

EXEC DBMS_STATS.GATHER_DATABASE_STATS;
EXEC DBMS_STATS.GATHER_DATABASE_STATS(ESTIMATE_PERCENT=>20);

Filed Under: Oracle, Oracle Database

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar



Subscribe to our mailing list

Enter your email address to subscribe to this blog and receive notifications of new posts by email

Recent Posts

  • How to verify stats for the table in EBS
  • STATISTICS_LEVEL in Oracle
  • Move SQL Profiles from One Database to Another 
  • How to compare statistics using stattab for a table in Oracle
  • How to compare statistics using history for a table in Oracle

Copyright © 2023 : TechGoEasy

  • Hire me
  • Privacy Policy
  • Contact Us
  • New? Start Here
  • About Us
x
x