-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Make SIGINT default stopsignal #714
Comments
I'm confused, and I'm not sure we're reading the same documentation (or perhaps we're interpreting it differently). From the link you've listed (https://www.postgresql.org/docs/11/server-shutdown.html):
vs:
(emphasis mine, on both) From my reading, In my opinion, this makes more sense as documentation changes, because it sounds like what's happening is that |
I see your point. If you run this container in a Kubernetes setup, it may not be able to complete, for example due to applications using persistent connections, or very long queries. This will result in Kubernetes killing the container altogether. This results in a much less graceful shutdown, and occasion can actually lead to data corruption. Because Therefore one could argue that |
I believe |
@tianon 2 minutes won't be enough if your application keeps database connections open, or if you have a connection pooler between your application and PG. The problem with |
The parts you bolded out in the documentation for SIGINT like aborting transactions are bad, but these are all things the clients can and should handle. After all, transactions can fail for other reasons too, and backups can fail for all sorts of reasons. The postgres container on the other hand cannot do anything to make sure it gets shut down properly with SIGTERM. There is nothing stopping clients from keeping connections open, and then if eventually the container gets SIGKILL, Postgres has no chance to clean anything up. This can lead to data-corruption. I think that the primary duty of the postgres container should be to make sure the postgres container gets shutdown properly, without any data loss. Whether transactions get stopped gracefully is a secondary concern imho. Also note that if the Postgres container gets SIGKILL, then all the bad things from SIGINT still happen, just x seconds later. Now above I wrote that 'there is nothing stopping clients from keeping connections open'. Thing is: the clients don't even know that the postgres container has received SIGTERM and they should disconnect (in typical setups). Of course there are all sorts of notification mechanisms possible, but that would be incredibly complex, and then whether Postgres correctly saves its data before shutting down is still in the hands of the clients. Settings |
Is there anyone who thinks, this proposed change should NOT be made? -- I guess, as this is a breaking change, it must be documented (where?) and should only be applied to new versions of postgres e.g. the upcoming 13 release? |
Yes, that's why this issue is still open and under discussion instead of closed/fixed. |
@tianon alright, thank you for the quick response. -- I would like to add another argument for changing the default stopsignal. I looked up what the default stopsignal is, when you install postgres under systemd. The offical postgres documentation suggests to use |
Also, in our case we have no control (as in: its not our app, we can not change the source code) over the application using the postgres database. We cant control whether or not the client application will close the db connections when the database server must shut down. The biggest problem is, that the client application has no way to know that the database server will be shut down. So the client has no way to stop whatever it is doing. Our specific case:
|
This is the winning argument 😄 The setting from the service file of the package we install also corroborates this: $ docker pull postgres
Using default tag: latest
latest: Pulling from library/postgres
Digest: sha256:91462e8207eadf217fe72822163277d189215b1f3792719f29352de5beb0ad53
Status: Image is up to date for postgres:latest
docker.io/library/postgres:latest
$ docker run --rm postgres grep 'ExecStop' /lib/systemd/system/postgresql@.service
ExecStop=/usr/bin/pg_ctlcluster --skip-systemctl-redirect -m fast %i stop (That |
As far as I see, this can be closed, because it has been already merged: bfc5d81 |
Yes, this can be closed afaik. Thanks for fixing this 👏 Wasn't sure whether the issue creator should close issues, so left this open. Will close now |
See: - docker-library/postgres#714 Fixes #492
This is directly related to these issue that were (IMHO incorrectly) closed:
There is a misconception that sending "SIGTERM is more graceful". Generally that is true, however considering how Postgres interprets signals (https://www.postgresql.org/docs/11/server-shutdown.html), that simply doesn't guarantee to shutdown Postgres cleanly.
According to the docs the only way to guarantee a graceful shutdown without dataloss is using
SIGINT
.Note that in a lot of production environments (e.g. in Kubernetes clusters) containers might be stopped at unexpected moments using the default signal, and in a lot of those environments connections to the server will not be closed by the clients in time (since they generally don't know the server is shutting down). Ergo, there are a lot of production setups in which the default image is not usable because it will lead to corrupted data.
I'd be happy to create a PR for this, but I have a feeling that some discussion is needed first.
The text was updated successfully, but these errors were encountered: