snippetsqlModerate
How to drop inheritance?
Viewed 0 times
inheritancedrophow
Problem
I am new to PostgreSQL. The situation I have is someone created a child table inherits from the parent table. And dropped the child table. But the parent table still has the "down arrow" sign on it.
I checked and there's no other link/relation on the parent table. Is this really an issue?
I was told that the parent table is still in the 'been inherited' status and causing the performance issue. How to resolve this? By removing the 'been inherited' status' from the parent table?
I checked and there's no other link/relation on the parent table. Is this really an issue?
I was told that the parent table is still in the 'been inherited' status and causing the performance issue. How to resolve this? By removing the 'been inherited' status' from the parent table?
Solution
In addition to what @Josh already clarified, this quote from the manual should answer the question in the title:
[...] an inheritance link can be removed from a child using the
Either that or just delete the
Also, you can include all inheriting tables when dropping the parent table using the
A parent table cannot be dropped while any of its children remain.
[...] If you wish to remove a table and all of its descendants, one
easy way is to drop the parent table with the
You can invert this to take advantage of the behaviour and debug your situation. Start a transaction and try to drop the parent table:
The error message lists inheriting tables that block the
Unless you get an error (aborting the transaction automatically), be sure to issue a
[...] an inheritance link can be removed from a child using the
NO INHERIT variant of ALTER TABLE.ALTER TABLE child NO INHERIT parent;Either that or just delete the
child table.Also, you can include all inheriting tables when dropping the parent table using the
CASCADE key word:A parent table cannot be dropped while any of its children remain.
[...] If you wish to remove a table and all of its descendants, one
easy way is to drop the parent table with the
CASCADE option.You can invert this to take advantage of the behaviour and debug your situation. Start a transaction and try to drop the parent table:
BEGIN;
DROP TABLE a;ERROR: cannot drop table a because other objects depend on it
DETAIL: table b depends on table a
HINT: Use DROP ... CASCADE to drop the dependent objects too.
The error message lists inheriting tables that block the
DROP command.Unless you get an error (aborting the transaction automatically), be sure to issue a
ROLLBACK if you don't actually want to delete the table:ROLLBACK;Code Snippets
ALTER TABLE child NO INHERIT parent;BEGIN;
DROP TABLE a;Context
StackExchange Database Administrators Q#44572, answer score: 15
Revisions (0)
No revisions yet.