Wednesday, 19 August 2009

How to reverse engineer PostgreSQL database

On Ubuntu/Kubuntu download postgresql-autodoc module:

$ sudo apt-get install postgresql-autodoc
or install it from source:
$ wget
$ tar -xvfz postgresql_autodoc-1.40.tar.gz
$ cd postgresql_autodoc
$ sudo make install

Now run postgresql-autodoc with an appropriate database connection:
$ postgresql_autodoc -h localhost -p 5432 -d lasma -U lasma

This will generate a bunch of files containing your database schema.
Further you may use GraphViz dot utility to make a neat diagram in vector or raster format.
$ sudo apt-get install graphviz
$ dot -Tdia -o output_lasma.dia #output dia diagram
$ dot -Tpng -o output_lasma.png #output png image


Pēteris said...

Šito nezināju, noderēs :)

Lasma Sietinsone said...

Check out pgDesigner for cool GUI tool (for Lunix only)...