-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pglogrepl_demo: how to handle postgres server disconnect #20
Comments
Can you double check that the server is really stopped? This is what I get when I stop my PostgreSQL server.
|
Thank you very much for the response! You were right. This was user error. My apologies. For others that may encounter this issue:
Changing my testing to use postgres within a container (so that when the container terminates, all child processes are terminated) and is much more representative of a netsplit / postgres server termiantion in production, allowed the go program to termiante:
|
Just by running postgres in its official docker container and stopping the container, I get keepalive messages with ReplyRequested set for 10 seconds before the connection actually stops; pg_recvlogical doesn't exhibit the same behavior (it stops immediately, instead), in spite of the logic being pretty much the same between both. How can I diagnose this? |
And of course right as I post here I figure it out - at least on my Postgres 15 setup, you should acknowledge that you've written up to the ServerWALEnd upon receiving a keepalive message so that Postgres doesn't keep the connection open for longer than it's intended: https://github.com/postgres/postgres/blob/881cd9e581c2c40023f82edcd1cd2335691b78f2/src/bin/pg_basebackup/pg_recvlogical.c#L469C13-L469C13 Is this something that should be added to the example code? |
Extremely cool project! Thank you very much for creating it.
I'm a go beginner & I'm trying to learn by using your library to create a toy version of debezium that serializes the logical replication messages to json & writes them to stdout. The demo made it very approachable & easy to get started so thank you again! Its been a fantastic way to learn go.
I've got most of it working except the case when the connection with postgres is broken and I'm not sure how to make forward progress.
If this is the wrong forum to ask this question please let me know.
My desired behavior is that if my program looses connection to the postgres server, I'd like the program to terminate with an error (just like the demo does if it can't connect in the first place). I'm simulating this by simply shutting down the postgres server I'm connected to after the program has successfully connected to the postgres server.
The problem I'm running in to is that I can't figure out how to determine if the connection with postgres is still alive or not and I'm confused because it appears that calls to
conn.ReceiveMessage
are returning successfully immediately, even if the postgres server shut down after connection.I'm observing is that if the postgess server shuts down after the demo has connected, the call to
conn.ReceiveMessage
doesn't return an error (which is what I, probably ignorantly, would have expected), instead it returns immediately with aPrimaryKeepaliveMessage
https://github.com/jackc/pglogrepl/blob/master/example/pglogrepl_demo/main.go#L75.Logs from the demo look like:
Then when I shut down the postgres server the following log is output over & over as the
nextStandbyMessageDeadline
is always in the past &conn.ReceiveMessage
always returns immediately with no error (I don't understand why):So my questions are:
conn.ReceiveMessage
returning a result when the postgres server it is requesting to receive messages from is no longer alive to send messages?I'm using the following versions:
The text was updated successfully, but these errors were encountered: