schema_diagram - Create a diagram of a database's tables


schema_diagram [--user username] [--password password] [--format format] [--output filename] [--tile] [--scale factor] [--paper paper_size] DBI_data_source


Produces a diagram of the specified database, showing all the tables, listing their fields, and indicating foreign key links between tables.

The output can be various formats, including PostScript, png, SVG, and GraphViz's dot. If the poster(1) command is available then PostScript output can be tiled on to multiple sheets.


Generate a PostScript diagram of the Postgres database wedding, saving it to the file

  schema_diagram DBI:Pg:dbname=wedding

Same, but tile it over multiple sheets:

  schema_diagram --tile DBI:Pg:dbname=wedding

Generate a png image of the MySQL database intranet, connecting as the user wiki, and saving it to the file intranet.png:

  schema_diagram --format png --user wiki DBI:mysql:intranet

Same, but save to the file DB_schema.png:

  schema_diagram --output DB_schema.png --user wiki DBI:mysql:intranet

Specifying the Database

Specify the database with DBI_data_source, a string in the format used by the Perl DBI module, such as in the above examples.

If non-default authentication is required, specify them with these options:

--user username

The username to the database as.

--password password

The password to use when connecting to the database.

Specifying the Output

These options can be used to specify the output format and filename. By default PostScript output is generated and the filename based on the database's name.

--format format

The output format. Valid values include png, svg, fig, plain, and any format which the GraphViz module can create with an add_* method. The format dot can be used to specify GraphViz's dot format, suitable for passing to dot(1).

--output filename

The name of the file to save the diagram in. If the filename has an extension which matches the desired format then there is no need to also pass the --format option; schema_diagram will work out the format from the filename.


These options use the poster(1) command to split the diagram over multiple sheets, with cutmarks suitable for printing and assembling into a large poster. There is no tiling by default.


Tile the diagram. This will use the system's default paper size, and a scale factor of 0.4.

--scale factor

Scale the diagram by the specified factor.

Specifying --scale implies --tile.

--paper paper_size

Tile on to sheets of the specified paper size.

Specifying --paper implies --tile.

Tweaking the Included Tables

If you wish to tweak a diagram, perhaps to remove some irrelevant tables or specify a de facto foreign key link which isn't encoded in the database, use --format dot. Then edit the created file with a text editor (the format is quite intutive to make basic changes), and use the dot command to generate the diagram.


DBI, GraphViz, GraphViz::DBI::FromSchema, poster


Written by Smylers, for Webfusion

Contact me on <> or


Copyright 2011 Webfusion Ltd

This library is software libre; you may redistribute it and modify it under the terms of any of these licences:

  • The GNU General Public License, version 2

  • The GNU General Public License, version 3

  • The Artistic License

  • The Artistic License 2.0