Are you able to lock a table outside begin/commit oe end transaction control statement:
pgtst_db=# lock table pgtst_vacuum in exclusive mode;
ERROR: LOCK TABLE can only be used in transaction blocks
pgtst_db=#
Observation: No. As per the postgresql guide as of 30Jan2023, its not possible to lock a table outside a transaction control block.
Note:
Also a commit between begin/end or commit closes the tx and releases any exclusive lock acquired manually like below...
Session 1:
BEGIN
pgtst_db=*# lock table pgtst_vacuum in exclusive mode;
LOCK TABLE
pgtst_db=*# INSERT INTO pgtst_schema.pgtst_vacuum
pgtst_db-*# SELECT i, lpad('TST',mod(i,100),'CHK')
pgtst_db-*# FROM generate_series (20016,20020) s(i);
INSERT 0 5
pgtst_db=*# commit;
COMMIT
pgtst_db=#
Session 2:
pgtst_db=# begin work;
BEGIN
pgtst_db=*# lock table pgtst_vacuum in exclusive mode;
LOCK TABLE <<<< this was acquied as soon as commit is issued. No need of 'commit work;' statement.
pgtst_db=*#
No comments:
Post a Comment