0

If I want to drop a PostgreSQL DB I get this error:

postgres@server:~$ dropdb c123_d
dropdb: database removal failed: ERROR:  
        database "c123_d" is being accessed by other users
DETAIL:  There is 1 other session using the database.

I know how to help myself. I can do select * from pg_stat_activity; and see what is still running.

In my case it was a LISTEN.

Is there a way to mark the LISTEN-statement or this session as "unimportant"? In this context this means that the DB is allowed to kill this statement if the database should get shut-down or dropped.

Is there a way to tell PostgreSQL this?

2

1 Answer 1

1

Is there a way to mark the LISTEN-statement or this session as "unimportant"?

Unimportant to you? Perhaps.

Unimportant to Postgres? No.

Every connection is as "important" as every other.

If you want to kill off an active connection, look to the pg_cancel_backend function.

1
  • Great if postgres thinks every session is important by default. Sad, that there is no way to tell postgres that this is a server waiting for ever in a LISTEN (and kill it, if you are told to drop the db).
    – guettli
    Sep 6, 2018 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.