To identify any possible locks we need to query the v_monitor.locks table.
The table contains details about the locking session and it's lock type.
dbadmin=select*fromlocks;-[RECORD1]-----------+--------------------------------------------------------node_names|v_test_node0001object_name|Table:public.test_lockobject_id|45035996273773554transaction_id|45035996273775496transaction_description|Txn:a0000000011388'insert into test_lock values (1);'lock_mode|Ilock_scope|TRANSACTIONrequest_timestamp|2014-04-2216:17:46.537463-03grant_timestamp|2014-04-2216:17:46.537469-03
You can see that I(insert lock) is hold on public.test_lock by the transaction id 45035996273775496.
To see how long the lock is going on use the following query:
To get a complete view of your process that is currently locking an object use the DUMP_LOCKTABLE function.
The function will return information about deadlocked clients and the resources they are waiting for.
dbadmin=SELECTDUMP_LOCKTABLE();DUMP_LOCKTABLE|Transactioninprogress:tid=a0000000011388digraphLock_Wait_Graph{graph[rankdir=BTlabel="nNode 'v_test_node0001' Locktable (1 entries)n(This is a Waits
-For graphnCircles are transactions, Squares are things lockednEdges from Txns to Oids =
= Txn waiting for LocknEdges from Oids to Txns == Lock in use by Txn)nn"labelloc=t]1[label="Table:public.test_lock(a0000000010bf2)"shape=box];2[label="Txn: a0000000011388 'insert into test_lock values (1);'"shape=ellipse];1-2[label="I; TRANSACTION; 2014-04-22 16:17:46.537463-03; 2014-04-22 16:17:46.537469-03"color="orange"];}digraphLock_Wait_Graph{graph[rankdir=BTlabel="nCombined Distributed Lock Graphn(This is a Waits-For graphnCi
rcles are transactions, Squares are things lockednEdges from Txns to Oids == Txn waiting
for LocknEdges from Oids to Txns == Lock in use by Txn)nn"labelloc=t]1[label="Table:public.test_lock(a0000000010bf2)"shape=box];2[label="Txn: a0000000011388 'insert into test_lock values (1);'"shape=ellipse];1-2[label="I; TRANSACTION; 2014-04-22 16:17:46.537463-03; 2014-04-22 16:17:46.537469-03"color="orange"];}
// ]]>
To get a better view of the this crazy code use the copy and paste it into this online Graphviz Api or you
can download the open source software and install it on your machine.
The output should be something like this:
To fix this situation you need to wait for the session to close/commit or you can kill that session using it's transaction_id.
To identify the session_id responssible for the lock you need to query the v_monitor.sessions table.
dbadmin=select*fromsessionswheretransaction_idin(selecttransaction_idfromlocks);-[RECORD1]--------------+-----------------------------------------------------------------------------------node_name|v_test_node0001user_name|dbadminclient_hostname|127.0.0.1:59169client_pid|32583login_timestamp|2014-04-2216:08:16.487623-03session_id|bih001-20862:0x43de2client_label|transaction_start|2014-04-2216:17:46.513285-03transaction_id|45035996273775496transaction_description|userdbadmin(insertintotest_lockvalues(1);)statement_start|2014-04-2216:47:01.657181-03statement_id|67last_statement_duration_us|9434runtime_priority|current_statement|select*fromsessionswheretransaction_idin(selecttransaction_idfromlocks);last_statement|select*fromlocks;ssl_state|Noneauthentication_method|Passwordclient_type|vsqlclient_version|07.00.0000client_os|Linux2.6.32-220.el6.x86_64x86_64-- to kill or close the transactiondbadmin=selectclose_session('bih001-20862:0x43de2');
// ]]>
The v_monitor.sessions table offers us valuable information about our running sessions suck as :