Monitoring PG fast shutdown

143 Views Asked by At

I have a PG running inside the docker container. When I try to stop the PG using a fast shutdown, sometimes it gets stuck and takes a lot of time.

Is there a good way to track the progress of fast shutdown from outside the container? I need to see how it is progressing.

Documentation of fast shutdown: https://www.postgresql.org/docs/current/server-shutdown.html

SIGINT
This is the Fast Shutdown mode. The server disallows new connections and sends all existing server processes SIGTERM, which will cause them to abort their current transactions and exit promptly. It then waits for all server processes to exit and finally shuts down.

I need to track the progress of all the existing server processes when they receive the SIGTERM. and if they are stuck, why they are stuck.

I have been thinking of trapping the SIGINT signal and echoing out this information, so that it can show up in docker logs. But I do not want to re-invent the wheel if I can get this information from some place else.

1

There are 1 best solutions below

0
Laurenz Albe On

You cannot monitor this, short of tracing all PostgreSQL processes. If a fast shutdown takes a long time, one of the server processes must be slow in reacting to the shutdown request. You can easily identify the process with ps. One thing you can do is attach to it with a debugger and see what it is doing.

If a normal PostgreSQL activity does not react to an interrupt promptly, that is a bug. However, extensions loaded into PostgreSQL might also be the problem, if they define functions that don't check for interrupts recently.

For more help, you should attach to the hanging process with a debugger, take a stack trace and add it to the question.