ERROR: cannot execute SELECT in a read-only transaction when connecting to DB

14,854

Solution 1

There are several reasons why you can get this error:

  1. The PostgreSQL cluster is in recovery (or is a streaming replication standby). You can find out if that is the case by running

    SELECT pg_is_in_recovery();
    
  2. The parameter default_transaction_read_only is set to on. Diagnose with

    SHOW default_transaction_read_only;
    
  3. The current transaction has been started with

    START TRANSACTION READ ONLY;
    

    You can find out if that is the case using the undocumented parameter

    SHOW transaction_read_only;
    

If you understand that, but still wonder why you are getting this error, since you are not aware that you attempted any data modifications, it would mean that the application that you use to connect tries to modify something (but pgAdmin shouldn't do that).

In that case, look into the log file to find out what statement causes the error.

Solution 2

This was a bug which is now fixed, Fix will be available in next release.

https://redmine.postgresql.org/issues/3973

If you want to try then you can use Nightly build and check: https://www.postgresql.org/ftp/pgadmin/pgadmin4/snapshots/2019-02-17/

Share:
14,854

Related videos on Youtube

Gilles Groven
Author by

Gilles Groven

Updated on June 04, 2022

Comments

  • Gilles Groven
    Gilles Groven almost 2 years

    When trying to connect to my Amazon PostgreSQL DB, I get the above error. With pgAdmin, I get "error saving properties".

    I don't see why to connect to a server, I would do any write actions?

  • Gilles Groven
    Gilles Groven about 5 years
    But at this stage i am not even connect to the server yet. it when it tries to connect it throws these errors.
  • Laurenz Albe
    Laurenz Albe about 5 years
    Can you try with psql? Can you get the PostgreSQL log file?
  • Gajendra D Ambi
    Gajendra D Ambi over 3 years
    My newly created db is in recovery mode and SHOW transaction_read_only; results in true. How can i set recovery off and read only to false
  • Laurenz Albe
    Laurenz Albe over 3 years
    @GajendraDAmbi How did you create that database? I cannot think of a way to create a database in recovery mode. But I think you should ask a new question for your problem.
  • Gajendra D Ambi
    Gajendra D Ambi over 3 years
    @LaurenzAlbe manually from pgadmin4 but not I got it resolved, I just had to connect to DB first before executing the commands.