Menu Close

Partition statistics not being copied

This is a rather quick investigation, but it shows some interesting Oracle behaviour.  I had written a PL/SQL package that manages range partitioned tables: adding new partitions, copying statistics and unlocking the statistics of older partitions.  I had implemented it on a new database and set it running a few days before and everything was running fine.  I checked again after the weekend and discovered that the statistics were apparently not being copied.  This was rather strange as the package sends emails and these all stated that stats had been copied.  I looked at the log table for the package and it also suggested that the statistics were being copied.  Either I had a bug in my package or something very strange was going on.  I took a look at DBA_OPSTAT_OPERATIONS and sure enough there were entries showing statistics being copied by my package to the partitions.  These were all marked as complete.  However there was also an entry for the standard “gather_database_stats” procedure and this was listed as timed out.  What appears to be happening is that the “gather_database_stats” job starts gathering the global statistics for the relevant table.  Some time later, my package added partitions to the table that the “gather_database_stats” procedure gathering statistics for.  My package then copied statistics to the newly created partitions and some time after that the “gather_database_stats” procedure times out and rolls back the statistics for the table.  Thus my package had been working as intended, but the rollback of the statistics executed when “gather_database_stats” timed out also rolled by the copying of the statistics by my package.  The simple solution was to adjust the timing of the job executing my package to ensure it never coincided with the “gather_database_stats” procedure.