4. How Do I Gather Statistics?
What steps should be included in the gather stats job, what type of stats should be collected?
Is this the rule to be followed?
Of course not! This is what I do!
Is this the best way to do it?
Of course not! I am convinced there are many other ways to do it.
Is this working for me?
Of course it is! Otherwise I wouldn’t do
it!
Is this working for you? Should you do it this way?
Give it a try, and find out for yourself! Only you can answer that question.
So what does Diana do in the gather stats script?
First,
I disable the default gather stats task.
The reason for it: I want to make sure that stats are gathered for all the objects that need new statistics, every time I run the stats job, that is why I am not using the default task. With the default job, if the maintenance window ends, not all tables that need statistics will get statistics collected.
I incorporated the step to disable the default gather stats task, right into my script, so I don’t need to remember and check if the default stats
task is enabled or not.
Second, I gather statistics on the data dictionary. I do not gather system statistics or fixed object statistics in my script, as this is not recommended by Oracle.
Third, I do a listing of the objects
with STALE stats, gather statistics on these objects for tables, table partitions, indexes.
Fourth, I list the objects with EMPTY stats, gather statistics on these objects for tables, table partitions, indexes.
I capture the time
it takes to gather stats for each object, which is great for trending purposes, or for troubleshooting long job runs.
I also capture the statements to gather stats, this way I can confirm what was gathered in each run.
I use a shell script, which is scheduled as a database job, and runs once a
week.
Please find the script here gather_statistics.sh.
Disclaimer: You need
to update the script to run in your own environment. Run the script at your own risk, and always run it in test environment first.