{"id":368,"date":"2024-06-13T14:03:45","date_gmt":"2024-06-13T14:03:45","guid":{"rendered":"http:\/\/77interactive.com\/?p=368"},"modified":"2024-06-14T16:49:49","modified_gmt":"2024-06-14T16:49:49","slug":"postgresql-locks","status":"publish","type":"post","link":"http:\/\/77interactive.com\/?p=368","title":{"rendered":"PostgreSQL Locks"},"content":{"rendered":"\n<p>The following script displays PostgreSQL locks<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \n    pid,\n    usename,\n    application_name,\n    client_addr,\n    locktype,\n    mode,\n    granted,\n    relation::regclass AS relation_name,\n    page,\n    tuple,\n    virtualxid,\n    transactionid,\n    classid,\n    objid,\n    objsubid,\n    virtualtransaction,\n    backend_start,\n    query\nFROM \n    pg_locks l\nJOIN \n    pg_stat_activity a \nON \n    l.pid = a.pid\nORDER BY \n    relation_name, \n    locktype, \n    mode;\n<\/code><\/pre>\n\n\n\n<p>The following lists blocking activity<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>WITH blocking_info AS (\n    SELECT\n        blocked_locks.pid AS blocked_pid,\n        blocked_activity.usename AS blocked_user,\n        blocking_locks.pid AS blocking_pid,\n        blocking_activity.usename AS blocking_user,\n        blocked_activity.query AS blocked_query,\n        blocking_activity.query AS blocking_query,\n        blocking_activity.application_name AS blocking_application,\n        blocking_activity.client_addr AS blocking_client,\n        blocked_activity.application_name AS blocked_application,\n        blocked_activity.client_addr AS blocked_client\n    FROM\n        pg_catalog.pg_locks blocked_locks\n    JOIN\n        pg_catalog.pg_stat_activity blocked_activity ON blocked_activity.pid = blocked_locks.pid\n    JOIN\n        pg_catalog.pg_locks blocking_locks ON blocking_locks.locktype = blocked_locks.locktype\n        AND blocking_locks.database IS NOT DISTINCT FROM blocked_locks.database\n        AND blocking_locks.relation IS NOT DISTINCT FROM blocked_locks.relation\n        AND blocking_locks.page IS NOT DISTINCT FROM blocked_locks.page\n        AND blocking_locks.tuple IS NOT DISTINCT FROM blocked_locks.tuple\n        AND blocking_locks.virtualxid IS NOT DISTINCT FROM blocked_locks.virtualxid\n        AND blocking_locks.transactionid IS NOT DISTINCT FROM blocked_locks.transactionid\n        AND blocking_locks.classid IS NOT DISTINCT FROM blocked_locks.classid\n        AND blocking_locks.objid IS NOT DISTINCT FROM blocked_locks.objid\n        AND blocking_locks.objsubid IS NOT DISTINCT FROM blocked_locks.objsubid\n    JOIN\n        pg_catalog.pg_stat_activity blocking_activity ON blocking_activity.pid = blocking_locks.pid\n    WHERE\n        NOT blocked_locks.granted\n)\nSELECT\n    blocked_pid,\n    blocked_user,\n    blocking_pid,\n    blocking_user,\n    blocked_query,\n    blocking_query,\n    blocked_application,\n    blocked_client,\n    blocking_application,\n    blocking_client\nFROM\n    blocking_info\nORDER BY\n    blocked_pid;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following script displays PostgreSQL locks The following lists blocking activity<\/p>\n","protected":false},"author":1,"featured_media":376,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[17,18],"class_list":["post-368","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-postgresql","tag-postgres","tag-postgresql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PostgreSQL Locks - 77 Interactive<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/77interactive.com\/?p=368\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL Locks - 77 Interactive\" \/>\n<meta property=\"og:description\" content=\"The following script displays PostgreSQL locks The following lists blocking activity\" \/>\n<meta property=\"og:url\" content=\"http:\/\/77interactive.com\/?p=368\" \/>\n<meta property=\"og:site_name\" content=\"77 Interactive\" \/>\n<meta property=\"article:published_time\" content=\"2024-06-13T14:03:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-06-14T16:49:49+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/77interactive.com\/wp-content\/uploads\/2024\/06\/Bear_keys-1024x576.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"576\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Rudy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rudy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/77interactive.com\/?p=368#article\",\"isPartOf\":{\"@id\":\"http:\/\/77interactive.com\/?p=368\"},\"author\":{\"name\":\"Rudy\",\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9\"},\"headline\":\"PostgreSQL Locks\",\"datePublished\":\"2024-06-13T14:03:45+00:00\",\"dateModified\":\"2024-06-14T16:49:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/77interactive.com\/?p=368\"},\"wordCount\":13,\"image\":{\"@id\":\"http:\/\/77interactive.com\/?p=368#primaryimage\"},\"thumbnailUrl\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2024\/06\/Bear_keys.png\",\"keywords\":[\"postgres\",\"postgresql\"],\"articleSection\":[\"PostgreSQL\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/77interactive.com\/?p=368\",\"url\":\"http:\/\/77interactive.com\/?p=368\",\"name\":\"PostgreSQL Locks - 77 Interactive\",\"isPartOf\":{\"@id\":\"http:\/\/77interactive.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/77interactive.com\/?p=368#primaryimage\"},\"image\":{\"@id\":\"http:\/\/77interactive.com\/?p=368#primaryimage\"},\"thumbnailUrl\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2024\/06\/Bear_keys.png\",\"datePublished\":\"2024-06-13T14:03:45+00:00\",\"dateModified\":\"2024-06-14T16:49:49+00:00\",\"author\":{\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9\"},\"breadcrumb\":{\"@id\":\"http:\/\/77interactive.com\/?p=368#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/77interactive.com\/?p=368\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/77interactive.com\/?p=368#primaryimage\",\"url\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2024\/06\/Bear_keys.png\",\"contentUrl\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2024\/06\/Bear_keys.png\",\"width\":1771,\"height\":997,\"caption\":\"Bear with keys\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/77interactive.com\/?p=368#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/77interactive.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL Locks\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/77interactive.com\/#website\",\"url\":\"http:\/\/77interactive.com\/\",\"name\":\"77 Interactive\",\"description\":\"Rudy&#039;s Code snippets\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/77interactive.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9\",\"name\":\"Rudy\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g\",\"caption\":\"Rudy\"},\"url\":\"http:\/\/77interactive.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PostgreSQL Locks - 77 Interactive","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/77interactive.com\/?p=368","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL Locks - 77 Interactive","og_description":"The following script displays PostgreSQL locks The following lists blocking activity","og_url":"http:\/\/77interactive.com\/?p=368","og_site_name":"77 Interactive","article_published_time":"2024-06-13T14:03:45+00:00","article_modified_time":"2024-06-14T16:49:49+00:00","og_image":[{"width":1024,"height":576,"url":"http:\/\/77interactive.com\/wp-content\/uploads\/2024\/06\/Bear_keys-1024x576.png","type":"image\/png"}],"author":"Rudy","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rudy","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/77interactive.com\/?p=368#article","isPartOf":{"@id":"http:\/\/77interactive.com\/?p=368"},"author":{"name":"Rudy","@id":"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9"},"headline":"PostgreSQL Locks","datePublished":"2024-06-13T14:03:45+00:00","dateModified":"2024-06-14T16:49:49+00:00","mainEntityOfPage":{"@id":"http:\/\/77interactive.com\/?p=368"},"wordCount":13,"image":{"@id":"http:\/\/77interactive.com\/?p=368#primaryimage"},"thumbnailUrl":"http:\/\/77interactive.com\/wp-content\/uploads\/2024\/06\/Bear_keys.png","keywords":["postgres","postgresql"],"articleSection":["PostgreSQL"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/77interactive.com\/?p=368","url":"http:\/\/77interactive.com\/?p=368","name":"PostgreSQL Locks - 77 Interactive","isPartOf":{"@id":"http:\/\/77interactive.com\/#website"},"primaryImageOfPage":{"@id":"http:\/\/77interactive.com\/?p=368#primaryimage"},"image":{"@id":"http:\/\/77interactive.com\/?p=368#primaryimage"},"thumbnailUrl":"http:\/\/77interactive.com\/wp-content\/uploads\/2024\/06\/Bear_keys.png","datePublished":"2024-06-13T14:03:45+00:00","dateModified":"2024-06-14T16:49:49+00:00","author":{"@id":"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9"},"breadcrumb":{"@id":"http:\/\/77interactive.com\/?p=368#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/77interactive.com\/?p=368"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/77interactive.com\/?p=368#primaryimage","url":"http:\/\/77interactive.com\/wp-content\/uploads\/2024\/06\/Bear_keys.png","contentUrl":"http:\/\/77interactive.com\/wp-content\/uploads\/2024\/06\/Bear_keys.png","width":1771,"height":997,"caption":"Bear with keys"},{"@type":"BreadcrumbList","@id":"http:\/\/77interactive.com\/?p=368#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/77interactive.com\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL Locks"}]},{"@type":"WebSite","@id":"http:\/\/77interactive.com\/#website","url":"http:\/\/77interactive.com\/","name":"77 Interactive","description":"Rudy&#039;s Code snippets","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/77interactive.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9","name":"Rudy","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/77interactive.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g","caption":"Rudy"},"url":"http:\/\/77interactive.com\/?author=1"}]}},"_links":{"self":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts\/368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=368"}],"version-history":[{"count":0,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts\/368\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/media\/376"}],"wp:attachment":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=368"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}