Cosmovex Tools

Need an ER diagram of a Postgres schema? Paste the SQL and see it drawn

Postgres ER diagram with Schema Diff Studio

A six-table issue tracker schema is loaded with no Before, so the page opens straight on its ER diagram: organizations, users, memberships, projects, issues and comments, with every foreign key drawn as a relationship and primary keys marked. The schema is executed in Postgres in your tab first, so the diagram shows what Postgres understood, not what a parser guessed.

  1. Clear Before (or leave it empty) and paste your schema into After: CREATE TABLE statements, a migrations folder concatenated into one file, or pg_dump --schema-only -d your_db output.
  2. Press Compare. With no Before, the page opens on the Diagram tab with every table laid out automatically and every foreign key drawn between the columns it joins.
  3. Drag tables to arrange them on a desktop screen; the positions are saved with the project in this browser.
  4. Exporting is Pro ($29 once): PNG or SVG for a document, a Mermaid erDiagram (.mmd) for a README or wiki that renders Mermaid, or a Markdown data dictionary listing every column. Viewing and arranging the diagram stay free.
postgres er diagram from sql sql to er diagram onlinepostgres er diagram generatorpg_dump to er diagramgenerate erd from ddlpostgresql er diagram online
Open Schema Diff Studio Free · Pro $29 one-time · no account

What to know

Most "SQL to ER diagram" tools parse the CREATE TABLE text themselves, and a hand-written parser misreads the parts of Postgres DDL that matter most: foreign keys added later with ALTER TABLE ONLY ... ADD CONSTRAINT (which is how pg_dump writes every one of them), composite primary keys, identity columns, quoted identifiers and schema-qualified names. Here the SQL runs in a real Postgres first and the diagram is drawn from its catalog, so a relationship appears exactly when Postgres has a foreign key for it.

Mermaid export (Pro) makes the diagram live next to the code. GitHub, GitLab and many wikis render a ```mermaid block containing erDiagram, so the exported .mmd can go straight into a README and be regenerated when the schema changes. Mermaid's ER syntax has no notion of composite foreign keys or check constraints, so the export carries tables, columns, keys and relationships, and the Markdown data dictionary carries the rest: types, defaults, NULL rules and constraints per column.

A diagram of a large schema is only readable when it is arranged. Automatic layout places tables connected by foreign keys near each other; after that, dragging the central tables (users and issues here) to the middle usually untangles the rest. Pro adds labelled frames per schema namespace, which helps when one dump contains public, billing and auth schemas side by side.

Once the diagram exists, the same page compares versions. Paste the schema you have in Before and the one you are designing in After, and the diagram marks new tables and columns while the Changes and Migration tabs give you the ALTER script for them.

Updated · Cosmovex

Questions

How do I generate an ER diagram from a Postgres database?

Run pg_dump --schema-only -d your_db > schema.sql, paste or open schema.sql in the After editor with Before empty, and press Compare. The diagram is drawn from the schema only; no connection to the database is made and no rows are read.

Can I export the diagram to Mermaid?

Yes, with Pro ($29 once): export a Mermaid erDiagram (.mmd) and paste it into a ```mermaid code block in Markdown on any platform that renders Mermaid. PNG and SVG images and a Markdown data dictionary are Pro exports too. Viewing, zooming and arranging the diagram are free.

Does it draw foreign keys defined with ALTER TABLE?

Yes. Relationships come from the foreign keys Postgres actually created, so it does not matter whether they were inline REFERENCES, table constraints or ALTER TABLE ... ADD CONSTRAINT statements at the end of a pg_dump file.

Can I rearrange the diagram on a phone?

On a phone the diagram can be panned and pinch-zoomed but tables cannot be dragged. Arrange it on a desktop: the positions are saved with the project in that browser, and Pro exports use them.

Does it work for MySQL?

No. Postgres and SQLite are supported. A MySQL paste is detected and the tool says so instead of drawing a wrong diagram.

The free plan covers everything on this page. Schema Diff Studio Pro ($29, paid once) is described on the Schema Diff Studio page.