I need to delete a database. But the database cannot be deleted due to some active sessions using the database. I then run the command
psql -c "select pg_terminate_backend(procpid) from pg_stat_activity where procpid<> pg_backend_pid() and datname='mydb"
pg_terminate_backend
----------------------
t
t
t
t
(4 rows)
to delete the sessions. However, the sessions come back with different process ids.
psql -c "select * from pg_stat_activity where datname='mydb';"
datid | datname | procpid | usesysid | usename | current_query | waiting | xact_start | query_start | backend_start | client_addr | client_port
--------+-------------+---------+----------+-------------+---------------+---------+------------+-------------------------------+-------------------------------+-------------+-------------
220030 | mydb | 25454 | 189669 | myname | <IDLE> | f | | 2018-05-17 15:13:04.741252-05 | 2018-05-17 15:12:12.480389-05 | ::1 | 59540
220030 | mydb | 25475 | 189669 | myname | <IDLE> | f | | 2018-05-17 15:13:04.903452-05 | 2018-05-17 15:12:12.559564-05 | ::1 | 59542
220030 | mydb | 25639 | 189669 | myname | <IDLE> | f | | 2018-05-17 15:13:04.731736-05 | 2018-05-17 15:12:12.969821-05 | ::1 | 59546
220030 | mydb | 25640 | 189669 | myname | <IDLE> | f | | 2018-05-17 15:13:04.735792-05 | 2018-05-17 15:12:12.984415-05 | ::1 | 59548
(4 rows)
My PostgreSQL is 8.4.20. Why do the connections keep on comming back? How can I completely remove them?