Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.postgresql.util.PSQLException: ERROR: cannot execute INSERT in a read-only transaction

Tags:

postgresql

I am using PostgreSQL server and suddenly I am getting this error. Due to that, I am not able to insert data into any table.

org.postgresql.util.PSQLException: ERROR: cannot execute INSERT in a read-only transaction

I have checked solution online and found that the default_transaction_read_only parameter needs to be set to off but it is off already.

like image 573
DeepInJava Avatar asked Mar 05 '26 13:03

DeepInJava


1 Answers

Log on to PostgreSQL and verify if your database is in recovery mode or not with below command :-

  • select pg_is_in_recovery();

pg_is_in_recovery() should be false(f)

  • If the above value is true, intimate admin to move the DB out of recovery mode.

Further check if default transaction is read-only or read-write with below command :-

  • show default_transaction_read_only;

default_transaction_read_only must be "off"

  • If the value is not off, run the below command
  • psql -U username -d postgres begin; alter database dbname set default_transaction_read_only = off; commit; \q

If issue persists after performing the above fix, please check on the connection setting and make sure to use hostname rather than host IP in place of jdbcUrl

like image 83
arun Avatar answered Mar 08 '26 02:03

arun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!