IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Administration Oracle Discussion :

Retrouver le nom d'un utilisateur qui a verrouillé une ligne


Sujet :

Administration Oracle

  1. #1
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut Retrouver le nom d'un utilisateur qui a verrouillé une ligne
    Salut,
    j'aimerais savoir comment retrouver le nom de l'utilisateur ayant verrouillé une ligne dans une table ?

    Merci

    Oracle 9.2

  2. #2
    Rédacteur

    Inscrit en
    Septembre 2004
    Messages
    626
    Détails du profil
    Informations forums :
    Inscription : Septembre 2004
    Messages : 626
    Points : 848
    Points
    848
    Par défaut qui bloque qui ?
    Bonjour,


    Je pense que vous cherchez ca :

    select b.username est_bloque, b.sid, b.serial#, d.username bloqueur, d.sid, d.serial#
    from v$lock a, v$session b, v$lock c, v$session d
    where a.type = 'TX' and
    a.request = 6 and
    a.sid = b.sid and
    a.id1 = c.id1 and
    a.id2 = c.id2 and
    c.sid = d.sid and
    c.request = 0



    Cordialement,

    Laly.
    In the heart of the truly greats, perfection is never achieved but endlessly pursued.

    Mon article sur les fonctions analytiques d'Oracle (calcul de moyennes mobiles, de quartiles et bien d'autres...)

  3. #3
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Merci,
    cela fonctionne si on exécute la requête suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    select col,col2 from table for update
    J'ai oublié de préciser que je recherche cette info dans le cas ou j'effectue la requête suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    select col,col2 from table for update NOWAIT
    Dans ce cas ta solution ne fonctionne plus car les vues système ne semblent pas mémoriser ces infos.

  4. #4
    Rédacteur

    Inscrit en
    Septembre 2004
    Messages
    626
    Détails du profil
    Informations forums :
    Inscription : Septembre 2004
    Messages : 626
    Points : 848
    Points
    848
    Par défaut
    Bonjour,


    Pour moi ca fonctionne bien :

    Session 1 :
    select * from t for update nowait

    Session 2
    update t set x = 3 -> la session est bloqué

    Et quand j'exécute ma requête je vois bien la ligne correspondante...

    Est-ce-que j'ai bien compris ton scénario ? Quel est le résultat de la requête pour toi ?


    Cordialement,

    Laly.
    In the heart of the truly greats, perfection is never achieved but endlessly pursued.

    Mon article sur les fonctions analytiques d'Oracle (calcul de moyennes mobiles, de quartiles et bien d'autres...)

  5. #5
    Expert éminent sénior
    Avatar de orafrance
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    15 967
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 15 967
    Points : 19 073
    Points
    19 073
    Par défaut
    Citation Envoyé par Laurent Dardenne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    select col,col2 from table for update NOWAIT
    Dans ce cas ta solution ne fonctionne plus car les vues système ne semblent pas mémoriser ces infos.
    bah oui... NOWAIT -> pas de lock... ou est le probléme ?

  6. #6
    Rédacteur

    Inscrit en
    Septembre 2004
    Messages
    626
    Détails du profil
    Informations forums :
    Inscription : Septembre 2004
    Messages : 626
    Points : 848
    Points
    848
    Par défaut
    Je suis pas d'accord avec toi : select ... for update NOWAIT : on veut verrouiller la ligne, si la ligne est déjà verrouillé renvoie immédiatement un message d'erreur au lieu de rester bloqué, sinon on a verrouillé la ligne.


    Laly.
    In the heart of the truly greats, perfection is never achieved but endlessly pursued.

    Mon article sur les fonctions analytiques d'Oracle (calcul de moyennes mobiles, de quartiles et bien d'autres...)

  7. #7
    Expert éminent sénior
    Avatar de orafrance
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    15 967
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 15 967
    Points : 19 073
    Points
    19 073
    Par défaut
    houla oui, tu as raison les vendredis sont difficiles

    Et que donne cette requête ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    select   substr(a.os_user_name,1,8)    "OS User" 
     , substr(a.oracle_username,1,8) "DB User" 
           , substr(b.owner,1,8)  "Schema" 
     , substr(b.object_name,1,20)    "Object Name" 
        , substr(b.object_type,1,10)    "Type" 
        ,a.session_id "SID"
    from v$locked_object      a 
         , all_objects b 
    where   a.object_id =  b.object_id 
    and object_name = '&table'

  8. #8
    Expert éminent sénior
    Avatar de orafrance
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    15 967
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 15 967
    Points : 19 073
    Points
    19 073
    Par défaut
    En voila une autre plus "jolie"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    col sid for 999 head ' |sid'
    col id1 for 9999999 head 'resource|ID 1'
    col id2 for 999999 head 'res.|ID 2'
    col command for 999 head 'command|num'
    col held for a4 head 'mode|held'
    col req for 9990 head 'mode|req'
    col osuser for a8 head 'unix|username'
    col username for a6 head 'oracle|user'
    col objname for a26 head 'object name|ID1'
    col  type for a4 head 'lock|type'
    select s.username,s.osuser,l.sid,l.type,
      decode(l.lmode,0,'NONE',1,'NULL',2,'RS',3,'RX',4,'S',5,'SRX',6,'X','?') held,
      decode(l.request,0,'NONE',1,'NULL',2,'RS',3,'RX',4,'S',5,'SRX',6,'X','?') req,
      l.id1,l.id2,nvl(o.object_name,'NONE') objname
    from v$lock l,v$session s,sys.dba_objects o
    where l.sid=s.sid 
      and l.id1=o.object_id(+)
      and o.object_name = '&objet'
      and s.username is not null
    /* and l.type in ('TM','TX','UL') */
    order by l.id1,l.id2,l.sid
    /

  9. #9
    Membre actif Avatar de Nounoursonne
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    264
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 264
    Points : 208
    Points
    208
    Par défaut
    Bonjour,

    j'ai le meme soucis

    un user 1 fait :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    select chps1 from table 1 where cond1 for update nowait;
    ==> la ligne est verrouillée

    un user 2 fait :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    select chps1 from table 1 where cond1 for update nowait;
    la ligne n'est pas verrouillée
    Mais comment indiqué à user 2 que c'est user 1 qui le bloque ?

  10. #10
    Membre régulier
    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    64
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 64
    Points : 73
    Points
    73
    Par défaut
    Il faut traper le code erreur en retour ( 'ressource busy' )

  11. #11
    Membre actif Avatar de Nounoursonne
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    264
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 264
    Points : 208
    Points
    208
    Par défaut
    ben ça ne marche pas
    voici le code que j'utilise :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
    declare
         ligne_verrouillee exception;
         pragma exception_init (ligne_verrouillee,-54);
         str varchar2(100);
    begin
         select champs1 into str
         from table1
         where champs1='1'
         for update nowait;
     
    exception when ligne_verrouillee Then
     
         select b.username ||' Bloqué par : '|| d.username
         into str
         from v$lock a, v$session b, v$lock c, v$session d 
         where a.type = 'TX' and 
         a.request = 6 and 
         a.sid = b.sid and 
         a.id1 = c.id1 and 
         a.id2 = c.id2 and 
         c.sid = d.sid and 
         c.request = 0;
     
         dbms_output.Put_line(str);
    ENd;
    Je precise que la ligne que j'essaies de verrouiller l'est déjà par une autre session.
    La requete qui est censée me donner le bloqueur me retourne un No_Data_Found

    Any idea ?

  12. #12
    Rédacteur

    Inscrit en
    Septembre 2004
    Messages
    626
    Détails du profil
    Informations forums :
    Inscription : Septembre 2004
    Messages : 626
    Points : 848
    Points
    848
    Par défaut
    Bonjour,


    Bien sur ca marche pas, puisque tu n'es pas bloqué :wink:

    Tu peux essayer ca alors mais il faut vérifier dans la doc quand est acquis un lock TM :
    select 'est bloqué par ' || username
    from v$session
    where sid in (
    select sid from v$lock where id1 = (select object_id from user_objects where object_name = 'maTable')
    )

    Laly.
    In the heart of the truly greats, perfection is never achieved but endlessly pursued.

    Mon article sur les fonctions analytiques d'Oracle (calcul de moyennes mobiles, de quartiles et bien d'autres...)

  13. #13
    Membre actif Avatar de Nounoursonne
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    264
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 264
    Points : 208
    Points
    208
    Par défaut
    le probleme c'est que plusieurs users bloquent plusieurs ligne differentes mais sur la meme table

  14. #14
    Membre confirmé

    Profil pro
    Inscrit en
    Juin 2004
    Messages
    487
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2004
    Messages : 487
    Points : 455
    Points
    455
    Par défaut
    Je ne sais pas si cela pourra vous aider, mais voici une requête qui montre qui bloque qui à travers les verrous

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
     
     
    select
      s.sid "SID",
      s.serial# "SER",
      o.object_name "Table",
      o.owner,
      s.osuser "OS User",
      s.machine "Node",
      s.terminal "Terminal",
      --p.spid "SPID",
      --s.process "CPID",
      decode (s.lockwait, null, 'Have Lock(s)', 'Waiting for <' || b.sid || '>') "Mode",
      substr (c.sql_text, 1, 150) "SQL Text"
    from v$lock l,
      v$lock d,
      v$session s,
      v$session b,
      v$process p,
      v$transaction t,
      sys.dba_objects o,
      v$open_cursor c
    where l.sid = s.sid
      and o.object_id (+) = l.id1
      and c.hash_value (+) = s.sql_hash_value
      and c.address (+) = s.sql_address
      and s.paddr = p.addr
      and d.kaddr (+) = s.lockwait
      and d.id2 = t.xidsqn (+)
      and b.taddr (+) = t.addr
      and l.type = 'TM'
    group by
      o.object_name,
      o.owner,
      s.osuser,
      s.machine,
      s.terminal,
      p.spid,
      s.process,
      s.sid,
      s.serial#,
      decode (s.lockwait, null, 'Have Lock(s)', 'Waiting for <' || b.sid || '>'),
      substr (c.sql_text, 1, 150)
    order by 
      decode (s.lockwait, null, 'Have Lock(s)', 'Waiting for <' || b.sid || '>') desc,
      o.object_name asc,
      s.sid asc;

  15. #15
    Membre régulier
    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    64
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 64
    Points : 73
    Points
    73
    Par défaut
    ça marche chez moi ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    declare
         ligne_verrouillee exception;
         pragma exception_init (ligne_verrouillee,-54);
         str varchar2(100);
    begin
         select champs1 into str
         from table1
         where champs1='1'
         for update nowait;
    exception 
     
    when ligne_verrouillee then
     
         select s.username || ' ' || s.osuser || ' ' || l.sid || ' ' || l.type || ' ' || 
      decode(l.lmode,0,'NONE',1,'NULL',2,'RS',3,'RX',4,'S',5,'SRX',6,'X','?') || ' ' || 
      decode(l.request,0,'NONE',1,'NULL',2,'RS',3,'RX',4,'S',5,'SRX',6,'X','?') || ' ' || 
      l.id1 || ' ' || l.id2 || ' ' || nvl(o.object_name,'NONE')  into str
    from v$lock l,v$session s,sys.dba_objects o
    where l.sid=s.sid
      and l.id1=o.object_id(+)
      and o.object_name = 'ma table'
      and s.username is not null
    /* and l.type in ('TM','TX','UL') */
    order by l.id1,l.id2,l.sid;
     
     
         dbms_output.Put_line(str);     
    ENd;

  16. #16
    Membre actif Avatar de Nounoursonne
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    264
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 264
    Points : 208
    Points
    208
    Par défaut
    je suis d'accord avec toi, mais maintenant si plusieurs user ont posé un verrou sur des lignes differentes de la meme table, comment tu fais ?

  17. #17
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Merci,
    je vais tester vos requêtes.

  18. #18
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Aprés qq essais les requêtes proposées par Aline et Echoes ne régle pas le pb.
    Celle d'Echoes renvoi No_Data_Found:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
     
     
      1   declare
      2        ligne_verrouillee exception;
      3        pragma exception_init (ligne_verrouillee,-54);
      4        str varchar2(100);
      5   begin
      6        select num into str
      7        from fiches
      8        where num ='152337'
      9        for update nowait;
     10   exception
     11  when ligne_verrouillee then
     12    begin
     13       select s.username || ' ' || s.osuser || ' ' || l.sid || ' ' || l.type || ' ' ||
     14    decode(l.lmode,0,'NONE',1,'NULL',2,'RS',3,'RX',4,'S',5,'SRX',6,'X','?') || ' ' ||
     15    decode(l.request,0,'NONE',1,'NULL',2,'RS',3,'RX',4,'S',5,'SRX',6,'X','?') || ' ' ||
     16    l.id1 || ' ' || l.id2 || ' ' || nvl(o.object_name,'NONE')  into str
     17  from v$lock l,v$session s,sys.dba_objects o
     18  where l.sid=s.sid
     19    and l.id1=o.object_id(+)
     20    and o.object_name = 'ma table'
     21    and s.username is not null
     22  /* and l.type in ('TM','TX','UL') */
     23  order by l.id1,l.id2,l.sid;
     24       dbms_output.Put_line(str);
     25   end;
     26* ENd;
    mona@DEV> /
     declare
    *
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at line 13
    ORA-00054: resource busy and acquire with NOWAIT specified

  19. #19
    Membre actif Avatar de Nounoursonne
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    264
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 264
    Points : 208
    Points
    208
    Par défaut
    Je suis dans le meme cas de figure que toi

  20. #20
    Membre régulier
    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    64
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 64
    Points : 73
    Points
    73
    Par défaut
    il faut penser à remplacer "ma table" dans la requête des verrous en "fiches"

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. Réponses: 2
    Dernier message: 25/07/2012, 23h10
  2. Réponses: 0
    Dernier message: 29/09/2010, 11h53
  3. Réponses: 2
    Dernier message: 27/06/2009, 12h54
  4. Réponses: 1
    Dernier message: 02/09/2008, 23h13
  5. [MySQL] Trouver le nom de l'utilisateur qui se connecte(debutant)
    Par Natsume dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 27/10/2006, 13h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo