在PostgreSQL的小表上ALTER查询非常慢

编程入门 行业动态 更新时间:2024-10-28 04:22:09
本文介绍了在PostgreSQL的小表上ALTER查询非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有PostgreSQL 9.2和一个很小的数据库,其中只有一个种子数据用于我正在工作的网站。

I've got PostgreSQL 9.2 and a tiny database with just a bit of seed data for a website that I'm working on.

以下查询似乎永远运行:

The following query seems to run forever:

ALTER TABLE diagnose_bodypart ADD description text NOT NULL;

diagnose_bodypart 是一个小于10的表行。我让查询运行了超过一分钟没有任何结果。可能是什么问题呢?有任何调试建议吗?

diagnose_bodypart is a table with less than 10 rows. I've let the query run for over a minute with no results. What could be the problem? Any recommendations for debugging this?

推荐答案

添加列不需要重写表(除非您指定默认)。这是没有任何锁的快速操作。正如Craig所指出的那样,pg_locks是检查的地方。

Adding a column does not require rewriting a table (unless you specify a DEFAULT). It is a quick operation absent any locks. pg_locks is the place to check, as Craig pointed out.

通常,最可能的原因是长时间的事务处理。我将查看哪些工作流正在冲击这些表,以及事务开放的时间。这种锁通常是事务性的,因此提交事务通常可以解决问题。

In general the most likely cause are long-running transactions. I would be looking at what work-flows are hitting these tables and how long the transactions are staying open for. Locks of this sort are typically transactional and so committing transactions will usually fix the problem.

更多推荐

在PostgreSQL的小表上ALTER查询非常慢

本文发布于:2023-10-14 22:52:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492451.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表上   PostgreSQL   ALTER

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!