Large Table Statistics
Script: dstatbig.sql
Section titled “Script: dstatbig.sql”rem dstatbig.sqlremttitle 'Large Table Statistics'remcol owner format a8 heading 'OWNER'col table_name format a25 heading 'TABLE NAME'col num_rows format 999999990 heading 'ROWS'col chain_cnt format 9990 heading 'CHAIN|COUNT'col avg_row_len format 9990 heading 'AVG|ROW|SIZE'col blocks format 9999990 heading 'USED|BLOCKS'col empty_blocks format 999990 heading 'EMPTY|BLOCKS'col avg_space format 9990 heading 'AVG|FREE|SPACE'rembreak on report on owner skip 1compute sum of num_rows blocks empty_blocks on report ownerremselect owner, table_name, num_rows, chain_cnt, avg_row_len, blocks, empty_blocks, avg_space from sys.dba_tables where owner like upper('&owner') and table_name like upper('&table') and ( num_rows >= &rows or blocks >= &blocks or empty_blocks >= 10000 ) order by owner, table_name;
Purpose
Section titled “Purpose”This script identifies and displays statistics for large tables in the database based on configurable thresholds for row count, used blocks, or empty blocks. It helps DBAs focus on tables that may require special attention due to their size.
Key Features
Section titled “Key Features”- Flexible Filtering: Filter by owner, table name, and size thresholds
- Comprehensive Stats: Shows row counts, chaining, block usage
- Summary Totals: Computes sums by owner and report total
- Large Table Focus: Automatically filters for significant tables
Parameters
Section titled “Parameters”The script prompts for:
- owner: Schema owner (supports wildcards with %)
- table: Table name pattern (supports wildcards with %)
- rows: Minimum row count threshold
- blocks: Minimum used blocks threshold
Output Columns
Section titled “Output Columns”- OWNER: Schema that owns the table
- TABLE NAME: Name of the table
- ROWS: Number of rows (from statistics)
- CHAIN COUNT: Number of chained/migrated rows
- AVG ROW SIZE: Average row length in bytes
- USED BLOCKS: Number of blocks containing data
- EMPTY BLOCKS: Number of allocated but empty blocks
- AVG FREE SPACE: Average free space per block
Usage Examples
Section titled “Usage Examples”Find All Large Tables
Section titled “Find All Large Tables”SQL> @dstatbig.sqlEnter value for owner: %Enter value for table: %Enter value for rows: 1000000Enter value for blocks: 10000
Specific Schema Analysis
Section titled “Specific Schema Analysis”SQL> @dstatbig.sqlEnter value for owner: SALESEnter value for table: %Enter value for rows: 500000Enter value for blocks: 5000
Pattern Matching
Section titled “Pattern Matching”SQL> @dstatbig.sqlEnter value for owner: %Enter value for table: %HISTORY%Enter value for rows: 100000Enter value for blocks: 1000
Large Table Criteria
Section titled “Large Table Criteria”Tables are included if they meet ANY of these conditions:
- Row count >= specified threshold
- Used blocks >= specified threshold
- Empty blocks >= 10000 (hardcoded)
Performance Indicators
Section titled “Performance Indicators”Chain Count
Section titled “Chain Count”- High chain_cnt indicates row migration/chaining
- May require table reorganization
- Can impact query performance
Empty Blocks
Section titled “Empty Blocks”- Large number suggests space wastage
- Consider shrinking or reorganizing
- May indicate deleted data
Average Row Size
Section titled “Average Row Size”- Helps estimate storage requirements
- Useful for capacity planning
- Indicates data characteristics
Best Practices
Section titled “Best Practices”- Regular Monitoring: Run periodically to track growth
- Statistics Currency: Ensure statistics are up-to-date
- Threshold Tuning: Adjust thresholds based on database size
- Action Planning: Use results to plan maintenance
Common Actions
Section titled “Common Actions”Based on findings:
- High Chaining: Consider increasing PCTFREE or reorganizing
- Many Empty Blocks: Use ALTER TABLE SHRINK SPACE
- Rapid Growth: Implement partitioning or archiving
- No Statistics: Gather statistics for accurate results
Related Scripts
Section titled “Related Scripts”- dtable.sql: General table information
- dtabhist.sql: Table statistics history
- objcnt.sql: Object counts by type
- maxshrink.sql: Calculate shrinkable space