Estatísticas | Oracle | 2015

224 visualizações

Publicada em

Como funcionam as estatísticas da base de dados em Oracle.

Publicada em: Software
0 comentários
1 gostou
  • Seja o primeiro a comentar

Sem downloads
Visualizações totais
No SlideShare
A partir de incorporações
Número de incorporações
Incorporações 0
Nenhuma incorporação

Nenhuma nota no slide
  • In order for the Cost Based Optimizer to accurately determine the cost for an execution plan, it must have information about all of the objects (table and indexes) accessed in the SQL statement, and information about the system on which the SQL statement will be run. This necessary information is commonly referred to as Optimizer statistics. Understanding and managing statistics are key to optimal SQL execution. Knowing when and how to gather statistics in a timely manner is critical to maintaining good performance. By using a combination of the automatic statistics gathering job and the DBMS_STATS package, a DBA can maintain an accurate set of statistics for a system, ensuring the Optimizer will have the best possible source of information to determine the execution plan.
  • Using dbms_stats.gather_schema_stats
    The dbms_stats.gather_schema_stats procedure allows you to gather statistics for all objects in a give schema. This is the easiest way to generate statistics for a large number of objects. Here is an example of using the dbms_stats.gather_schema_stats procedure to gather statistics on the SCOTT schema of a database:
    EXEC dbms_stats.gather_schema_stats('SCOTT', cascade=>TRUE);
    This command will generate statistics on all tables in the SCOTT schema. Since we included the cascade command, the indexes will also have statistics generated on them. This is important, you need statistics on indexes as well as on tables in Oracle!
    Of course, this is just the basic way to run this command. Several options are available, but for now as a new DBA this will do.  In fact, Oracle 10g automatically collects database statistics every night out of the box.  Later you will want to investigate some of the Oracle Database 10g statistics gathering options such as histograms, and granularity.
    If you create a new table, then it may not be practical or desirable to re-generate statistics on the entire schema if the schema is quite large and the database is very busy. Instead you will use the dbms_stats.gather_table_stats command to generate statistics for a single table, and optionally for related table indexes. Here is an example:
    EXEC dbms_stats.gather_table_stats('SCOTT','EMP',cascade=>TRUE);
    In this case we are generating statistics for the EMP table in the SCOTT schema. Again we use the cascade parameter to insure all of the indexes get analyzed.
  • Estatísticas | Oracle | 2015

    1. 1. Estatísticas - Oracle – (Versão 2015) Carlos Pampulim Caldeira Administração de Bases de Dados
    2. 2. Exemplos do que está incluído nas estatísticas: • Tabelas – número de linhas – número de blocos – comprimento médio da linha • Colunas – número de valores distintos – número de nulos – histograma (distribuição dos dados) • Índices – número de blocos (folhas) – níveis – factor de clustering • Sistema – I/O - performance e utilização – CPU – performance e utilização
    3. 3. Recolher estatísticas de tabelas e colunas no schema EXECUTE DBMS_STATS.GATHER_SCHEMA_STATS(’schema’, cascade => TRUE); EXECUTE DBMS_STATS.GATHER_SCHEMA_STATS ('ccaldeira', cascade => TRUE);
    4. 4. Recolher/Actualizar estatísticas de todos os objectos da BD EXEC DBMS_STATS.GATHER_DATABASE_STATS;
    5. 5. Recolher estatísticas do sistema EXECUTE DBMS_STATS.GATHER_SYSTEM_STATS;
    6. 6. Recolher estatísticas para uma tabela ANALYZE TABLE schema.tabela COMPUTE STATISTICS; EXEC DBMS_GATHER_TABLE_STATS(‘shema’, ‘tabela’, CASCADE => TRUE);
    7. 7. Recolher estatísticas para uma tabela EXEC DBMS_STATS.GATHER_TABLE_STATS('ccaldeira', 'Terrorista Actos', cascade => TRUE); BEGIN DBMS_STATS.GATHER_TABLE_STATS ( ownname => '"CCALDEIRA"', tabname => '"Terrorista Actos"', estimate_percent => 10 ); END;