Skip to content

Instantly share code, notes, and snippets.

@tyagiakhilesh
Last active January 26, 2018 07:33
Show Gist options
  • Save tyagiakhilesh/747cf2471fd1e66c629fda127ae774e6 to your computer and use it in GitHub Desktop.
Save tyagiakhilesh/747cf2471fd1e66c629fda127ae774e6 to your computer and use it in GitHub Desktop.
Postgres maintainance queries
-- Finding open connections
SELECT * FROM pg_stat_activity;
-- Dropping open connections
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = <databasename> AND pid <> pg_backend_pid() AND state in ( 'idle');
-- Describing a table
select column_name, data_type, character_maximum_length from INFORMATION_SCHEMA.COLUMNS where table_name = 'pg_stat_activity';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment