248

I would like to generate an entity-relationship diagram (ERD) from an existing PostgreSQL database.

  • What is the recommended approach to do this?
  • Are there any built-in tools to do it? Or third-party alternatives?
toraritte
  • 6,300
  • 3
  • 46
  • 67
Badr
  • 10,384
  • 15
  • 70
  • 104
  • 4
    i want to visualize the relationships between tables of the existing schema – Badr Aug 13 '10 at 06:40
  • @ALL is there any add-on for pgadmin III to get the ER-Diagrams done as this [Video in this Link Says](http://stackoverflow.com/questions/9692913/create-an-er-diagram-in-pgadmin) . – 09Q71AO534 Oct 15 '13 at 13:56
  • check this out... https://softwarerecs.stackexchange.com/questions/34552/generate-database-table-diagrams-from-a-postgresql-database – ntg Jun 08 '21 at 10:49
  • No one mentioned [SchemaSpy](https://schemaspy.org/) below thus far, so here it is. – toraritte Apr 15 '23 at 13:49
  • You can use [Luna Modeler](https://www.datensen.com) to visualize relationships in PostgreSQL. – Vaclav Jun 01 '23 at 05:49
  • TablePlus does this as well with free plug-in. Instructions: https://github.com/TablePlus/TablePlus/issues/44#issuecomment-668054912 – jrc Jul 27 '23 at 12:04

13 Answers13

222

You can use dbeaver to do this. It allows you to export the ER diagram as png/svg etc.

DBeaver - https://dbeaver.io/

Double click on a schema (eg, Schemas->public->Tables) and open the "ER Diagram" tab (next to "Properties" tab)

Anu
  • 65
  • 8
krishnakumarp
  • 8,967
  • 3
  • 49
  • 55
  • Second this! While l I generally prefer the psql terminal, at times I also use DBeaver CE (Community Edition; https://dbeaver.jkiss.org/download/ ; an excellent, free and open source platform) for viewing data and visualizing the ERDs. – Victoria Stuart Mar 08 '18 at 19:45
  • 4
    Just installed DBeaver and was able to get the E-R diagram of my database. A tool that works. If you have more than 100 tables, then the generated E-R diagram will need some manual arrangement though... – honor Jul 01 '18 at 09:22
  • 3
    Here's the [DBeaver ER Diagrams wiki page](https://github.com/dbeaver/dbeaver/wiki/ER-Diagrams), which includes helpful tips for layout and exporting to image file format: – dpmott Jun 24 '19 at 20:24
  • And it is opensource, meanwhile the accepted answer is for a product (DBVisualizer) that gives a limited trial and after you need to purchase a license – Jose V Aug 08 '19 at 17:32
  • Started with DBVisualizer because it was higher on the page, but this is CLEARLY the right answer here. DBVisualizer's free version is immensely limited AND it looks like it was designed by a DBA in 1992. Meanwhile DBeaver, while not a design _marvel_, is quite nice looking, and the ERDs it generates are SIGNIFICANTLY easier to read/follow/look at. – tandrewnichols Jan 27 '20 at 22:15
  • Just point out that DBeaver Community Edition allows : double click on table to open ER diagram limited to related tables ; save manual arrangements you do to each autogenerated ER diagram ; create custom diagrams (.erd files) with a subset of tables ; add table to existing diagrams and auto add relationships ; export diagrams as .png – Mauricio Jul 08 '20 at 03:26
  • It is a pain to configure a proxy server in DBeaver. – ceving Sep 17 '20 at 12:27
210

pgAdmin 4 version 30 and newer can generate the ERD from an existing database. Just right-click on the database and select Generate ERD.

enter image description here

Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145
Abdinardo Oliveira
  • 2,410
  • 1
  • 5
  • 12
  • I just tried it (on a small DB with 5 tables) and it seems to work fairly well! – Martin Häusler Mar 24 '21 at 20:05
  • Good start but that doesn't generate everything. It would be usefull to also design views for example. – GeoGyro Apr 23 '21 at 07:13
  • 3
    Can we generate ERD for some tables ? – Shahid Feb 22 '22 at 13:05
  • 2
    (For those looking to export the ERD to an image, there's a download image button along the top options after creating [Alt+Ctrl+I is the listed shortcut for me]. Since that was part of krishna's answer, and my desire, figured that may be of use to some) – JeopardyTempest Jul 10 '22 at 14:45
110

We used DBVisualizer for that.

Description: The references graph is a great feature as it automatically renders all primary/foreign key mappings (also called referential integrity constraints) in a graph style. The table nodes and relations are layed out automatically, with a number of layout modes available. The resulting graph is unique as it displays all information in an optimal and readable layout. from its site

simo
  • 23,342
  • 38
  • 121
  • 218
rudi-moore
  • 2,650
  • 1
  • 19
  • 16
16

pgModeler can generate nice ER diagram from PostgreSQL databases.

It seems there is no manual, but it is easy enough without manual. It's QT application. AFAIK, Fedora and Ubuntu has package. (pgmodeler)

In the latest version of pgModeler (0.9.1) the trial version allows you to create ERD (the design button is not disabled). To do so:

  1. Click Design button to first create an empty 'design model'
  2. Then click on Import and connect to the server and database you want (unless you already set that up in Manage, in which case all your databases will be available to select in step 3)
  3. Import all objects (it will warn that you are importing to the current model, which is fine since it is empty).
  4. Now switch back to the Design tab to see your ERD.
rmcsharry
  • 5,363
  • 6
  • 65
  • 108
Yasuo Ohgaki
  • 429
  • 4
  • 4
6

Download DbVisualizer from : https://www.dbvis.com/download/10.0

and after installing create database connection:

SS1

Change highlighted detail of your db and test by click ping server. Finally click connect

Enjoy.

ankit
  • 2,591
  • 2
  • 29
  • 54
  • 1
    Thanks, works for me. After you are connected - double-click on 'TABLE' and go to 'References' tab. Here is the [link for details](https://www.dbvis.com/features/tour/references-graphs/). – Andrey Kotov Jan 22 '19 at 23:57
4

Our team use Visual Paradigm to generate ER diagram from database in many of our projects. While we mainly work on MS SQL and Oracle, as I know they also support some other DBMS like PostgreSQL, MySQL, Sybase, DB2 and SQLite.

Steps:

  1. Select Tools > DB > Reverse Database... from the toolbar of Visual Paradigm
  2. Keep the settings as is and click Next Select PostgreSQL as driver and provide the driver file there. You can simply click on the download link there to get the driver.
  3. Enter the hostname, database name, user and password, and then click Next
  4. They will then study your database and lists out the tables in it.
  5. Select the table to form an ERD and continue, and that's it. An ERD will be generated with the tables you selected presented.

BTW they also support generating and updating database schema from ERD.

Hope this helps. :-)

More information about generating ERD from PostgreSQL database

Kyle Costello
  • 372
  • 2
  • 10
3

ERBuilder can generate ER diagram from PostgreSQL databases (reverse engineer feature).

Below step to follow to generate an ER diagram:

• Click on Menu -> File -> reverse engineer

• Click on new connection

• Fill in PostgresSQL connection information

• Click on OK

• Click on next

• Select objects (tables, triggers, sequences…..) that you want to reverse engineer.

• Click on next.

  • If you are using trial version, your ERD will be displayed automatically.
  • If your are using the free edition you need to drag and drop the tables from the treeview placed in the left side of application

enter image description here

2

Another option is use Oracle SQL Developer. Two steps as below:

(1) First of all, you need to connect SQL Developer to your PostgreSQL database.

(2) Then you can generate an entity-relationship (ER) diagram using SQL Developer

Yuci
  • 27,235
  • 10
  • 114
  • 113
0

Perhaps have a look at AquaFold's Aqua Data Studio. It is a database IDE with entity-relationship diagramming. It also includes data profiling. It is not free but its price is very reasonable considering its capabilities.

0

postgresql_autodoc is a command-line tool for doing this. Doesnt do cardinality, but none of the above mentioned GUI tools do as well.

toraritte
  • 6,300
  • 3
  • 46
  • 67
-1

I use DrawERD for ERD & DB doc. https://drawerd.com enter image description here

enter image description here

Hooopo
  • 1,380
  • 10
  • 16
-8

You can generate ER diagram from PgAdmin.

  1. Open PgAdmin
  2. Right click on any table and select statement and it will show two window one is query other is graphical window so you can add the table which you want to generate the diagram.
  3. To save go to save as and select Graphical Query (image)
JJJ
  • 32,902
  • 20
  • 89
  • 102
Husen
  • 1
  • 4
    I don't see any options like this, pgAdmin 4, version 2.1. There is no "select statement" or "statement" in the context menu for a table – Adam Lehenbauer Apr 26 '18 at 21:20
-10
  1. Open MySQL Workbench. In the home screen click 'Create EER Model From Existing Database'. We are doing this for the case that we have already made the data base and now we want to make an ER diagram of that database.

  2. Then you will see the 'Reverse Engineer Database' dialouge. Here if you are asked for the password, provided the admin password. Do not get confused here with the windows password. Here you need to provide the MySQL admin password. Then click on Next.

  3. In the next dialouge box, you'll see that the connection to DBMS is started and schema is revrieved from Database. Go next.

  4. Now Select the Schema you created earlier. It is the table you want to create the ER diagram of.

  5. Click Next and go to Select Objects menu. Here you can click on 'Show Filter' to use the selected Table Objects in the diagram. You can both add and remove tables here.Then click on Execute.

6.When you go Next and Finish, the required ER diagram is on the screen.

sujith
  • 5
  • 1