I’m using a custom-built inhouse application that generates a standard set of reports on a weekly basis. I have no access to the source code of the application, and everyone tells me there is no documentation available for the Oracle database schema. (Aargh!)
I’ve been asked to define the specs for a variant of an existing report (e.g., apply additional filters to constrain the data set, and modify the layout slightly). This sounds simple enough in principle, but is difficult without any existing documentation.
It’s my understanding that the logs can’t help me because the report only queries the database; it does not actually insert, delete, or update database values, so there is nothing to log (is this correct?).
So my question is this: is there a tool or utility (Oracle or otherwise) that I can use to see the actual SQL statement that is being executed while the report generation job is still running? I figure, if I can see what tables are actually being accessed to produce the existing report, I’ll have a very good starting point for exploring the schema and determining the correct SQL to use for my own report.
On the data dictionary side there are a lot of tools you can use to such as Schema Spy
To look at what queries are running look at views sys.v_$sql and sys.v_$sqltext. You will also need access to sys.all_users
One thing to note that queries that use parameters will show up once with entries like
while others that dont will show up multiple times such as:
An example of these tables in action is the following SQL to find the top 20 diskread hogs. You could change this by removing the WHERE rownum <= 20 and maybe add ORDER BY module. You often find the module will give you a bog clue as to what software is running the query (eg: ‘TOAD 9.0.1.8’, ‘JDBC Thin Client’, ‘runcbl@somebox (TNS V1-V3)’ etc)
Note that if the query is long .. you will have to query v_$sqltext. This stores the whole query. You will have to look up the ADDRESS and HASH_VALUE and pick up all the pieces. Eg: