From a clean Ubuntu 12.04 Precise install I was able to get it to work with this:
echo 'deb http://ppa.launchpad.net/ubuntugis/ppa/ubuntu precise main' | sudo tee -a /etc/apt/sources.list
echo 'deb-src http://ppa.launchpad.net/ubuntugis/ppa/ubuntu precise main' | sudo tee -a /etc/apt/sources.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 314DF160
sudo apt-get update
sudo apt-get install -y postgresql-server-dev-9.1 postgis python-mapscript python-gdal
For more up-to-date gis packages use the unstable repository
echo 'deb http://ppa.launchpad.net/ubuntugis/ubuntugis-unstable/ubuntu precise main' | sudo tee -a /etc/apt/sources.list
echo 'deb-src http://ppa.launchpad.net/ubuntugis/ubuntugis-unstable/ubuntu precise main' | sudo tee -a /etc/apt/sources.list
This also works for Ubuntu 14.04 Trusty, just replace precise
with trusty
when adding the ubuntugis repos. Then you can also install postgres 9.3 instead of 9.1. So on Trusty use:
sudo apt-get install -y postgresql-server-dev-9.3 postgis python-mapscript python-gdal
The two references for installing this I used were
http://trac.osgeo.org/ubuntugis/wiki/UbuntuGISRepository
https://launchpad.net/~ubuntugis/+archive/ubuntu/ppa/
Also, if you want to use the postgis raster driver through mapscript, it is worth trying to install the latest GDAL version, as it has essential improvements on the raster driver (its much faster and more stable). So in that case I would recommend the unstable repo, in my work so far I did not run into problems due to the "unstable" name.
Best Answer
OGR method, courtesy of this page:
Another way: Adapted from here. Doesn't use ogr but it does let you access the data a bit more easily IMHO.
If you're doing this in qgis, you might want to look at Load a specific spatial data from a postGIS table or Load PostGIS layer/table to QGIS canvas using Python .