CentauroDB Logo
Advanced

PostgreSQL

Switch from SQLite to PostgreSQL — same API, server-grade backend.

CentauroDB supports PostgreSQL as an alternative backend. The Python API is identical — you change the connection string and everything else works the same. This guide covers setup, differences, and when to choose PostgreSQL over SQLite.

Installation

Install the PostgreSQL extra:

pip install "centaurodb[postgres]"

This installs psycopg, the modern PostgreSQL adapter for Python.

Connecting

Pass a PostgreSQL connection URL to Engine:

from centaurodb import Engine, Collection

engine = Engine("postgresql://user:password@localhost:5432/mydb")
coll = Collection(engine, "monitoring")

Everything else works exactly the same — write_object(), read_objects(), create_view(), all query operators, relations, time-series. Your Python code is backend-agnostic.

URL formats

# Standard
Engine("postgresql://user:password@localhost:5432/mydb")

# Alternate scheme
Engine("postgres://user:password@localhost:5432/mydb")

What changes under the hood

While the Python API stays identical, CentauroDB adapts the SQL it generates:

SQLitePostgreSQL
SetupZero — built into PythonRequires a running PostgreSQL server
ConnectionFile path or ":memory:"postgresql:// URL
JSON storagejson() textJSONB (binary, faster queries)
JSON extractionjson_extract(meta, '$.field')meta->>'field'
ConcurrencySingle-writerMulti-writer
AsyncNeeds check_same_thread=FalseThread-safe by default
Installpip install centaurodbpip install "centaurodb[postgres]"
The SQL dialect differences are handled internally by CentauroDB. You never need to think about json_extract vs ->> — just write Python.

Starting with SQLite, moving to PostgreSQL

A common pattern is to develop locally with SQLite and deploy to production with PostgreSQL. The migration path is straightforward — change one line:

# Development
engine = Engine("app.db")

# Production
engine = Engine("postgresql://user:pass@db-host/myapp")

No code changes, no model changes, no view recreation. The same Collection, TimeSeriesCollection, create_view, and create_index calls work on both backends.

You can start development with SQLite and switch to PostgreSQL for deployment — just change the connection URL. No code changes required.

When to use PostgreSQL

  • You need concurrent writers (multiple processes or services writing to the same database)
  • You need a network-accessible database (shared across services)
  • You're deploying to a server environment with existing PostgreSQL infrastructure
  • You need advanced PostgreSQL features via raw SQL (full-text search, triggers, etc.)

When to stick with SQLite

  • Local development, prototyping, Jupyter notebooks
  • Embedded applications (CLI tools, desktop apps)
  • Single-user scenarios or single-writer workloads
  • You want zero infrastructure — just a .db file
  • Edge/IoT deployments where simplicity matters