O'Reilly logo

PostgreSQL 9 Administration Cookbook - Second Edition by Simon Riggs, Gianni Ciolli, Hannu Krosing, Gabriele Bartolini

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Killing a specific session

Sometimes, the only way to let the system continue as a whole is by surgically terminating some offending database sessions. Yes, you read it right—surgically. You might indeed be tempted to reboot the server, but you should think of that as a last resort in a business continuity scenario.

In this recipe, you will be learning how to intervene, from gracefully canceling a query to brutally killing the actual process from the command line.

How to do it…

You can either run this function as a superuser or, when using PostgreSQL 9.2 or newer versions, with the same user as that of the offending backend (look for the usename field in the pg_stat_activity view).

Once you have figured out the backend you need to kill, use the function ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required