大网数据广告活动
服务器运维问答

How to change Postgresql database from Read-only to Writable

· 52CE 我爱测

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…

问题原文

原帖链接 · hdr · CC BY-SA 3.0

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.

已采纳解答

原帖链接 · Craig Ringer · CC BY-SA 3.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-09-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。