Skip to content

Commit

Permalink
Add sanity check if both relations are locked in access exclusive mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
MasahikoSawada committed May 21, 2024
1 parent 6e416d0 commit 8f6d0df
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/repack.c
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,24 @@ repack_swap(PG_FUNCTION_ARGS)
CommandCounterIncrement();
}

/*
* Sanity check if both relations are locked in access exclusive mode
* before swapping these files.
*/
#if PG_VERSION_NUM >= 120000
{
LOCKTAG tag;

SET_LOCKTAG_RELATION(tag, MyDatabaseId, oid);
if (!LockHeldByMe(&tag, AccessExclusiveLock))
elog(ERROR, "must hold access exclusive lock on table \"%s\"", relname);

SET_LOCKTAG_RELATION(tag, MyDatabaseId, oid2);
if (!LockHeldByMe(&tag, AccessExclusiveLock))
elog(ERROR, "must hold access exclusive lock on table \"table_%u\"", oid);
}
#endif

/* swap tables. */
swap_heap_or_index_files(oid, oid2);
CommandCounterIncrement();
Expand Down

0 comments on commit 8f6d0df

Please sign in to comment.