diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 588c1ec536..bad698c125 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -1416,6 +1416,20 @@ ExecuteTruncate(TruncateStmt *stmt) /* find_all_inheritors already got lock */ rel = heap_open(childrelid, NoLock); + + /* + * It is possible that the parent table has children that are + * temp tables of other backends. We cannot safely access + * such tables (because of buffering issues), and the best + * thing to do seems to be to silently ignore them. No point + * in holding onto the lock either. + */ + if (RELATION_IS_OTHER_TEMP(rel)) + { + heap_close(rel, AccessExclusiveLock); + continue; + } + truncate_check_rel(RelationGetRelid(rel), rel->rd_rel); truncate_check_activity(rel);