how to quickly analyze a postgres database

Go To StackoverFlow.com

3

I have a postgres database that I want to know some quick stats. For instance, which tables are taking up the most space? I don't need anything fancy, command line is all I need. What is a good tool for this?

2012-04-04 20:00
by priestc


4

The functions you want are here:

http://www.postgresql.org/docs/current/interactive/functions-admin.html#FUNCTIONS-ADMIN-DBSIZE

A quick query to find the top 20 tables in terms of space usage might look like this:

SELECT oid::regclass, pg_size_pretty(pg_total_relation_size(oid))
  FROM pg_class
  WHERE relkind = 'r'
  ORDER BY pg_total_relation_size(oid) DESC
  LIMIT 20;
2012-04-04 20:19
by kgrittn


2

From the client program psql, "\l" will list databases, add a "+" to also show the sizes: "\l+". Also, "\dt+" will give you information on specific table sizes.

2012-04-05 00:30
by coder_tim


1

Interesting question. I think you can query the information using psql. Here are few pointers.

http://securfox.wordpress.com/2009/09/02/how-to-find-the-postgresql-database-size/ and http://heatware.net/databases/find-postgresql-database-size-using-sql-select/ .

Hope this helps.

Thanks, Shankar

2012-04-04 20:11
by Shankar
Ads