Postgres Table Sizes

Sometimes it’s handy to know the tables in your DB that are taking up the most space. Here’s a quick query that returns the table names and pages used in descending order:


SELECT table_name, relpages
FROM information_schema.TABLES
INNER JOIN pg_class
ON relname=table_name
WHERE table_schema='public'
ORDER BY relpages DESC

 

The reason for the join on the information schema is to limit the results to just the tables you created. If you just use pg_class, then you also get the sizes of indexes and views including the postgres owned objects.

Leave a Comment

Blender Project

I’m sharing a few notes here on some work I’m doing with Blender. The task is to model some physical objects that we control in Blender and then autogenerate a lot of information that we can use to make a simulator for testing our controller, the data used by the controller and the scada monitoring system.

Yesterday I downloaded the beta version of Blender as it has a revised GUI and python API which I think will make my life much easier. Using the example in the API Intro I was able to quickly make a custom panel that displays the name of the currently selected object.

The next cab off the rank is to connect to our configuration database and pull out any records that we have configured for our blender model. Specifically we want to assign a class to this model which describes how it is controlled and that in turn will enable us to pull up a list of configuration variables.

To do this I started by installing the python-pygresql package for ubuntu and reading a tutorial on Linux Journal. The first derailment was almost immediate:

import pgdb
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
ImportError: No module named pgdb
 

After a few googles I was led to understand that blender has a bundled version of python with limited built in modules. To use the full power of python I had to install the version that python was bundled with natively on my system and then compile in any modules I wanted for that version. Looking at the console for blender, it gave the version as 3.1.2.

I managed to find a python3 package in ubuntu’s synaptic package manager and installed that but this made no difference so I ended up leaving a message on the blender forums which is where I’m leaving things for today.

UPDATE: The solution to the hurdle of not being able to load the pgdb module from blender is documented on the linked forum post but here is the summary:


1) The pgdb module is python 2.6 only
2) I had to compile an alternative module py-postgresql from source as there are no .deb packages that work with python3
3) py-postgresql installed ok but the install script left the read permissions as root-only. Python reported that the module didn’t exist which I guess is a generic way of saying it couldn’t read the module library files.

I also misunderstood the way blender interacts with the system python version. It seems to always run the bundled version of python but you can add the search paths using PYTHONPATH so that it will load external modules you have installed yourself. As long as the python versions are close, the modules will load ok.

Once I had py-postgresql installed correctly, I was able to set PYTHONPATH to include /usr/local/lib/python3.1/dist-packages/ and import py-postgresql and connect to my database from there.

Comments (1)