Skip to content
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

Unable to drop a database when there is an active cron job #318

Closed
Ngalstyan4 opened this issue Apr 1, 2024 · 0 comments · Fixed by #319
Closed

Unable to drop a database when there is an active cron job #318

Ngalstyan4 opened this issue Apr 1, 2024 · 0 comments · Fixed by #319

Comments

@Ngalstyan4
Copy link
Contributor

Ngalstyan4 commented Apr 1, 2024

In PG15 + pg_cron,
when there is a scheduled active cron job, the client is unable to successfully drop any databases, even the ones on which there are no cron jobs.

postgres=# CREATE DATABASE testdb;
CREATE DATABASE
postgres=# SELECT cron.schedule('59 seconds', $$SELECT pg_sleep(5)$$);
 schedule
----------
        5
(1 row)
postgres=# DROP DATABASE testdb;



^CCancel request sent
ERROR:  canceling statement due to user request

When there is at least one active cron job, running DROP DATABASE testdb and canceling as above puts the target testdb into an invalid state.

postgres=# \c testdb;
connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL:  cannot connect to invalid database "testdb"
HINT:  Use DROP DATABASE to drop invalid databases.
Previous connection kept

It seems DROP DATABASE deadlocks with bgworker running in pg_cron. I see the following server log when DROP DATABASE is blocked:

still waiting for backend with PID 93345 to accept ProcSignalBarrier

where the backend with the mentioned PID is the background worker running pg_cron.c:PgCronLauncherMain.

An issue with similar symptoms existed and was fixed in Timescale (timescale/timescaledb#4838)

Similar issue exists in 2ndQuadrant/pglogical#418

it seems calling CHECK_FOR_INTERRUPTS() in the main PgCronLauncher loop fixes the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant