Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start psql with read-only transactions by default

My goal is to start the psql client with read-only transactions as the default. I can get this behaviour my manually setting default_transaction_read_only once psql has started (e.g. SET default_transaction_read_only TO on), but I don't want to have to do that.

Theoretically this seems like it should work:

psql --set=default_transaction_read_only=on mydb myuser

But it doesn't, probably due to the caveat mentioned here:

These assignments are done during a very early stage of start-up, so variables reserved for internal purposes might get overwritten later.

Is there a way to do this, ideally with a single command line invocation?

like image 987
overthink Avatar asked Oct 17 '25 21:10

overthink


1 Answers

Probably with ALTER ROLE ... SET ..., or could put that in your ".psqlrc".

like image 127
Milen A. Radev Avatar answered Oct 19 '25 11:10

Milen A. Radev