DELETE PENDING strikes back, via pg_ctl stop/start

Started by Alexander Lakhinalmost 2 years ago2 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliestests failedCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t50143
psql -h localhost -U postgres

Built from patchset v1 (message #1), August 17, 2026 at 09:47 AM.

Jump to latest
#1Alexander Lakhin
exclusion@gmail.com

Hello hackers,

As a recent failure, produced by drongo [1]https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=drongo&dt=2024-08-19%2017%3A32%3A54, shows, pg_ctl stop/start
sequence may break on Windows due to the transient DELETE PENDING state of
posmaster.pid.

Please look at the excerpt from the failure log:
...
pg_createsubscriber: stopping the subscriber
2024-08-19 18:02:47.608 UTC [6988:4] LOG:  received fast shutdown request
2024-08-19 18:02:47.608 UTC [6988:5] LOG:  aborting any active transactions
2024-08-19 18:02:47.612 UTC [5884:2] FATAL:  terminating walreceiver process due to administrator command
2024-08-19 18:02:47.705 UTC [7036:1] LOG:  shutting down
pg_createsubscriber: server was stopped
### the server instance (1) emitted only "shutting down" yet, but pg_ctl
### considered it stopped and returned 0 to pg_createsubscriber
[18:02:47.900](2.828s) ok 29 - run pg_createsubscriber without --databases
...
pg_createsubscriber: starting the standby with command-line options
pg_createsubscriber: pg_ctl command is: ...
2024-08-19 18:02:48.163 UTC [5284:1] FATAL:  could not create lock file "postmaster.pid": File exists
pg_createsubscriber: server was started
pg_createsubscriber: checking settings on subscriber
### pg_createsubscriber attempts to start new server instance (2), but
### it fails due to "postmaster.pid" still found on disk
2024-08-19 18:02:48.484 UTC [6988:6] LOG:  database system is shut down
### the server instance (1) is finally stopped and postmaster.pid unlinked

With extra debug logging and the ntries limit decreased to 10 (in
CreateLockFile()), I reproduced the failure easily (when running 20 tests
in parallel) and got additional information (see attached).

IIUC, the issue is caused by inconsistent checks for postmaster.pid
existence:
"pg_ctl stop" ... -> get_pgpid() calls fopen(pid_file, "r"),
 which fails with ENOENT for the DELETE_PENDING state (see
 pgwin32_open_handle()).

"pg_ctl start" ... -> CreateLockFile() calls
    fd = open(filename, O_RDWR | O_CREAT | O_EXCL, pg_file_create_mode);
which fails with EEXISTS for the same state of postmaster.pid.

[1]: https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=drongo&dt=2024-08-19%2017%3A32%3A54

Best regards,
Alexander

Attachments:

pg_ctl-debugging.patchtext/x-patch; charset=UTF-8; name=pg_ctl-debugging.patchDownload+25-5
regress_log_040_pg_createsubscriber.tar.bz2application/x-bzip; name=regress_log_040_pg_createsubscriber.tar.bz2Download
#2Alexander Lakhin
exclusion@gmail.com
In reply to: Alexander Lakhin (#1)
Re: DELETE PENDING strikes back, via pg_ctl stop/start

21.08.2024 13:00, Alexander Lakhin wrote:

As a recent failure, produced by drongo [1], shows, pg_ctl stop/start
sequence may break on Windows due to the transient DELETE PENDING state of
posmaster.pid.

lorikeet didn't lose it's chance to add two cents to the conversation and
failed on "pg_ctl stop" [1]https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=lorikeet&dt=2024-08-22%2009%3A52%3A46:
waiting for server to shut down........pg_ctl: could not open PID file "data-C/postmaster.pid": Permission denied

I find it less interesting, because Cygwin-targeted code doesn't try to
handle the DELETE PENDING state at all.

I've made a simple test (see attached), which merely executes stop/start
in a loop, and observed that running 10 test jobs in parallel is enough to
get:
### Stopping node "node" using mode fast
# Running: pg_ctl -D .../tmp_check/t_099_pg_ctl_stop+start_node_data/pgdata -m fast stop
waiting for server to shut down....pg_ctl: could not open PID file
".../tmp_check/t_099_pg_ctl_stop+start_node_data/pgdata/postmaster.pid": Permission denied
# pg_ctl stop failed: 256

or
# Running: pg_ctl -D .../tmp_check/t_099_pg_ctl_stop+start_node_data/pgdata -m fast stop
waiting for server to shut down....pg_ctl: could not open PID file
".../tmp_check/t_099_pg_ctl_stop+start_node_data/pgdata/postmaster.pid": Device or resource busy
# pg_ctl stop failed: 256

[1]: https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=lorikeet&dt=2024-08-22%2009%3A52%3A46

Best regards,
Alexander

Attachments:

099_pg_ctl_stop+start.plapplication/x-perl; name=099_pg_ctl_stop+start.plDownload