N
NJHTools

PostgreSQL ER Diagram from Your Schema

Paste a PostgreSQL schema, for example the output of pg_dump --schema-only, and get an ER diagram of its tables, primary and foreign keys and enum types. It runs in your browser, so your schema is never uploaded, and it can export the model back to PostgreSQL SQL, DBML or Mermaid.

PostgreSQL codeYour schema stays in this browser.

Tab indents. Press Esc, then Tab, to move focus out. Autosaved in this browser.

How to make a PostgreSQL ER diagram

  1. 1Run pg_dump --schema-only --no-owner --no-privileges mydb > schema.sql.
  2. 2Keep PostgreSQL selected and paste the contents of schema.sql.
  3. 3Review tables, enum types and the foreign key lines between them.
  4. 4Drag tables or re-run auto-layout until the diagram reads well.
  5. 5Export PNG or SVG for your docs, or DBML and Mermaid to keep the model as text.

Dumping a PostgreSQL schema

pg_dump --schema-only (or -s) writes the structure without any rows. Add --no-owner and --no-privileges to drop ALTER ... OWNER and GRANT lines, and -n public or -n your_schema to dump a single schema. From a hosted database, the same command works with a connection string: pg_dump --schema-only "postgresql://user@host/db".

pg_dump writes foreign keys as separate ALTER TABLE ONLY ... ADD CONSTRAINT ... FOREIGN KEY statements near the end of the file; keep them, because they are what draws the relationship lines. If functions, triggers or extensions stop the parser, remove those blocks; the diagram does not need them.

PostgreSQL features in the diagram

CREATE TYPE ... AS ENUM types are shown as enum boxes, and columns that use them show the enum name as their type. Tables outside the public schema keep their schema name, such as billing.invoices, so large multi-schema databases stay readable.

Exporting the model as MySQL or SQL Server SQL is a quick way to draft a port, but column types are largely carried over as written. Review PostgreSQL-specific types such as serial, jsonb, arrays and timestamptz by hand, because they have no exact match in other databases.

Normalization tips that show up in a diagram

First normal form means one value per column: no comma-separated tag lists and no phone1, phone2, phone3 columns. If you see repeating columns, move them to a child table with a foreign key back to the parent. In the diagram that becomes a clear one-to-many line instead of a wide table.

Second and third normal form mean every non-key column depends on the key, the whole key and nothing but the key. A customer_email column on orders depends on the customer, not the order, so it belongs on customers. Tables with no relationship lines at all, or one table that every line points at, are both worth a second look.

Denormalize on purpose, not by accident. Copying a price onto order_items at the time of purchase is correct, because the order must not change when the catalog price does. Note such decisions in the schema so the next reader knows the duplication is intended.

Frequently Asked Questions

How do I get my PostgreSQL schema without data?↓

Run pg_dump --schema-only --no-owner --no-privileges mydb > schema.sql and paste the file. In psql, \d table_name shows one table, but it is not valid SQL to paste; use pg_dump output instead. The tool never connects to your database.

Does it show PostgreSQL enums and schemas?↓

Yes. Enum types declared with CREATE TYPE ... AS ENUM appear with their values, and tables in schemas other than public are labelled with the schema name.

Is my database schema private? Is anything uploaded?↓

Nothing is uploaded. Parsing, layout and every export run in your browser, and the diagram is autosaved only in this browser's local storage. There are no share links on purpose, because table and column names can reveal how a product works. No signup is needed.

Which export formats are available?↓

You can export CREATE TABLE SQL for PostgreSQL, MySQL, SQL Server or Oracle, the schema as DBML, a Mermaid erDiagram for Markdown docs on GitHub or GitLab, and the diagram itself as a PNG image or an SVG vector file. Convert SQL to DBML turns pasted SQL into DBML you can keep editing.

Why does my SQL fail to parse?↓

Check that the selected dialect matches your SQL, because PostgreSQL, MySQL and SQL Server quote names and declare types differently. Dumps can also contain functions, triggers, procedures or permission statements that are not needed for a diagram; delete those and keep CREATE TABLE, CREATE TYPE and the ALTER TABLE statements that add keys.

All Text & Dev Tools →

Last updated: