Schemaspy: Useful Database Schema Extraction Source

1---
2title: 'Schemaspy: Useful Database Schema Extraction'
3date: '2014-01-21'
4published_at: '2014-01-21T08:52:00.000+11:00'
5tags: ['development', 'documentation', 'postresql', 'schema', 'schemaspy', 'software engineering', 'sql']
6author: 'Gavin Jackson'
7excerpt: 'Sometimes it''s nice to visualise a pre-existing database (particularly when a new staff member joins the team and you need to walk them through your database). I came across a useful open source tool...'
8updated_at: '2014-01-21T08:52:12.892+11:00'
9legacy_url: 'http://www.gavinj.net/2014/01/schemaspy-useful-database-schema.html'
10---
11
12[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuef6Hno-pT_lrbBMdX7l1vVWei9KAIDdGnf7PqZ3bHQ9dcGZREpzhV2XkfgrO3Mt_BSlfkKJCKl-MT59zOp9A6Bh-ozY3b7asbxJJA-9Vq-280mhiiXLlWXSPjLLp0jUEtZ-D1TrvIO8/s1600/schemaspy_1.jpg)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuef6Hno-pT_lrbBMdX7l1vVWei9KAIDdGnf7PqZ3bHQ9dcGZREpzhV2XkfgrO3Mt_BSlfkKJCKl-MT59zOp9A6Bh-ozY3b7asbxJJA-9Vq-280mhiiXLlWXSPjLLp0jUEtZ-D1TrvIO8/s1600/schemaspy_1.jpg)
13
14Sometimes it's nice to visualise a pre-existing database (particularly when a new staff member joins the team and you need to walk them through your database). I came across a useful open source tool called schemaspy (http://schemaspy.sourceforge.net/).
15
16Basically you just need to drop in a JDBC driver for your database, update the connection details and tell it to generate the schema documentation.
17
18It generates a bunch of html files (with dot diagrams showing table relationships), what's really sweet is that you can start at a high level, seeing every single relationship in your database and drill down to a specific table.
19
20The next view down shows immediate table relationships (which can be dynamically set to different depths).
21
22[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZQcWn5g0XFBZUFyp5TeTQ1exFRK1cLlOTCC6hY8_4I0TKXEgFRIrxBjHNWIQRPD7MZb00G8t1_NX3I-QuX6r7nETo7wMmC2SdL4VCpA0nth9cfdN5GhDqd9wehboTGvtLXoydsByIuII/s1600/schemaspy2.jpg)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZQcWn5g0XFBZUFyp5TeTQ1exFRK1cLlOTCC6hY8_4I0TKXEgFRIrxBjHNWIQRPD7MZb00G8t1_NX3I-QuX6r7nETo7wMmC2SdL4VCpA0nth9cfdN5GhDqd9wehboTGvtLXoydsByIuII/s1600/schemaspy2.jpg)
23
24This is a fantastic way of exploring a database. We have a cron job that generates this doco of our test database on a nightly basis and drops the files onto an internal web server, meaning that we always have fresh schema documentation without having to install any fancy (and often expensive) client side database design/visualisation tools.
25
26Here are a few notes on how I got it working with a postgresql database:
27
281. Download the schemaspy jar and extract it into a new folder (jar -xvf [jarfile]).
29
302. Modify ./net/sourceforge/schemaspy/dbTypes/pgsql.properties to point at your local postgresql jdbc driver.
31
32**`description=PostgreSQL`** **** **`connectionSpec=jdbc:postgresql://localhost:5432/[SCHEMA]`** **`host=localhost:5432`** **`db=[DBNAME]`** **** **`driver=org.postgresql.Driver`** **** **`# Sample path to the postgresql drivers.`** **`# Use -dp to override.`** **`driverPath=/path/to/postgresql-9.2-1002.jdbc4.jar`**
33
343. Recreate the jar file (with the updated config file).
35
36rm schemaSpy_5.0.0.jar jar -cmf./META-INF/MANIFEST.MF../schemaSpy_5.0.0.jar.
37
384. /usr/bin/java -jar /[PATH TO JAR]/schemaSpy_5.0.0.jar -t pgsql -host localhost -port 5432 -db [DBNAME] -s [SCHEMA] -u [USERNAME] -p [PASSWORD] -o [LOCATION OF OUTPUT]
39
405. If all works well, you will see a bunch of static html files and graphviz generated images in the output directory.****
41
42**** **** ** ** What are your favorite database tools?
43
44
45