Have you ever restarted your PostgreSQL cluster and wondered why it’s taking so long? The cause of this is generally one of these:
- You didn’t include the “-m fast” flag (v9.4 and earlier), and sessions are still connected
- A large update query is rolling back
- There are a large number of dirty blocks, which are not yet written to disk
If you run a manual “CHECKPOINT” immediately prior to running the shutdown, then you can sometimes drastically shorten the time a restart takes:
postgres@localhost[default:5432] ~/$ psql -c CHECKPOINT && pg_ctl restart -m fast