【问题标题】:SQL command stuck for only one table in postgresSQL 命令只卡在 postgres 中的一张表上
【发布时间】:2016-07-07 13:56:26
【问题描述】:

SQL 命令在 postgres 中只卡在一张表上

我在使用 postgres 数据库的 django 项目中工作。

SQL 查询适用于所有表,但不适用于 common_designprofilecontent

工作

reader=# SELECT COUNT(*) FROM  common_document;
 count 
-------
 20046
(1 row)

不工作

reader=# SELECT COUNT(*) FROM  common_designprofilecontent;

此查询没有结果,此表中至少存在 20046 * 4 行。


执行以下操作后:

reader=# select * from pg_stat_activity;

5:30 | 2016-03-21 10:22:27.240863+05:30 | 2016-03-21 10:22:28.614431+05:30 | t       | SELECT "common_designprofilecontent"."id", "common_designprofil
econtent"."page_id", "common_designprofilecontent"."doc_id", "common_designprofilecontent"."profilename", "common_designprofilecontent"."profileconten
t", "common_designprofilecontent"."page_rev_no", "common_designprofilecontent"."createdDate", "common_designprofilecontent"."createdAgent_id", "common
_designprofilecontent"."modifiedDate", "common_designprofilecontent"."modifiedAgent_id" FROM "common_designprofilecontent" WHERE "common_designprofile
content"."doc_id" = 26952 
 16440 | reader        |   28783 |       10 | postgres | vacuumdb         |             |                 |          -1 | 2016-03-19 23:37:15.579589+0
5:30 | 2016-03-19 23:37:15.581737+05:30 | 2016-03-19 23:37:15.581737+05:30 | t       | VACUUM (FULL, ANALYZE);                                        



                                   +

日志文件/var/log/pgsql中也没有任何内容

【问题讨论】:

  • 没有结果是什么意思?绞刑?只是空结果?并且由于某种原因有一个完全真空运行,这可能会阻塞一些东西。
  • 如果你重启 postgres 你能重现这个问题吗?
  • @SamiKuhmonen:挂了..我不知道真空。
  • @spicyramen:我重新启动了 postgres,但还是同样的问题。
  • 请关闭这个问题。在 SO 上徘徊的“不知道如何”问题毫无意义。

标签: mysql django postgresql


【解决方案1】:

Django 在处理大表时可能会很棘手,我尝试过原始 SQL 查询,但它们在 django 上似乎效果不佳。我认为对您来说最简单和最快的选择是使用 count

x = pg_stat_activity.objects.all()
x.count()

len(x)

len 更快...

【讨论】:

    猜你喜欢
    • 2012-05-31
    • 2013-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 2013-06-10
    • 1970-01-01
    • 2022-11-04
    相关资源
    最近更新 更多