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 stop pg_cron scheduler #352

Open
serpent7776 opened this issue Aug 28, 2024 · 3 comments
Open

Unable to stop pg_cron scheduler #352

serpent7776 opened this issue Aug 28, 2024 · 3 comments

Comments

@serpent7776
Copy link

I'm unable to stop pg_cron scheduler, even after I drop the extension. I also tried to restart the cluster and whole postgres service, but the scheduler is still running.

This is an issue, because it maintains connection to the database. In the case I install the extension to database other than postgres, it effectively prevents me from dropping/renaming the database.

It happened both with background workers and libpq connection.

I'd expect that dropping the extension should stop the scheduler.

I'm running postgresql-16-cron 1.6.4-1.pgdg22.04+1

postgres=# create extension pg_cron;

postgres=# SELECT pid,datname,application_name FROM pg_stat_activity WHERE datname = 'postgres';
  pid  | datname  | application_name  
-------+----------+-------------------
 23807 | postgres | pg_cron scheduler
 26168 | postgres | psql

postgres=# drop extension pg_cron;

postgres=# SELECT pid,datname,application_name FROM pg_stat_activity WHERE datname = 'postgres';
  pid  | datname  | application_name  
-------+----------+-------------------
 23807 | postgres | pg_cron scheduler
 26168 | postgres | psql
@TheOtherBrian1
Copy link

Can you try killing the process?

Get process id

SELECT
  pid as process_id,
  usename as database_user,
  application_name,
  backend_start as when_process_began,
  wait_event_type,
  state,
  query,
  backend_type
FROM pg_stat_activity where application_name ilike 'pg_cron scheduler';

kill process

SELECT pg_terminate_backend(<pid of the process>)

@serpent7776
Copy link
Author

IIRC I tried to kill the backend postgres process, but it was then auto restarted, but I think I used a different query.
I'm not able to check it now, but I will try to check it in few days.

@serpent7776
Copy link
Author

Sorry, I forgot about this. I can successfully kill the cron process, but then a new one is spawned.

postgres> SELECT
   pid as process_id,
   usename as database_user,
   application_name,
   backend_start as when_process_began,
   wait_event_type,
   state,
   query,
   backend_type
 FROM pg_stat_activity where application_name ilike 'pg_cron scheduler';
+------------+---------------+-------------------+-------------------------------+-----------------+--------+-------+------------------+
| process_id | database_user | application_name  | when_process_began            | wait_event_type | state  | query | backend_type     |
|------------+---------------+-------------------+-------------------------------+-----------------+--------+-------+------------------|
| 104195     | postgres      | pg_cron scheduler | 2024-11-26 16:25:15.464989+00 | Extension       | <null> |       | pg_cron launcher |
+------------+---------------+-------------------+-------------------------------+-----------------+--------+-------+------------------+
SELECT 1
Time: 0.007s

postgres> SELECT pg_terminate_backend(104195)
+----------------------+
| pg_terminate_backend |
|----------------------|
| True                 |
+----------------------+
SELECT 1
Time: 0.005s

postgres> SELECT
   pid as process_id,
   usename as database_user,
   application_name,
   backend_start as when_process_began,
   wait_event_type,
   state,
   query,
   backend_type
 FROM pg_stat_activity where application_name ilike 'pg_cron scheduler';
+------------+---------------+-------------------+------------------------------+-----------------+--------+-------+------------------+
| process_id | database_user | application_name  | when_process_began           | wait_event_type | state  | query | backend_type     |
|------------+---------------+-------------------+------------------------------+-----------------+--------+-------+------------------|
| 104412     | postgres      | pg_cron scheduler | 2024-11-26 16:30:04.98081+00 | Extension       | <null> |       | pg_cron launcher |
+------------+---------------+-------------------+------------------------------+-----------------+--------+-------+------------------+
SELECT 1
Time: 0.005s

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

No branches or pull requests

2 participants