SchemaSpy is a neat tool to produce visual diagrams for most relational databases.
Here's how to use it to generate schema relationship diagrams for PostgreSQL databases:
-
Download the jar file from here (the current version is schemaSpy_5.0.0.jar)
-
Get the PostgreSQL JDBC driver (either the JDBC3 or JDBC4 jar file is fine)
-
Run the command against an existing database. For most databases, the schema (-s option) we are interested in is the public one:
java -jar schemaSpy_5.0.0.jar -t pgsql
-s public -db [db name] -u [db user] -p [password]
-host localhost -o /tmp
-dp /path/to/JDBC/driver/postgresql-9.4-1200.jdbc4.jar
The above example sends all the output to the <tt>/tmp</tt> folder, but that can be changed as desired.
SchemaSpy produces several different diagrams, but the main summary diagram is in:
<tt>/tmp/diagrams/summary/relationships.real.large.png</tt>.