Skip to content

Feature: connect directly to a live PostgreSQL instance (--postgres DSN) instead of dumping schema to .sql first #1093

Closed

Description

@safishamsi

Summary

Add an optional live-database source so users can point graphify at a running PostgreSQL instance (via a connection string / DSN) and have it auto-extract the schema, instead of manually running pg_dump --schema-only first and feeding the resulting .sql file.

Motivation

Graphify already maps database schemas well: extract_sql() (extract.py:4251) parses tables, views, functions, and foreign-key relationships from .sql files via tree-sitter, and this is exactly what the v0.6.0 "map your entire backend in one graph" feature is about.

The friction is the manual dump step. Today the workflow is:

pg_dump --schema-only mydb > schema.sql
graphify extract ./schema.sql

For users who just want a graph of their live database, the dump-to-file round trip is an unnecessary step, and it goes stale the moment the schema changes. A direct connector would let them do:

graphify extract --postgres "postgresql://user:pass@host:5432/mydb"

and get a fresh graph of the current schema on demand.

Proposed design

This should be a thin wrapper around the existing extraction path, not a new extractor:

  1. New optional dependency group, e.g. postgres = ["psycopg[binary]"].
  2. A small introspection helper that connects, reads the schema from the catalog (information_schema / pg_catalog), and emits the same node/edge shape extract_sql() already produces - tables, views, functions, and FK references edges - so everything downstream (build, cluster, report, export) is unchanged.
  3. Wire it as a --postgres <dsn> flag (or a graphify extract source variant) that feeds the introspected schema into the normal pipeline.

Reusing the extract_sql node/edge contract keeps this isolated: no changes to build/cluster/export, and the graph looks identical whether the schema came from a .sql dump or a live connection.

Scope / non-goals

  • Schema only, not data. Same as the current .sql path - this maps structure (tables, columns, FKs, views, functions), not rows.
  • Read-only. The connector only introspects the catalog; it never writes.
  • Postgres first. The same approach generalizes to other engines later (MySQL, etc.) but this issue is scoped to Postgres.
  • Credentials handling: support a DSN string and standard PG* env vars (PGHOST, PGUSER, ...); document not committing secrets.

Alternatives

  • Keep the status quo (pg_dump then graphify extract). Works today, but stale and manual.

Context

Came up from a user asking whether graphify could point directly at PostgreSQL (and VictoriaLogs). The .sql-file path covers the Postgres-schema case once dumped; this issue is about removing the dump step. (Live log/time-series ingestion like VictoriaLogs is a separate, out-of-scope domain.)

Activity

  1. geektan123 commented on Jun 1, 2026

    @geektan123
    Contributor

    Hi! I'd like to work on this issue. Could you assign it to me?

  2. added a commit that references this issue on Jun 2, 2026
    b78c449
  3. safishamsi commented on Jun 7, 2026

    @safishamsi
    MemberAuthor

    Fixed in 7467c1b (landed as part of PR #1103).

    graphify extract --postgres "postgresql://user:pass@host/db" now introspects a live database directly — no pg_dump roundtrip needed. Extracts tables, views, routines, and FK relations via information_schema in a SERIALIZABLE READ ONLY transaction. Credentials are sanitized from error messages. New graphify[postgres] optional extra (psycopg3).

    Upgrade: uv tool upgrade graphifyy (coming in v0.8.34)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions