I inherited a database nobody can explain

Short answerLet a tool read the live database and draw it for you. DbSchema reverse-engineers it into an interactive ER diagram, and DbSchema Pro saves that map as a model file and publishes it as HTML5, PDF or Markdown documentation for the whole team. A DBA review helps with the hard cases. Free checks for later: dump the schema, list the foreign keys and read the application's models.

01

Map and document it with DbSchema Pro

DbSchema Pro connects to the live database, reverse-engineers it into an interactive ER diagram and saves the design to a model file you can work on offline. With Schema Documentation it publishes the whole schema as one HTML5 file, a PDF or a Markdown file, with the diagram and a description of every table, column, index and foreign key. The next person who inherits the database gets a map instead of a puzzle. When you start changing the schema, Pro also handles schema synchronization and migration.

Good if you need to hand the database over, explain it to others or start changing it

Editions and pricing · Schema Documentation · ER diagram tool

Tool
Cost€€
EffortLow
HelpsToday
02

Take a first look with DbSchema Community

DbSchema Community Edition is free for any use, needs no account and runs on Windows, macOS and Linux against more than 100 SQL and NoSQL databases. Connect it, tick the schemas under Reverse Engineer the Database, and it draws the tables and foreign key lines as an interactive ER diagram. Move to DbSchema Pro once you want to save the design or publish documentation.

Good if you want to see the whole schema as one picture today

ER diagram tool · Features · Editions and pricing

Tool
CostFree
EffortLow
HelpsToday
03

Open the diagram in your database's admin tool

pgAdmin's ERD Tool generates a diagram for an existing database, a schema or one table and plots the tables with their foreign key links. For a single schema it leaves out links to tables in other schemas. On SQL Server, the Database Designer in SSMS draws diagrams of the database you are connected to.

Good if you already use pgAdmin or SSMS

Skip if your tables sit in many schemas that point at each other

pgAdmin · Microsoft Learn

Tool
CostFree
EffortLow
HelpsToday
04

Bring in a DBA for a schema review

If the database runs a system people depend on and your map still has gaps, book a few days with a database consultant who knows your engine. Hand over your schema file, the foreign key list and your notes so they start from your map. The PostgreSQL project lists companies that offer professional services, sorted by region.

Good if production depends on it and you have to change the schema soon

PostgreSQL

Expert
Cost€€€
EffortMedium
HelpsThis week
05

Save the schema to a file first

On PostgreSQL, run pg_dump with --schema-only: it writes every table, key and constraint as SQL, without the data. On SQL Server, the Generate and Publish Scripts Wizard in SSMS scripts all objects of a database. Put the file in Git so you can see later what changed.

Good if you want one file you can read and search

PostgreSQL · Microsoft Learn

Do it yourself
CostFree
EffortLow
HelpsToday
06

List the foreign keys from information_schema

Query the referential_constraints view on PostgreSQL or SQL Server, or KEY_COLUMN_USAGE and its REFERENCED_TABLE_NAME column on MariaDB. Copy the result into a sheet: one row per link, child table, parent table. On PostgreSQL the view only shows keys on tables you may write to, so run it as the owner or an admin role.

Good if you want the declared links in one list

Skip if the database declares no foreign keys at all

PostgreSQL · Microsoft Learn · MariaDB

Do it yourself
CostFree
EffortLow
HelpsToday
07

Read the relations in the application code

ORM models often hold links the database never declared. In Django, a model generally maps to one table, and a ForeignKey field names the table it points to. If the app has no models, python manage.py inspectdb drafts them from the database, as a shortcut, not a finished model. Ask the previous owner which tables matter and write the answers down.

Good if the tables have no foreign keys, but an app uses them

Skip if nobody has the code any more

Models · Integrating Django with a legacy database

Do it yourself
CostFree
EffortMedium
HelpsThis week
08

Check which tables are still read

In PostgreSQL, pg_stat_user_tables shows per table how many sequential and index scans ran (seq_scan, idx_scan), when it was last read (last_seq_scan, last_idx_scan) and roughly how many rows it holds (n_live_tup). Start your map with the tables that are read the most. A table nobody reads is a question for the team, not something to drop.

Good if you face hundreds of tables and need a place to start

Skip if you don't run PostgreSQL

PostgreSQL

Do it yourself
CostFree
EffortLow
HelpsThis week
09

Write what you learn into table and column comments

Put each finding where the next person will find it: COMMENT ON TABLE and COMMENT ON COLUMN in PostgreSQL, an extended property named MS_Description in SQL Server. Your next pg_dump includes the comments unless you pass --no-comments. One sentence per table is enough to start.

Good if you are the one who will be asked next time

COMMENT · Microsoft Learn · pg_dump

Do it yourself
CostFree
EffortLow
HelpsThis week

When it's bigger than a quick fix

Bring in a DBA or your vendor's support when the database runs a system people depend on and you still can't say what some tables are for, when you have to change or drop tables, or when there are no foreign keys and the code doesn't explain the links either.

If there is no backup you have restored at least once, make one before you run any ALTER or DROP. Without it, one wrong statement on a production table can lose data you cannot get back.

Backup and Restore · Professional Services

Questions people ask

What does it mean to reverse engineer a database?

You read an existing database's catalog to rebuild its structure: tables, columns, keys and the links between them. The result is usually a schema script, an ER diagram or both.

How do I see how the tables relate to each other?

List the foreign keys from information_schema, or open the database in a tool that draws an ER diagram from them. Links the database never declared are in the application code.

What if the database has no foreign keys?

Then the relations live in the application code and in naming habits, such as a customer_id column. Read the ORM models, ask the previous team and record each link you confirm.

Can I generate a diagram from an existing database for free?

Yes. pgAdmin's ERD Tool does it for PostgreSQL and the Database Designer in SSMS for SQL Server, and free desktop tools connect to many engines.

Should I delete tables that look unused?

Not yet. Check the usage statistics, ask the team that runs the app, and take a backup first.

Sources

  1. DbSchema: Editions and pricing
  2. DbSchema: Schema Documentation
  3. DbSchema: ER diagram tool
  4. DbSchema: Features
  5. pgAdmin: ERD Tool
  6. Microsoft Learn: Design database diagrams (Visual Database Tools)
  7. PostgreSQL: Professional Services
  8. PostgreSQL: pg_dump
  9. Microsoft Learn: Generate scripts (SQL Server Management Studio)
  10. PostgreSQL: referential_constraints
  11. Microsoft Learn: REFERENTIAL_CONSTRAINTS (Transact-SQL)
  12. MariaDB: Information Schema KEY_COLUMN_USAGE Table
  13. Django: Models
  14. Django: Integrating Django with a legacy database
  15. PostgreSQL: The Cumulative Statistics System
  16. PostgreSQL: COMMENT
  17. Microsoft Learn: sp_addextendedproperty (Transact-SQL)
  18. PostgreSQL: Backup and Restore