Skip to content

Instantly share code, notes, and snippets.

@jpinnix
Forked from dpapathanasiou/SchemaSpy-HOWTO.md
Created September 22, 2021 19:00
Show Gist options
  • Save jpinnix/8aa8a39c63bb3fc4890116ec4e0e6e87 to your computer and use it in GitHub Desktop.
Save jpinnix/8aa8a39c63bb3fc4890116ec4e0e6e87 to your computer and use it in GitHub Desktop.
How to use SchemaSpy to generate the db schema diagram for a PostgreSQL database

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:

  1. Download the jar file from here (the current version is v6.1.0)

  2. Get the PostgreSQL JDBC driver (unless your installed version of java is really old, use the latest JDBC4 jar file)

  3. 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-6.1.0.jar -t pgsql \
  -s public -db [db name] -u [db user] -p [password] \
  -host localhost -o /tmp \
  -dp /path/to/JDBC/driver/postgresql-42.2.12.jar

The above example sends all the output to the /tmp folder, but that can be changed as desired.

SchemaSpy produces several different diagrams, but the main summary diagram is in:

/tmp/diagrams/summary/relationships.real.large.png.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment