Disable trigger effects in PostgreSQL I have a function where there is:

alter table a disable trigger trig1;
some code
alter table a enable trigger trig1;


It basicaly disables the trigger for the purpose of specific operations.

My question is:

What will happen if at the same time the trigger is disabled, another user from another session makes operations on a which relies on that trigger to be triggered?
ALTER TABLE ... DISABLE TRIGGER ... takes a SHARE ROW EXCLUSIVE lock. So no relevant concurrent operation can happen on the table:


  DISABLE/ENABLE ... TRIGGER
  
  This command acquires a SHARE ROW EXCLUSIVE lock.


where the docs on lock levels say that:


  SHARE ROW EXCLUSIVE
  
  ... This mode protects a table against concurrent data changes, and is self-exclusive so that only one session can hold it at a time.


Despite the name, a SHARE ROW EXCLUSIVE lock is a table-level lock. The name is historical.

Now, PostgreSQL has a mechanism you can (ab)use to skip triggers firing on certain operations. It's intended for replication tools like Slony-I and Londiste, and is called session_replication_role. Be aware that using it for other purposes may have "surprising" consequences if you then start using a logical replication tool.