Postgresql数据库表结构异常 ERROR: cache lookup failed for relation

254 阅读1分钟

发生报错环境

表数据量大,为了减轻查询压力,使用了分区表。手动删除分区表后出现了表结果报错,主表无法正常打开。

错误内容:

ERROR: cache lookup failed for relation 63122

操作前先备份表和数据。

排查过程

查看该表内容

database=# \d table_name
ERROR: cache lookup failed for relation 63122

查询资料,表信息都在pg_class 与 pg_depend表中

database=# select relname, oid from pg_class where relname='table_name';
       relname      |  oid
--------------------+-------
     tableb_name    | 78105

删除相关的oid信息

database=# delete from pg_class where oid=63122;
DELETE 1
database=# delete from pg_depend where objid=63122;
DELETE 1

将表相关联的索引,序列和约束都删掉

select oid, relname from pg_class where relname like '%table_name%';

将查询出来该表相关的 ix_table_name_id, table_name_id_seq, table_name_pkey等删除掉

delete from pg_class where oid=9578;
delete from pg_depend where objid=9578;

然后尝试重建表,又报了一个错误

ERROR: type 'table_name' already exists HINT: A relation has an associated type of the same name, so you must use ...

此处应该发现若是表存在的话应该报的错误是

ERROR: relation "table_name" already exists

既然type 已存在, 就将该type删除

下面是在 DROP TYPE的时候还报 cache lookup failed for relation 63122的错误,感觉没有删除干净有查询到pg_depend表的refobjid中存在该id的引用

database=# delete from pg_depend where refobjid=78105;
DELETE 4

最后删除该表TYPE

database=# DROP TYPE table_name;
DROP TYPE

转载至:blog.csdn.net/asd54090/ar…