Recording sql statements performing on a table in Oracle - oracle

Is there a way to record sql statements performing on table in Oracle? I need to record those queries for a table in production and hopefully rerun them in my test to make sure I don't mess up table modification.
Thanks,
Sean

Oracle Database Replay is exactly the feature you are looking for: http://www.oracle.com/technetwork/articles/sql/11g-replay-099279.html

Oracle automatically records any SQL executed against the instance in a table called v$sqlarea

Related

how to fetch last access TIMESTAMP of a table in oracle?

How to fetch the last access date for a table in oracle using the query from Oracle DB?
I am using select TIMESTAMP from dba_tab_modifications query it's giving me last updates in table
but I need last execution of select query statement on a particular table
Thanks in Advance
Sai Kumar
Oracle does not keep this information by default. You need to enable the appropriate AUDIT rules. But I'd question what problem you think this will solve. Auditing every access to a table will be a lot of audit records.

Oracle DB Audit ALL

I have a 5TB large database.
I want to audit everything , really everything.
First of all, I tried with AUDIT ALL, but according to Oracle's document AUDIT ALL does NOT audit everything...
I know that this statement must be executed in order to start auditing db:
alter system set audit_trail=db,extended scope=spfile;
But what else should I do to start auditing all the SQL statements that users execute?
You need not to use the AUDIT feature if you only want a view on user queries (SELECT, UPDATE, INSERT) on your database. $AUD contains rather DDL statements, whereas V$SQL contains only DML statements.
A very simple solution is to use another view: V$SQL. You can extract duration and lot of useful info from it.
Useful example:
SELECT * FROM v$sql vv
WHERE lower(vv.SQL_TEXT) like '%delete%'
AND vv.PARSING_SCHEMA_NAME like 'A_SCHEMA%'
ORDER BY vv.LAST_ACTIVE_TIME desc;
V$SQL lists statistics on shared SQL area without the GROUP BY clause and contains one row for each child of the original SQL text entered. Statistics displayed in V$SQL are normally updated at the end of query execution.
Long running queries are updated every 5 seconds. This shows the impact of long running SQLs while they are still working.

Oracle: Finding the stored procedure that modifies record on a table

I've got a C# code that calls stored procedures and UPDATES a table. Can I monitor each operation made on this table by a SID.
Yes, you can do this at the database level using Oracle auditing. See here for good writeup and examples of its use.

Dynamic SQL-Loader control file

I have 20 tables that are temp-tables where we load and validate data constantly and I have a control file for each table.
How can I have a unique control file that just changes the table the data is loaded into?
Any suggestion?
Thanks in advance!
---Oracle info---
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
Suggest you write your control file load the data into a synonym rather than into the specific table. Begin each load run by redefining the synonym to the table you want.
Maybe you can use multiple INTO TABLE clauses, and distinguish bitween them, somehow, with the WHEN clause.
Look here for more details

How can I tell if a Materialized View in Oracle is being used?

We have some Materialized views in our Oracle 9i database that were created a long time ago, by a guy no longer working here. Is there an easy (or any) method to determine whether Oracle is using these views to serve queries? If they aren't being used any more, we'd like to get rid of them. But we don't want to discover after the fact that those views are the things that allow some random report to run in less than a few hours. The answer I'm dreaming of would be something like
SELECT last_used_date FROM dba_magic
WHERE materialized_view_name = 'peters_mview'
Even more awesome would be something that could tell me what actual SQL queries were using the materialized view. I realize I may have to settle for less.
If there is a solution that requires 10g, we are upgrading soon, so those answers would be useful also.
Oracle auditing can tell you this once configured as per the docs. Once configured, enable it by "AUDIT SELECT ON {name of materialized view}". The audit trail will be in the AUD$ table in the SYS schema.
One method other than auditing would be to read the v$segment_statistics view after one refresh and before the next refresh to see if there have been any reads. You'd have to account for any automatic statistics collection jobs also.
V$SQLAREA table has two columns which help identify the queries executed by the database.
SQL_TEXT - VARCHAR2(1000) - First thousand characters of the SQL text for the current cursor
SQL_FULLTEXT - CLOB - All characters of the SQL text for the current cursor
We can use this columns to find the queries using the said materialized views

Resources