Skip to main content
Question

Untangling locks using system or DC tables

  • July 12, 2019
  • 6 replies
  • 9 views

Bryan_H
Forum|alt.badge.img+2

I told a customer about using locks, dc_lock_requests and dc_lock_releases to get info about locks. Their response: "Is there a single query that will show me both the blocking and blocker info along with the detail lock information?" I'm not aware of one, but figured I'd post here in case someone has a query they could use for their reporting or dashboard. Thanks!

6 replies

Vertica_Curtis
Forum|alt.badge.img+1
  • Participating Frequently
  • July 12, 2019

I could write some queries for this, probably, but I need a way to reliably create a lock in the system so I can test it. I'm aware that there's a way to do this, but I can't find anything on it. Anyone know a way?


skeswani
Forum|alt.badge.img
  • Participating Frequently
  • July 15, 2019

CREATE LOCAL TEMPORARY TABLE lock_gantt ON COMMIT PRESERVE ROWS AS
select dc_lock_attempts.node_name,
dc_lock_releases.object_name,
dc_lock_releases.mode,
dc_lock_releases.transaction_id,
(dc_lock_attempts.start_time-mv_offset)second(5) lock_attempt,
(dc_lock_releases.grant_time-mv_offset)second(5) lock_grant,
(dc_lock_releases.time-mv_offset)second(5) lock_releases,
(dc_lock_releases.time-grant_time)second(5) hold_time,
(grant_time-dc_lock_attempts.time)second(5) wait_time,
concat(
concat(
concat(
lpad ('', ((dc_lock_attempts.start_time-mv_offset)second(0)/scale)::int ,' '),
lpad ('', ((grant_time-dc_lock_attempts.time)second(0)/scale)::int ,'.')),
rpad('|', ((dc_lock_releases.time-grant_time)second(0)/scale)::int, 'x')),
'|') chart
from dc_lock_releases join dc_lock_attempts on
dc_lock_releases.node_name = dc_lock_attempts.node_name
and dc_lock_releases.object_name = dc_lock_attempts.object_name
and dc_lock_releases.transaction_id = dc_lock_attempts.transaction_id
and dc_lock_releases.object = dc_lock_attempts.object
and dc_lock_releases.session_id = dc_lock_attempts.session_id
and dc_lock_releases.user_id = dc_lock_attempts.user_id
and dc_lock_releases.mode = dc_lock_attempts.mode
and dc_lock_attempts.start_time <= dc_lock_releases.grant_time
and dc_lock_releases.grant_time <= dc_lock_attempts.time
cross
join (
select min(time) mv_offset,
'20'::int scale
from dc_lock_attempts
) MinVal
where
-- dont care about locks held for less than 1 second
(dc_lock_releases.time-grant_time)second(5) > interval '1 second'
order by 1,4,5;
\o chart.gantt
select node_name, transaction_id, object_name, mode, chart from lock_gantt where node_name in ('node001') order by node_name, lock_attempt, lock_grant;
\o
! cat chart.gantt


skeswani
Forum|alt.badge.img
  • Participating Frequently
  • July 15, 2019

'20'::int scale

increase the scale so it can fit in a 64K col


Bryan_H
Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • July 15, 2019

Hi, I sent this to the customer and will see if it meets their needs. Thanks again!


Bryan_H
Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • July 16, 2019

@Jim_Knicely @skeswani Could we turn this into a Vertica tip public post, maybe with example output? This would probably help customers and staff debug certain issues around long-running concurrent queries. Thanks!


skeswani
Forum|alt.badge.img
  • Participating Frequently
  • July 16, 2019

yes, certainly. By all means.
The problem with the above sql is there is no good way to select scale and the duration of locks to ignore (in this case 1 sec). Different users care about different aspects of it. I struggled with make the scale a function of duration.

And perhaps as predicate to look at locks within the last hour or two would be a good enhancement. I can add this shortly, i expect it to be a trivial change.