属性编号10超过列数0

时间:2014-03-05 08:08:16

标签: postgresql postgresql-9.1

此查询成功返回表中的所有行(大约850+):

select * from my_db_log
 where date_trunc('day',creation_date) >= to_date('2014-03-05'::text,'yyyy-mm-dd');

但是当我使用如下相同的查询添加count(*)时:

select count(*) from my_db_log
 where date_trunc('day',creation_date) >= to_date('2014-03-05'::text,'yyyy-mm-dd');

然后它回报我:

********** Error **********

ERROR: attribute number 10 exceeds number of columns 0
SQL state: XX000

仅供参考:creation_date是我桌子的第10列。

有趣的是,当我用count(*)替换count(id)时,它会返回0,但我的表中有符合条件的记录。

编辑:我在整个数据库上尝试了vacuumdb命令,但它仍不适用于我。以下是此特定表中vacuumdb的详细输出。

>vacuumdb --full --analyze -h 192.168.1.10 -p 8888 -U root -W --verbose --table my_db_log my_db
Password:

输出:

INFO:  vacuuming "public.my_db_log"
INFO:  "my_db_log": found 0 removable, 0 nonremovable row versions in 0 pages
DETAIL:  0 dead row versions cannot be removed yet.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO:  analyzing "public.my_db_log"
INFO:  "my_db_log": scanned 0 of 0 pages, containing 0 live rows and 0 dead rows; 0 rows in sample, 0 estimated total rows

1 个答案:

答案 0 :(得分:1)

数据库中存在某些问题。尝试

VACCUM FULL ANALYZE my_db_log;

或者,从根本上说,从数据库服务器上的shell运行:

vacuumdb --full --analyze my_database

Details in the manual.

错误消息表示系统目录pg_attribute或其中一个关联索引中的破坏。在您做任何其他事情之前,请阅读corruption in the Postgres Wiki。小心不要丢失有价值的数据 Then one other thing to try:

reindexdb --system my_database

如果没有任何帮助,为了修复明显损坏的数据库,您可以尝试pg_dumpall整个群集,删除群集,创建新群集并恢复备份。还要确保找出破坏数据库的内容。这通常不会发生(从未发生在我身上)。有可能,您面临严重的硬件问题,在这种情况下您需要尽快采取行动......

相关问题