How to find sql statement which generates LOCK

Hello,
In my plsql procedure i have used SELECT FOR UPDATE NO WAIT statement to avoid the current record used by another user.
Actually i want to find which sqlquery is locking the Object other than my procedure.
I can find the session id which is locking the object but i can not able to find sql text.
How to find the SQL text from particular LOCKING Session id as v$sql or v$sqltext or v$sqlarea dont have session id?
Any help can be appreciated.
Thanks in advance.

It's not necessarily that easy to find the statement that was responsible for the lock.
It depends.
First of all, it depends on version.
If you're >= 10g and you're lucky and you're licensed for Diagnostic Pack, you might find it in ASH.
If the statement that's responsible for the lock is also waiting on something else or runs for long enough, then ASH will almost certainly have it.
Doug Burns has a 10-part series on the subject.
http://oracledoug.com/serendipity/index.php?/archives/1477-Diagnosing-Locking-Problems-using-ASH-Part-1.html

Similar Messages

  • How to find the sessions which generated maximum redo amount at instance?

    I use below query or Sql*Plus's set autotrace traceonly statistics > redo size statistic to calculate how much redo I generated in my session;
    CREATE OR REPLACE VIEW redo_size AS
    SELECT value
    FROM v$mystat, v$statname
    WHERE v$mystat.statistic# = v$statname.statistic#
    AND v$statname.name = ‘redo size’;
    But how to find the sessions which generated maximum(top 5 for example) redo from the last database startup on 9iR2 or also with new 10gR2 historic views?
    We need this information because from the produced archived log files we observe something new producing almost 2 times more redo for a week. I looked at statspack report but couldnt find as I suspected for a massive update or delete.
    Best regards,
    Tonguc

    I tried v$sysstat but I didnt think about v$sesstat Mr.Gasparotto, thank you very much :)
    SELECT ss.sid,
    sq.sql_text,
    se.status,
    se.username,
    se.osuser,
    se.program,
    se.machine,
    ss.VALUE
    FROM v$sesstat ss, v$statname sn, v$session se, v$sqlarea sq
    WHERE ss.statistic# = sn.statistic#
    AND se.sql_hash_value = sq.hash_value(+)
    AND se.sql_address = sq.address(+)
    AND ss.sid = se.sid
    AND sn.NAME = 'redo size'
    ORDER BY ss.VALUE DESC
    Best regards.

  • How to find sql statement with Unix process pid

    Hi
    how to find sql statement with Unix process pid
    is there any view to find that.
    please if so let me know
    Thanks in advance

    this is how I am doing this:
    oracle 7352340 7459066 0 07:47:10 - 0:00 oracleJDERED (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
    oracle 7459066 5386396 2 07:47:10 pts/1 0:01 sqlplus
    select sid,serial# from v$session where process='7459066';
    SID SERIAL#
    2178 6067
    select sql_text
    from
    v$sqlarea a,
    v$session b
    where a.hash_value = b.sql_hash_value
    and b.sid = 2178
    ;

  • How to find SQL Statement fired using SYS.AUD$ - Database Auditing

    Dear Friends
    I am having Oracle 9i Database and have configured it with database auditing option by setting the following parameter in init.ora file
    AUDIT_TRAIL = "DB"
    I want to audit SELECT, INSERT , UPDATE and DELETE operations on PRACTICE.EMP table for which I did :
    1) Logged in as SYS
    2) SQL> AUDIT SELECT, INSERT, UPDATE, DELETE
    ON PRACTICE.EMP
    BY ACCESS
    WHENEVER SUCCESSFUL;
    Audit Succedded
    Now how should I find out the SQL statement that does the insert, update or delete operation on the EMP table using SYS.AUD$ table
    Thanks

    Hi,
    It's contents can be viewed directly or via the following views:
    * DBA_AUDIT_EXISTS
    * DBA_AUDIT_OBJECT
    * DBA_AUDIT_SESSION
    * DBA_AUDIT_STATEMENT
    * DBA_AUDIT_TRAIL
    * DBA_OBJ_AUDIT_OPTS
    * DBA_PRIV_AUDIT_OPTS
    * DBA_STMT_AUDIT_OPTS
    The audit trail contains a lot of data, but the following are most likely to be of interest:
    * Username : Oracle Username.
    * Terminal : Machine that the user performed the action from.
    * Timestamp : When the action occured.
    * Object Owner : The owner of the object that was interacted with.
    * Object Name : The name of the object that was interacted with.
    * Action Name : The action that occured against the object. (INSERT, UPDATE, DELETE, SELECT, EXECUTE)
    So, take a look at action_name column from DBA_AUDIT_TRAIL view.
    Cheers
    Legatti

  • How to find SQL statement = Database Auditing

    Dear All
    I have configured Database Auditing on Oracle 9i Enterprise Edition Server
    parameter init.ora file:
    AUDIT_TRAIL = "DB"
    I want to audit INSERT,UPDATE, DELETE STATEMENT on PRACTICE.EMP table
    for which i did :
    1) Logged in as SYS
    SQL> AUDIT INSERT,UPDATE,DELETE
    ON PRACTICE.EMP
    BY ACCESS
    WHENEVER SUCCESSFUL
    Audit Succedded
    2) Now I have to check the SQL statement that did insert update or delete operation using SYS.AUD$
    3) There is SQLTEXT field , datatype is CLOB.
    How should I check the SQL Statements that were fired on PRACTICE.EMP table
    Kindly help

    SQL> show user
    USER is "SYS"
    SQL> alter system set audit_trail = db,extended scope=spfile;
    alter system set audit_trail = db,extended scope=spfile
    ERROR at line 1:
    ORA-32001: write to SPFILE requested but no SPFILE specified at startup
    I have init.ora but no spifle so should I create SPFILE based on INIT.ORA and then give the command ?
    As of now I am using V$SQL view to find all the commands executed on my database.
    I found one good book "Oracle Security" OREILY PUBLICATION in which Auditing Database is discussed in good details.
    Thank you so much for all your efforts

  • For Finding sql statements which consumes High CPU

    Hai,
    Can any help me for finding, which sql statements are comsumes high CPU

    generaly:
    1. from unix site :
    us top command or ps (but this depend on platform) -> use pid in select * from v$process where spid <>
    2. from db site
    select * from v$sql_area order by buffer_gets desc ;
    this can You join with v$session where v$session.sql_address=v$sqlarea.address
    and when You wont to see % of os select *spid from v$process where addr=<v$session.paddr>
    and then in unix ps -ef | grep <spid>
    But point 2 is maybe discutable because also parse is one style how to consume CPU ... etc
    In 10g
    from AWR dba_hist_osstat -> DBA_HIST_SQLSTAT You can see high usage CPU interval , but this show You not momentaly action , but historical data
    momentali from ASH
    now I study viraq_sh script ... I thing this answer your question tottally
    Message was edited by:
    branislav.dobrotka

  • How to find SQL Statements for BW queries ?

    Experts,
    Is there a way, we can see what SQL statement BW queries creates ?
    please Help.

    Hi,
    use sql trace: transaction ST05.
    ask your database admin. He can control the database session.
    => for oracle: you can see the session also in the sap gui.
    Sven

  • How to find out in which order locks are aquired by one or more sessions.

    hi,
    i am using following query to find locking of two sessions .
    SELECT resource_database_id, t.resource_type , t.resource_associated_entity_id,partitions.index_id,blocking_session_id,
                indexes.name as index_name,o.name,
        t.request_status, t.request_mode,t.request_session_id,
        t.resource_description 
        ,s.total_elapsed_time,s.start_time, convert(varchar ,getdate() - s.start_time, 114)
        ,s.wait_type,s.wait_time
        ,s.last_wait_type,s.lock_timeout,s.row_count
        ,s.*,o.*,t.*
        FROM sys.dm_tran_locks t
        LEFT JOIN sys.objects o on t.resource_associated_entity_id=o.object_id
        LEFT JOIN sys.dm_exec_requests s ON s.session_id=t.request_session_id
        left join sys.partitions on partitions.hobt_id = t.resource_associated_entity_id
        left join sys.indexes on indexes.object_id = partitions.object_id and indexes.index_id = partitions.index_id
        WHERE s.session_id in (51,52) ORDER BY s.start_time,s.total_elapsed_time
    resource_type resource_associated_entity_id request_session_id request_mode index_name name resource_description
    DATABASE 0 51 S NULL NULL
    OBJECT 2094278866 51 Sch-S NULL wt
    OBJECT 2094278866 52 IX NULL wt
    PAGE 72057597150887936 52 IX PK_wt NULL 1:204815
    KEY 72057597150887936 52 X PK_wt NULL (4fb98fd9bfad)
    DATABASE 0 52 S NULL NULL
    Q1)i wanted to know session id 52 acquired object,page,key and database locks in same order or it was opposite
    how can i find the order of aquisition of locks by (one or two session).
    Q2)i have express edition advance of sqlserver 2008 r2 , it possible to trace every event with out using profiler as u know it
    does not ship with it 
    yours sincerley

    http://blogs.conchango.com/jamesrowlandjones/archive/2009/05/28/the-curious-case-of-the-dubious-deadlock-and-the-not-so-logical-lock.aspx
    select *,%%lockres%%
    from    dbo.Table(nolock)
    where    %%lockres%% IN('(4fb98fd9bfad)')
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to run a SQL statement which is stored inside an SQL Table

    Hello,
    If anyone please help me with the following problem I would be forever grateful
    I have an SQL statement which is stored inside a certain SQL table, I want to use that SQL statement inside my PL/SQL procedure.
    Was thinking of a simple solution of obtaining the SQL statement into an array and then execute it, yet how could I do so exactly with PL/SQL? I've only started playing around with PL/SQL in the last few days.
    Thanks in advance!
    This is how it looks like more or less:
    Displaying result for:
    SELECT TRIM(OBJ_VALU_TXT)
    FROM   OBJ_VALU_DOC
    WHERE  OBJECT_TYPE  = 'FLD'
      AND  OBJECT_CODE  = 15443
      AND  OBJ_VALU_CD  = 'ACR'
    ORDER BYDOC_SEQ_NO
    00001                                                            
    SELECT
    VALUE(MAX(RECEIPT_NO) + 1, :OUT-COMP-FACTOR)
    FROM RECEIPT
    WHERE (RECEIPT_NO BETWEEN
    :OUT-COMP-FACTOR AND :OUT-TO-NUMBER) OR
    (RECEIPT_NO > :OUT-COMP-FACTOR AND
    :OUT-TO-NUMBER = 0)

    Here's a demo of your requirement.
    create table t ( col1 varchar2(200));
    table created
    insert into t values('select * from dual');
    1 row inserted
    declare
    v_col varchar2(200);
    v_val varchar2(200);
    begin
    select col1 into v_col from t;
    execute immediate v_col into v_val;
    dbms_output.put_line(v_val);
    end;
    X
    Using into clause, you can use as many variables as required. But the basic approach reamins the same.
    But storing SQL in DB is not an efficient design.
    Ishan

  • How can I write a SQL statement which checks if a table exists?

    How can I write a SQL statement which tells me whether a table exists?

    execute an sql query: select * from <tablename>
    catch the exception n check whether the erroe code
    matches the one that occurs for table doesn't exist
    that's itHow is your answer any different from the one given in the first reply?
    It isn't.
    As WorkForFood says DatabaseMetaData has a bunch of methods for getting information about tables but this is more useful when you don't know the names of any of the tables.. it sounds like you do so I would concur SELECT from table is probably the quickest way to go. If it helps the Xopen error should be either S1000 or 42S01 (I think) but I would try and see if there is a specific vendor code for table not found/not exists error and check for that.

  • How to find out what is the lock key for the computer

    How to find out what is the lock key for the computer?

    You don't.
    If you forgot or lost the password, all you can practically do is reset it.
    The manner in which you do so depends on what version of OS X you are running. The older versions utilize the reset password utility on your recovery/re-installation disk/drive.
    On Lion, you use the following technique to reset the Administrators password:
    Boot to your Lion Recovery Partition, by holding down the Option key while starting, and then selecting the Recovery HD as the boot choice.
    Once booted, at the top of the screen is a menu ..., select Utilities / Terminal from the menu bar.
    In the Terminal window, type “resetpassword” (without the quotes) and press return. A “Reset Password” window will open. Select your boot volume (your SSD drive) if it is not already selected. Select your administrators username from the menu labeled “Select the user account” if it is not already selected. Follow the prompts to reset the password. Restart the computer from the apple menu.

  • Need SQL statement to generate a sequence number in the output rows

    Hi folks. I need to create an SQL statement that generates a sequence number column in the output rows (records) such that the first returned row has this column set to 1, second returned row has the column set to 2, etc.
    For example, consider the query:
    SELECT income from employees WHERE income != 20000 ORDER BY income;
    If employees.income contains 60,000, 20,000, 35,000, and 19,000 for respective rows, the output would be this:
    19,000
    35,000
    60,000
    I would like the SQL to also return a sequence number that is computed across the returned rows, resulting in two output columns:
    1 19,000
    2 35,000
    3 60,000
    Is there a simple SQL function that generates the sequence number, in order, and only for the returned rows? Or is there another way?
    I'm stumped. Any help is appreciated! Thanks!
    - Jack Cochrane

    Hi,
    Welcome to the forum!
    Use ROWNUM, like (example):
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL> select rownum, first_name from (select e.first_name from employees e where e.first_name like 'J%' order by e.first_name);
        ROWNUM FIRST_NAME
             1 Jack
             2 James
             3 James
             4 Janette
             5 Jason
             6 Jean
             7 Jennifer
             8 Jennifer
             9 John
            10 John
            11 John
            12 Jonathon
            13 Jose Manuel
            14 Joshua
            15 Julia
            16 Julia
    16 rows selected
    SQL> But rememeber if you want to be sure of unique numbers in certain field is better to use sequences and use seq_name.nextval each time you need.
    Regards,

  • How to find sql server backup was taken under compression mode

    Hello,
    How to find SQL server backup was taken under compression mode ? I have disabled the Compress Mode backup setting but I want to make sure the backup is taken without compression.
    Is there a script for that?
    Thanks
    JK

    I have disabled the Compress Mode backup
    That is only a default setting, in backup command you can always overwrite it to a different value.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • How to Capture  sql statement

    we have 1 server oracle and many clients.
    when client sends sql statement to server.How to Capture sql statement to analysis berfore it sent to server and execution.
    Edited by: 955185 on Aug 27, 2012 4:22 AM

    955185 wrote:
    yes. how to do this?Check these link all of them talking about Already executed sql in database by Users , but i don't know if what you ask is possible since they already connect to database
    If you attending to analysis sql read the below links and start your analysis,
    Last executed sql
    http://www.databasejournal.com/features/oracle/article.php/3373701/Watching-SQL-Execute-on-Oracle---Part-I.htm
    http://stackoverflow.com/questions/55899/how-to-see-the-actual-oracle-sql-statement-that-is-being-executed

  • How to find out is my phone lock or unlock

    How to find out is my phone lock or unlock

    Put in a sim from another wireless carrier. Does the receipt say
    unlocked?

