PostgreSQL: mark current session as “unimportant”

postgresql

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?

Best Answer

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.