A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label slow. Show all posts
Showing posts with label slow. Show all posts

Faster count(*) in postgres

For an approximate count you can do:

SELECT reltuples FROM pg_class WHERE oid = 'schema_name.table_name'::regclass;

(replacing schema_name and table_name)

(source)

Find and kill slow postgres queries


SELECT query_start,datname,procpid,current_query FROM pg_stat_activity;
SELECT NOW();

SELECT pg_cancel_backend($PID);
-- where $PID is the number from the procpid column in the first query