Maybe you are looking for

  • Fixed lenght file and row separator

    Hi experts. Im using open data set and close datd set commands to create a text file in background. It is separated by comma.when a field is blank it just displays , , . I want the file to be a fixed length file. I want to see as many spaces as the l

  • Cannot Open Adobe Reader X/XI

    Currently experiencing issues with Adobe Reader X/XI.  Organization wide problem. Adobe Reader X/XI is not starting/opening at all. Information: Adobe Reader X/XI 64-Bit with update 11.0.0.5 Windows 7 Event Viewer doesn't show any application error l

  • Oracle DB Can't Survive ZFS SA Controller Failover

    We are running two new Sparc T4-1 servers against a ZFS SA with two heads and a single DE2-24P disk shelf. It is configured with a single pool for all the storage. Our servers are clustered with VCS as an active/passive pair, so only one server acces

  • Photos not syncing with iPod touch

    I've been having a weird problem when syncing photos with both 2G, 3G and 4G iPod touches for the last 8 months or so. Photos that that were taken in a portrait (vertical) orientation using my Canon camera (and synced with iPhoto - currently at v. 8.

  • IMac goes to sleep running Civilization 3 game

    I recently had my mac serviced by Apple under the extended warranty program (for display/power supply recall). Since then, when I play Civ 3 for about 20-30 minutes, it goes to sleep. After a while I can resume (wake up) as normal and everthing is fi