How to rename database with active sessions

Useful when you need to for example switch databases – you must do it from psql when connected to other database (db postgres is the best choice in this case): restrict further connections into this database: ALTER DATABASE your_old_database CONNECTION LIMIT 0;...

Parallel run of queries / functions / tasks using dblink

PostgreSQL has one problem which limits scalability. One process / session / connection can use only one CPU / core. Therefore if you want / need to run several queries / tasks / functions in parallel you have to use dblink functions to open more parallel connections...

Kill / end connection / session in PostgreSQL

To kill only one connection use this: SELECT pg_terminate_backend( process_id ) where “process_id” is taken FROM pg_stat_activity – procpid in PG 8.4 or pid in PG 9.3   If you need to terminate processes / connections / sessions on some specific...

Show all sessions / connections on PostgreSQL server

Always shows all sessions / connections / processes / activities globally for the server regardless to which database are you connected to. This one shows all processes – also your own connection: select * from pg_stat_activity In PostgreSQL 9.3 result already...