Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

In PostgreSQL 8.4.9 with pgbouncer 1.3.4 in pool_mode = session (but some users connect to the database directly) - when I login as "super user" with

   psql -U postgres -W postgres

What is the command please to disconnect all "normal users" and prevent them from connecting again while I perform maintenance (I'd like to rename some table columns for more consistent naming and correspondingly change some stored procedures).

I can't find it in the III. Server Administration doc.

Or should I edit pg_hba.conf and restart the service/process?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

There isn't one, as far as I'm aware -- and I don't see the value in it. PgSQL gives you the ability to modify the database structure live, and in many cases all within a single transaction.

The hard part in any schema migration is having the users of the database know that they have to change the way they use the database (modifying code that calls the database, rewriting documentation, re-training users who execute manual, ad-hoc queries). Preventing users from connecting while you're doing the maintenance doesn't help with that, because they're just going to do things the old way when you allow them to reconnect. If you're able to do a lock-step migration of all users of the database at the same time as the maintenance, then you'd also be able to tell them all to stop using the database while you fiddle with it anyway.

share|improve this answer

Kicking them off should be as easy as something like:

SELECT pg_terminate_backend( psa.procpid )
    FROM pg_stat_activity psa
    JOIN pg_user u
    ON u.usesysid = psa.usesysid
    WHERE psa.procpid <> pg_backend_pid( )
        AND psa.datname = current_database( )
        AND u.usename NOT IN ('list', 'of', 'users', 'to', 'not', 'disconnect')
;

You could combine that with either revoke connect on <datname> from <role> or editing pg_hba.conf...

ref: "How do I detach all other users from a postgres database?"

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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