Postgres: drop foreign key constraint query getting stuck

北慕城南 提交于 2021-01-29 09:52:17

问题


I wanted to remove all foreign key constraints from a schema. I was successful in dropping constraints from most of the tables but in few of them drop foreign key constraint query is getting stuck.

ALTER TABLE table_name DROP CONSTRAINT fkey_name;

I tried truncate cascade but it was also getting stuck. I deleted all rows from both the tables manually. Still getting stuck.

Edits: By getting stuck I mean query continues running for long time without any error message even though tables are empty.


回答1:


Check for any dead locks using

SELECT * FROM pg_stat_activity;

If any then kill and run below sql,and then drop using

SELECT pg_terminate_backend(pid);

If Not solved check for any virtual transaction

SELECT database, gid FROM pg_prepared_xacts;

Rollback using

ROLLBACK PREPARED 'gid';



来源:https://stackoverflow.com/questions/53873800/postgres-drop-foreign-key-constraint-query-getting-stuck

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!