Prevent writes on large objects in read-only transactions

From: Yugo NAGATA <nagata(at)sraoss(dot)co(dot)jp>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Prevent writes on large objects in read-only transactions
Date: 2022-05-27 06:30:28
Message-ID: 20220527153028.61a4608f66abcd026fd3806f@sraoss.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

Currently, lo_creat(e), lo_import, lo_unlink, lowrite, lo_put,
and lo_from_bytea are allowed even in read-only transactions.
By using them, pg_largeobject and pg_largeobject_metatable can
be modified in read-only transactions and the effect remains
after the transaction finished. Is it unacceptable behaviours,
isn't it?

Also, when such transactions are used in recovery mode, it fails
but the messages output are not user friendly, like:

postgres=# select lo_creat(42);
ERROR: cannot assign OIDs during recovery

postgres=# select lo_create(42);
ERROR: cannot assign TransactionIds during recovery

postgres=# select lo_unlink(16389);
ERROR: cannot acquire lock mode AccessExclusiveLock on database objects while recovery is in progress
HINT: Only RowExclusiveLock or less can be acquired on database objects during recovery.

So, I would like propose to explicitly prevent such writes operations
on large object in read-only transactions, like:

postgres=# SELECT lo_create(42);
ERROR: cannot execute lo_create in a read-only transaction

The patch is attached.

Regards,
Yugo Nagata

--
Yugo NAGATA <nagata(at)sraoss(dot)co(dot)jp>

Attachment Content-Type Size
prevent_lo_writes_in_readonly.patch text/x-diff 4.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kyotaro Horiguchi 2022-05-27 06:37:35 Re: [BUG] Panic due to incorrect missingContrecPtr after promotion
Previous Message Amit Langote 2022-05-27 06:22:38 Re: doc phrase: "inheritance child"