11

I'm new to managing servers, especially postgresql on Ubuntu Server, so bear with me.

I'm trying to synchronize between two databases on two different computers, but I'm not sure what I did wrong, since whatever I tried to do, it seems to have configured the servers into read-only mode.

For example, if I wanted to create a role, I would get:

ERROR: cannot execute CREATE ROLE in a read-only transaction

Or if I want to create a table, I would get an error message:

ERROR: cannot execute CREATE TABLE in a read-only transaction.

I have no idea what to do here, so advice on how to resolve this issue is greatly appreciated.

I'm running PostgreSQL version 9.1 on Ubuntu Server 12.04 for by the way.

hdr
  • 193
  • 2
  • 2
  • 10

3 Answers3

17

Since SELECT pg_is_in_recovery() is true you're connected to a read-only replica server in hot_standby mode. The replica configuration is in recovery.conf.

You can't make it read/write except by promoting it to a master, at which point it will stop getting new changes from the old master server. See the PostgreSQL documentation on replication.

First step is to check whether there is a 'recovery.conf' file in the data directory. If it exists, if you are sure you are on master (not slave) server, rename that file to 'recover.conf.backup'. Then, re-start postgresql server. It should allow you to write new records now.

Craig Ringer
  • 11,525
1

if it's an RDS instance cluster, check your endpoint and use the Writer instance endpoint.

AditYa
  • 131
0

if you did what i did - you made the database read only and then forgot what you did to get it there.

alter database xyzzy set default_transaction_read_only = 'off';

i tried several times without the word "default" in the variable name.