Skip to content

Instantly share code, notes, and snippets.

@dpapathanasiou
Last active February 17, 2024 19:45
Show Gist options
  • Star 51 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save dpapathanasiou/c9c6236a410e9d018ae0 to your computer and use it in GitHub Desktop.
Save dpapathanasiou/c9c6236a410e9d018ae0 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.

@salmagomaa
Copy link

Thank you so much!

@jpinnix
Copy link

jpinnix commented Sep 22, 2021

Thank you so much! Super helpful.

@autra
Copy link

autra commented Jan 30, 2024

Thank you! Is there a way to generate documentation on a database spanning multiple schemas?

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