Skip to content
Guide · pgAdmin

pgAdmin ER Diagram Tutorial

pgAdmin 4 includes an ERD Tool that draws entity-relationship diagrams for PostgreSQL. It can generate a diagram from an existing database, schema or table, or let you design new tables and relationships and then generate the CREATE TABLE SQL. This tutorial follows the pgAdmin documentation step by step, using a small four-table example schema.

Steps and facts checked 8 October 2026 against the vendor's official documentation. Versions covered: pgAdmin 4 v9.18; PostgreSQL 18. Next review due April 2027. Menus, shortcuts and prices change between releases; check the vendor's documentation for your version.
Short answer
  • To diagram an existing database, select it in the Object Explorer and choose ERD For Database; for one table and its related tables, choose ERD For Table.
  • To design from scratch, open Tools > ERD Tool, add tables, then draw 1-1, 1-M or M-M relationships between them.
  • Generate SQL opens a Query Tool with the DDL ready to run; the diagram itself does not change the database until you execute that SQL.
  • Diagrams save as .pgerd project files (JSON) and can be downloaded as an image.
How we know: Research-based: the steps, menu names, toolbar options and preferences below come from the pgAdmin 4 9.18 documentation (ERD Tool, Menu Bar, Preferences and Keyboard Shortcuts pages), checked on 8 October 2026. We have not produced screenshots or run the example for this page; the example schema is ordinary PostgreSQL DDL for you to try.

What the pgAdmin ER diagram tool does

The ERD Tool is pgAdmin's database design tool. According to the documentation it can design and visualise tables and their relationships, add notes, auto-align tables and links, save a diagram to reopen later, generate ready-to-run SQL, generate a diagram for an existing database and accept tables dragged from the Object Explorer. You can open several ERD tabs at once.

It only works with PostgreSQL and EDB Postgres Advanced Server, like the rest of pgAdmin. If you need ER diagrams for several database engines, compare the options in best ER diagram tools. For the concepts behind the notation, read ER diagrams explained.

Example schema to follow along

To have something to diagram, create these four tables in a practice database with the Query Tool. They give one one-to-many chain (customers to orders) and a many-to-many relationship resolved through order_items.

PostgreSQL: four related tables for the ERD tutorial
CREATE TABLE customers (
    customer_id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    full_name   text NOT NULL,
    email       text UNIQUE
);

CREATE TABLE products (
    product_id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    name       text NOT NULL,
    price      numeric(10,2) NOT NULL
);

CREATE TABLE orders (
    order_id    integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    customer_id integer NOT NULL REFERENCES customers (customer_id),
    ordered_at  timestamptz NOT NULL DEFAULT now()
);

CREATE TABLE order_items (
    order_id   integer NOT NULL REFERENCES orders (order_id),
    product_id integer NOT NULL REFERENCES products (product_id),
    quantity   integer NOT NULL CHECK (quantity > 0),
    PRIMARY KEY (order_id, product_id)
);

Generate an ERD from an existing database

  1. In the Object Explorer, connect to the server and select the database.
  2. Open the Object menu (or right-click the database) and choose ERD For Database. The documentation notes this option is only available when a database is selected.
  3. pgAdmin fetches every table from every schema and plots them with their foreign key links.
  4. Click Auto align to tidy the layout, and Zoom to fit to see the whole diagram.

ERD for one table. Select a table and choose ERD For Table. pgAdmin then draws every table linked to it directly or indirectly. To limit how far it follows the links, set Table Relation Depth under Preferences > ERD Tool > Options; -1 means no limit.

ERD for one schema. The documentation also describes an ERD for a schema, which plots all tables in that schema. Foreign keys that point to a table in another schema are left out of a schema diagram.

Design new tables and relationships

  1. Choose Tools > ERD Tool to open an empty diagram (or drag existing tables onto it from the Object Explorer).
  2. Click Add table. A table dialog opens where you enter the name, columns and constraints; it is the same dialog pgAdmin uses for creating tables.
  3. Select the referencing table and click 1-M to add a foreign key. In the dialog, the Local Table and Local Column are the many side, and the Referenced Table and Referenced Column are the one side.
  4. Use 1-1 for a one-to-one link; the local column needs a primary key or unique constraint, and pgAdmin offers a unique constraint by default.
  5. Use M-M to link two tables through a new relation table whose columns are derived from the primary keys of both.
  6. Add a note to a table with Add/Edit note, and colour groups of tables with Fill Color and Text Color.

Double-click a table node to edit it. If you remove a column that a link depends on, pgAdmin drops the link.

Save the diagram, export an image and generate SQL

Generate SQL does not run anything by itself: review the script in the Query Tool and execute it when you are ready. To compare two existing databases or schemas, pgAdmin has a separate Schema Diff tool. On macOS the shortcuts use Option in place of Alt; the full list is in the pgAdmin keyboard shortcuts cheat sheet.

ERD Tool file and export options (Windows/Linux shortcuts from the Keyboard Shortcuts page)
ActionWhat it doesShortcut
Save / Save asSaves the diagram as a .pgerd project file (JSON), which you can reopen with Open FileCtrl + S / Shift + Ctrl + S
Download imageSaves the diagram in an image format; resolution is set by Image Download Resolution in PreferencesCtrl + Alt + I
Generate SQLOpens a Query Tool with the DDL for the diagram, ready to execute; the With DROP Table option adds DROP TABLE before each CREATE TABLECtrl + Alt + S
Show detailsToggles column details on the table nodesCtrl + Alt + T

Reading the diagram: notation and links

Each table node shows the schema name on the first row, the table name on the second and then the columns with their data types; primary key columns have a key icon. Links show cardinality: the single-line end points at the referenced column and the three-line end at the referring column. You can switch between crow's foot and Chen notation with Cardinality Notation on the toolbar or in Preferences.

Frequently asked questions

How do I generate an ER diagram in pgAdmin 4?

Select a database in the Object Explorer and choose ERD For Database from the Object or right-click menu. pgAdmin draws all tables with their foreign key links.

Can pgAdmin create tables from an ER diagram?

Yes, indirectly. Generate SQL opens a Query Tool with the CREATE TABLE statements for the diagram; you run them to create the tables.

How do I export a pgAdmin ERD as an image?

Click Download image on the ERD toolbar (Ctrl + Alt + I on Windows and Linux). Higher values for Image Download Resolution in Preferences give a sharper image but use more memory.

What is a .pgerd file?

It is the ERD Tool's project file, saved in JSON. You can reopen it with Open File to continue editing, and the Format ERD Project File? preference formats the JSON.

Why are some foreign keys missing from my schema diagram?

An ERD for a schema removes links to tables in other schemas. Generate the ERD for the whole database to see cross-schema foreign keys.

Sources

Checked 8 October 2026.

How we research tool guides: our editorial method. CodeWithSQL earns nothing from the vendors mentioned.

Still choosing a SQL client?

Read the full reviews, or compare tools side by side.