From 0901b82588a899a53665d2d6148ea6f14602c111 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Sun, 23 Apr 2017 21:22:54 +0300 Subject: [PATCH] acquire AccessShareLock on parent and children in repack_get_table_and_inheritors() --- lib/repack.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/repack.c b/lib/repack.c index 930fd56..073969c 100644 --- a/lib/repack.c +++ b/lib/repack.c @@ -32,6 +32,7 @@ #include "commands/tablecmds.h" #include "commands/trigger.h" #include "miscadmin.h" +#include "storage/lmgr.h" #include "utils/array.h" #include "utils/builtins.h" #include "utils/lsyscache.h" @@ -1314,7 +1315,14 @@ repack_get_table_and_inheritors(PG_FUNCTION_ARGS) ListCell *lc; int i; - relations = find_all_inheritors(parent, NoLock, NULL); + LockRelationOid(parent, AccessShareLock); + + /* Check that parent table exists */ + if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(parent))) + PG_RETURN_ARRAYTYPE_P(construct_empty_array(OIDOID)); + + /* Also check that children exist */ + relations = find_all_inheritors(parent, AccessShareLock, NULL); relations_array_size = list_length(relations); if (relations_array_size == 0)