SNAP_ANYTHING: Tiny little solution for snapping and recording anything that you can query

No rocket science here, but since I use it so frequently, I thought this might be actually usefull for others, too.

Quote from the Readme.txt file:

Once installed, the two tables, the PL/SQL package and the scheduler job
make it very easy to record regular snapshots of the results of SQL queries.

Since this is something I frequently need to do, e.g. for performance data
not snapped by STATSPACK/AWR, tracking a list of invalid objects in developer
schemas over longer periods of time, recording AUDIT information from remote
test/dev databases that are cloned from production every night, etc., I put
this into it's own schema/setup script for easy installation on different databases.


All you have to do to do a snapshot of query result data in fixed intervals
is adding a row to the table SNAP_ANYTHING.HIST_QUERIES, like in this example:

'Snapshots of V$SESSION',

This will execute the query 'SELECT * FROM V$SESSION' every five minutes and
write the result data rows into the table 'HIST$SESSIONS' (in the SNAP_ANYTHING
schema). If the table doesn't exist, it will be created automatically. The target
table will have all columns returned by the query, plus the columns SNAP_TIME
(date/time when this data was recorded) and ORDER_ID (row_num of row for this

The data is automatically cleaned up based on the number in the RETENTION_MINUTES
column. Putting 1440 there will keep the snapshot data from the last 24 hours
(purging happens after every snapshot taken).

Columns in HIST_QUERIES:

NAME: Just a descriptive name so you know what it does.
QUERY_TEXT: The SELECT query that should be executed.
TARGET_TABLE: The target table where the recorded data should go. Doesn't have to exist yet.
REPEAT_INTERVAL: Repeat interval for the execution of the query, e.g.'SYSDATE+(5/24/60)' (every 5 minutes) or 'trunc(sysdate)+7+9/24' (once a week at 9:00am)
RETENTION_MINUTES: Number of minutes that you want to keep snapshot data for
ENABLED: Y or N. N disables the snapshot collection.

The scheduler job SNAP_ANYTHING.SNAP_ANYTHING_SNAPPER_JOB checks the table HIST_QUERIES for queries that need to be run, based on their REPEAT_INTERVAL setting.

The table HIST_QUERIES_LOG shows the log entries for the snapshots executed by the scheduler jobs. The entries in HIST_QUERIES_LOG are limited to the 10 days of snapshot executions.

You can download the zip package with the setup script here:

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s