0

I am trying to refresh one of our staging databases with the production data. I created a database called pulse_temp and imported the data from production. After this I executed the below command to terminate all the active connections on the pulse database which I want to drop.

SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname= 'pulse';
pg_terminate_backend 
----------------------
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
 t
(90 rows)

Then I executed the below command to rename the current database to a random name.

ALTER DATABASE pulse RENAME TO pulse_temp1;
ERROR:  database "pulse" is being accessed by other users
DETAIL:  There are 90 other sessions using the database.

I am getting the above error even after terminating the sessions.

I even restarted the DB instance but this error seems to persist.

Any thoughts an why it is happening and ways to resolve the issue?

Daniel Vérité
  • 58,074
  • 15
  • 129
  • 156
sanj
  • 3
  • 4

1 Answers1

1

The most plausible explanation would be that a client or a pool of clients is immediately reconnecting.

just before terminating sessions, maybe you should disable new connections. See PostgreSQL: Temporarily disable connections on how to do that.

Daniel Vérité
  • 58,074
  • 15
  • 129
  • 156