Is there a way to see what locks a stored procedure obtains? I would like to run a stored procedure, and obtain an analysis of all the locks that it took while running. Is there a way to do that? If not automatically, then is there a resource that will explain to me how to figure it out statically?
I'm running Postgresql 9.4 but am open to solutions that only work in newer versions since we're planning to upgrade.
Stored procedures don't acquire locks. Queries do. But you can't really detect which query obtained a lock. You can only see which session/transaction is holding a lock.