What lock, if any, does 'CREATE TRIGGER' use in PostgreSQL 9.4.2

最后都变了- 提交于 2019-12-07 23:59:35

问题


according to postgres-xl, CREATE TRIGGER uses the SHARE ROW EXCLUSIVE lock, but according to the official Postgres docs for SHARE ROW EXCLUSIVE:

This lock mode is not automatically acquired by any PostgreSQL command.


回答1:


You're comparing Postgres-XL with the main PostgreSQL documentation. Two different products, albeit with a shared history. Postgres-XL has lots of changes from stock PostgreSQL.

CREATE TRIGGER should be listed in the Pg docs and isn't, though, and that's an oversight.

A quick look at the source code shows that CREATE TRIGGER takes a ShareRowExclusiveLock, so in this case XL's documentation matches PostgreSQL's behaviour.

You could check this yourself without looking at the sources by doing something like this:

CREATE TABLE test();

CREATE OR REPLACE FUNCTION dummy_tg() RETURNS TRIGGER
LANGUAGE plpgsql AS $$ BEGIN END; $$;

BEGIN;

CREATE TRIGGER blah BEFORE INSERT ON test FOR EACH ROW EXECUTE PROCEDURE dummy_tg();

\x

SELECT * FROM pg_locks 
WHERE pid = pg_backend_pid() 
AND relation = 'test'::regclass;

ROLLBACK;

... which shows that I was wrong about my reading of the sources, because:

locktype | relation
mode     | AccessExclusiveLock

it took an AccessExclusiveLock.



来源:https://stackoverflow.com/questions/33902679/what-lock-if-any-does-create-trigger-use-in-postgresql-9-4-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!