0

I set streaming replication in postgresql 9.3. I have one master and 3 slaves and replication works fine.

But when i restart the master server and login using postgres database, pg_stat_replication does not show replication details immediately. It takes several seconds ( around 5 seconds ) show replication details .

I want to know why this happens ? whether it's problem with pg_stat_replication ?

I want to make sure replication start as soon as server starts .

  • Before streaming replication can start, the server must replay any existing WAL and reach a restartpoint. There's no way around that. It isn't clear why you care about the delay. After all, there's always some delay between asking the server to start up and it actually starting. Perhaps you want it not to accept queries until it's caught up? If so, that's a different matter. Please explain what the actual problem you are trying to solve is here. Why do you care? What problem is it causing? – Craig Ringer Aug 13 '14 at 4:27
  • This is actually for learning. My thought was, when server started it will be ready to accept queries, and then after few seconds server start streaming replication. I though data will be lost in those few seconds. There's no specific requirements. Just trying to understand the replication. – Viraj Aug 13 '14 at 5:40
  • If i want to disable accepting queries until streaming replication start, is there a way to do it ? – Viraj Aug 13 '14 at 5:41
1

I want to make sure replication start as soon as server starts .

You can't. The server needs to start up, and it can only establish a streaming replication connection when it's up and ready.

I want to know why this happens

Because there's no reason not to accept connections before streaming replication begins.

Among other things, if you're using WAL shipping instead of streaming replication, there might be no replication connection to wait for. Even if you're using streaming, you probably want the replica to keep on serving results if it loses its connection to the master.

My thought was, when server started it will be ready to accept queries, and then after few seconds server start streaming replication. I though data will be lost in those few seconds.

It isn't.

The server is in recovery mode. Attempts to perform read/write queries will be rejected. This is the case whether or not there's a streaming replication connection.

After all, a server in hot standby mode that uses only a restore_command (no streaming replication) also rejects read/write queries.

You don't need to take any special action.

(In future, please try to include the background, the underlying problem, in your questions, so there's less guesswork and back and forth).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.