Pushing users off the system

Sometimes, we may need to remove groups of users from the database server for various operational reasons. Here's how.

How to do it…

You can terminate a user's session with the pg_terminate_backend() function included with PostgreSQL. That function takes the PID, or the process ID, of the user's session on the server. This process is known as the backend, and it is a different system process from the program that runs the client.

Note

Some of the columns used in this recipe had a different name in version 9.1 and before:

  • pid was called procpid
  • query was called current_query

The queries in this recipe are written for PostgreSQL 9.4, the most recent stable version at the time of writing this book. They work without changes ...

Get PostgreSQL 9 Administration Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.