【Hacker News搬运】Postgres锁定资源管理器
-
Title: Postgres locks explorer
Postgres锁定资源管理器
Text:
Url: https://leontrolski.github.io/pglockpy.html
标题:leontrolski - Postgres 锁定 作者:未提供 发布日期:未提供 顶部图片链接:无 文本内容: 详细信息/来源 - Postgres 表级锁定文档 - Postgres 行级锁定文档 - django-pg-zero-downtime-migrations - 此页面中的所有数据都来自这些测试,因此根据某种定义是真实的。 - 值得注意的是这个测试 - 对于任意 SQL 语句,它通过运行时检查确定所采取的锁定。 总结:该页面提供了关于 Postgres 数据库锁定机制的信息,包括表级锁定和行级锁定的文档链接,以及一个测试工具,该工具可以检测任意 SQL 语句所采取的锁定。这些信息对于理解 Postgres 数据库的锁定行为以及优化数据库操作可能很有帮助。
Post by: leontrolski
Comments:
frenchie4111: This is very cool, thank you. You should add this to <a href="https://github.com/dhamaniasad/awesome-postgres">https://github.com/dhamaniasad/awesome-postgres</a>
frenchie4111: 这很酷,谢谢。您应该将其添加到<a href=“https://;/;github.com#xx2F;dhamaniasad/!真棒postgres”>https:///;github.com/;dhamaniasad;了不起的postgres</a>
peter_l_downs: This is pretty cool as background information, but if you've ever run into a situation where you're not sure why something is locking, this kind of theoretical info isn't that helpful. If you want to know what queries to kill, and what's blocked on what, check out these two very helpful Postgresql wiki pages:<p>- <a href="https://wiki.postgresql.org/wiki/Lock_Monitoring" rel="nofollow">https://wiki.postgresql.org/wiki/Lock_Monitoring</a><p>- <a href="https://wiki.postgresql.org/wiki/Lock_dependency_information" rel="nofollow">https://wiki.postgresql.org/wiki/Lock_dependency_information</a><p>The "Recursive view of blocking" on the second page has been extremely helpful to me. You don't ever want to need this query but if you do, it's great. You should follow the page's recommendation and set it up as a view you can use if shit ever hits the fan.<p>...although you may want to show all the locks each pid has acquired, instead of the summary the query gives as written, by modifying it to use<p><pre><code> array_to_string(locks_acquired, E'\n')
</code></pre>
instead of<p><pre><code> array_to_string(locks_acquired[1:5] ||
CASE WHEN array_upper(locks_acquired,1) > 5
THEN '... '||(array_upper(locks_acquired,1) - 5)::text||' more ...'
END,
E'\n ')</code></pre>peter_l_downs: 这作为背景信息非常酷,但如果您;我曾经遇到过这样的情况:;不确定为什么有东西被锁定,这种理论信息是不确定的;这没什么帮助。如果你想知道要终止哪些查询;在什么方面被阻止了,请查看这两个非常有用的Postgresql wiki页面:<p>-<a href=“https://;/;wiki.Postgresql.org//!wiki/:Lock_Monitoring”rel=“nofollow”>https:///;wiki.postgresql.org/;wiki/;Lock_Monitoring</a><p>-<a href=“https://;/;wiki.postgresql.org//:wiki/,Lock_dependency_info”rel=“nofollow”>https:///;wiki.postgresql.org/;wiki/;锁定依赖信息</a><p>;阻塞的递归视图“;第二页对我非常有帮助;我从来都不想需要这个查询,但如果你需要,它;太棒了。您应该按照页面;的推荐,并将其设置为一个视图,如果大便击中了风扇,你可以使用它<</p>尽管您可能希望显示每个pid获取的所有锁,而不是查询所写的摘要,方法是将其修改为使用<p><pre><code>array_to_string(lock_acquired,E;\n;)</code></pre>而不是<p><pre><code>array_to_string(lock_acquired[1:5]||CASE WHEN array_uper(lock_acquired,1)>;5.然后'||(array_uper(lock_acquired,1)-5)::text||;更多x27;结束,E;\n-)</代码></pre>
cfchou360: Thanks! Very useful tool. Another one I often use is <a href="https://postgres-locks.husseinnasser.com/" rel="nofollow">https://postgres-locks.husseinnasser.com/</a>
cfchou360: 谢谢非常有用的工具。我经常使用的另一个是<a href=“https://;/;postgres-locks.husseinasser.com/”rel=“nofollow”>https:///;postgres locks.husseinasser.com/</一