I have created a procedure that returns an event trigger:
Whenever an ALTER TABLE
occurs SELECT
is granted on all sequences on all tables to a specific user.
During restore of the db the above fails in some occasions with a tuple concurrently updated error:
[2024-04-25T15:55:23.586Z] pg_restore: error: pg_restore:could not execute query: ERROR: tuple concurrently updated
[2024-04-25T15:55:23.586Z] CONTEXT: SQL statement "GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO ..."
[2024-04-25T15:55:23.586Z] PL/pgSQL function xxx.fake_sth() line 13 at SQL statement
[2024-04-25T15:55:23.586Z] Command was: ALTER TABLE ONLY public.table_name
[2024-04-25T15:55:23.586Z] ADD CONSTRAINT constraint_name PRIMARY KEY (id);
[2024-04-25T15:55:23.586Z]
[2024-04-25T15:55:23.586Z]
I read that there is no lock mechanism regarding catalog tables. So I assume that ALTER
triggers the execution of the function and the grant fails because a lock is held by the ALTER
on the pg_class
table and the grant fails as it needs to acquire a lock on pg_class
table.
Is there a way to overcome this?
I thought of acquiring a lock immediately before the GRANT statement but on rds permission is denied. Is there another way of achieving this?