Score:0

How can I still be able to write to primary postgresql while replication is absent?

vn flag

My goal is to let the master server still be able to process write request while standby is in failure. I have noticed synchronous_commit = can be manually set to off and then reload the primary server.

Other configuration includes repmgr.conf for repmgr: use_replication_slots=yes

Therefore the standby server created by repmgr request the primary server to reserve wal-logs for it while it is in failure. Things goes not exactly as expected - I am able to commit writing operation to the primary and the standby is able to clone that from primary, but with a bug - the writing command always stuck here:

postgres=# CREATE DATABASE ANYTHING;

The prompt did not show up again until I pressed Ctrl+D, with these lines:

^CCancel request sent
WARNING:  canceling wait for synchronous replication due to user request
DETAIL:  The transaction has already committed locally, but might not have been replicated to the standby.
CREATE DATABASE
postgres=#

So it always ended up a freeze whenever I tried to write to the primary while its synchronous_commit = off. (psql -c ... will result in a freeze in shell too) This means this temporary change of replication setting does not reach my goal to prevent primary from a "strike" while standby encounters problem!

Is there a way to get around this freeze? Thanks.

Nikita Kipriyanov avatar
za flag
Which Postgres version? If you want to stop synchronous replication temporary *remove the setting* `synchronous_standby_names` (set to empty, the default) in the configuration file and then reload the server. Set it back when standby is ready again (make sure slot retains all the WAL logs for it to catch up, otherwise you'd need to recreate it from scratch). `synchronous_commit` is per-session variable; you shouldn't need to restart server but you have to set it into your session prior to performing transactions.
George Y avatar
vn flag
@Nikita Kipriyanov Thanks for the reply. It is version 15. So the configuration I set in `repmgr`: `use_replication_slots=yes` is essential here? The default behavior for `repmgr` however is `no` use of replication slots.
Nikita Kipriyanov avatar
za flag
It's not essential *here* but it will make your life easier. What is essential is that if you use slots you *have* to monitor your pg_wal directory size; it will grow if slots aren't consumed and can potentially overflow. But this is not the topic of the question.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.