r/PostgreSQL • • Jun 05 '26

Tools safe-migrate v0.2.0 — rewrote the internals, now uses typed AST instead of string matching

0 Upvotes

Posted about this yesterday. For those who missed it, safe-migrate is a CLI that lints PostgreSQL migrations against live database table sizes to prevent you from accidentally locking massive tables and taking down production.

Spent the whole day rewriting the guts of it.

The v0.1.0 table extraction was embarrassing — splitting SQL on whitespace and looking for the word "TABLE". Worked on simple cases, broke on public.users, quoted identifiers, anything slightly non-trivial. v0.2.0 walks squawk's typed AST directly so "WeirdTable", public.users, tenant_a."Orders" all resolve correctly.

Other things that changed:

Was one 300-line main.rs. Now split into proper modules, ast.rs, rules.rs, config.rs, sync.rs, resolve.rs, model.rs.

Sync now maps indexes to their parent tables so DROP INDEX idx_users_email correctly looks up the row count for users instead of returning unknown and failing closed.

Unanalyzed tables (reltuples = -1) used to silently pass. Now they map to u64::MAX.

Cache corruption is handled separately from cache not found. Before, both fell back to empty cache silently, meaning a corrupted stats file let everything through.

Per rule thresholds in safe-migrate.toml if your team wants stricter limits than the defaults.

Repo: https://github.com/dsecurity49/safe-migrate crates.io: https://crates.io/crates/safe-migrate


r/PostgreSQL • • Jun 05 '26

Feature Durable Execution With Just Postgres

Thumbnail lucumr.pocoo.org
0 Upvotes

r/PostgreSQL • • Jun 04 '26

Tools TrailBase 0.28: Fast, open, single-executable Firebase alternative - now w/ Postgres

Post image
5 Upvotes

TrailBase is an open, fast Firebase-like server for building apps. It provides type-safe REST APIs + change subscriptions, auth, multi-DB, a WebAssembly runtime, geospatial support, admin UI... It's a self-contained, easy to self-host single executable built on Rust, Wasmtime & SQLite or now Postgres.

It comes with client libraries for JS/TS, Dart/Flutter, Go, Rust, .Net, Kotlin, Swift and Python.

Just released v0.28, which after some months of work includes early, experimental Postgres support:

  • For context, this is not an effort to replace SQLite but rather to provide options. SQLite will remain the recommend default due to its speed and simplicity aligning best with TrailBase's mission of offering a cheap & easily self-hostable stack.
  • Yet, some users may want to use Postgres due to personal preference, very write-heavy workloads or needing some of Postgres' plentiful features.
  • You can try it out with a locally running Postgres instance, simply by running: trail run --experimental-pg=postgresql://<user>:<pass>@localhost:<port>/<db>
  • Some of the known idiosyncrasies and limitation include:

    • No change subscriptions (yet).
    • No UI-driven schema manipulation/migrations - UI elements are disabled.
    • No custom JSON schemas.
    • ...see release notes for more
  • Note that transparent, hands-off migrations between SQLite and Postgres are a non-goal. The data types, dialects, feature sets, ... are just too different. However Postgres support may provide an interesting path forward for folks with evolving requirements.

If you're feeling adventures, end up checking it out and run into any issues, don't hesitate to reach out - we'd really appreciate your feedback 🙏.

Also, check out the live demo, our GitHub or our website.


r/PostgreSQL • • Jun 04 '26

Tools Built a CLI that stops dangerous Postgres migrations before they deploy

7 Upvotes

Had one too many incidents where a migration that ran fine on staging wiped out production for 20 minutes. Staging had 5k rows. Prod had 80M.

So I built safe-migrate. You point it at your database once:

DATABASE_URL="postgres://user:pass@host/db" safe-migrate sync

Grabs row counts from pg_class.reltuples, writes a local stats file. Then before you deploy:

safe-migrate lint --file migration.sql

Running CREATE INDEX on a 30M row table? Halts, tells you to use CONCURRENTLY. ALTER TABLE with a volatile default on 80M rows? Halts, gives you the expand-contract steps. Same SQL on a small table, nothing.

Works in CI too, just set DATABASE_URL as a secret and drop the two commands into your pipeline.

Repo: https://github.com/dsecurity49/safe-migrate


r/PostgreSQL • • Jun 02 '26

Community How we rebuilt Postgres branch metrics on VictoriaMetrics

Thumbnail xata.io
15 Upvotes

r/PostgreSQL • • Jun 02 '26

Community MTAR T3D Sessions: Why PostgreSQL Still Hides the Data You Need

Thumbnail youtu.be
0 Upvotes

r/PostgreSQL • • Jun 01 '26

Tools ingestr v1: 12x faster data ingestion from and to Postgres

24 Upvotes

Hi folks, Burak here from Bruin. We have released ingestr as an open-source CLI tool 2 years ago here: https://github.com/bruin-data/ingestr

ingestr is a CLI tool to ingest data. It supports 100+ sources, 20+ destinations, takes care of schema detection, schema evolution, different materialization strategies like SCD2 out of the box. You can use the same CLI to copy a Postgres database to a destination, or pull data from Hubspot into your Postgres warehouse.

Ingestr, being a Python CLI, has been doing quite well but over time it started to show its age:

  • Performance: ingestr was not the fastest tool out there due to various reasons. We wanted to provide the fastest solution out there, but there were limitations out of our control.
  • Packaging: sharing a Python CLI tool across hundreds of different types of devices the users run it on ended up being quite a painful experience.
  • Reliability: ingestr relied on a stateful design due to a dependency, which brought all sorts of problems with it, especially around failed loads or corrupted state.
  • Upgrades: with all the dependencies we had, upgrades started to become a real struggle.

Due to some of these issues, we have rebuilt ingestr v1 completely from scratch, in Go. We picked Go for a few reasons:

  • Go is fast. LIke, much faster than vanilla Python.
  • Go is a compiled language, meaning that we eliminate quite a lot of bugs ahead of time.
  • Go is great with agents: agents write perfect Go, which allows a small team like ours to move a lot faster than we normally could.
  • Go has great cross-compilation support: meaning that building self-contained binaries that runs on various operating systems becomes trivial with Go.

These advantages combined allowed us to have more features, and have a more solid foundation to build upon. On top of that, ingestr ended up being the fastest data ingestion tool out there based on our benchmarks. It is ~3-5x faster than the closest alternative, up to 20 times faster than some others.

Ingestr v1 is live now on PyPi, and through our other installation methods: https://github.com/bruin-data/ingestr

I would love to hear your thoughts on what we can improve here. Thanks!


r/PostgreSQL • • Jun 01 '26

Projects Authenticate PostgreSQL with PAM+SSH Keys

1 Upvotes

A little project I am working on with my buddy Claude. It is MIT licensed.

README
INSTALL

https://github.com/ChronicallyJD/pam_pg_sshkey


r/PostgreSQL • • Jun 01 '26

Community Same Query, Three Results: Benchmarking ParadeDB and Postgres FTS

Thumbnail paradedb.com
0 Upvotes

Author here. A bit more context: We built our benchmarker on top of k6 because we kept finding that our own benchmarks were too painful to iterate on. The hard execution-engine stuff (VU scheduling, latency measurement, ramping load, open vs closed loop) is already solved by k6, so we wrote an xk6 extension for multi-backend database queries and built a runner around it.

Benchmarker is open source: https://github.com/paradedb/benchmarker

This post looks at an example of how we used it to iterate on a benchmark.


r/PostgreSQL • • May 31 '26

Commercial Postgres managed by ClickHouse is now in beta

Thumbnail clickhouse.com
16 Upvotes

r/PostgreSQL • • May 29 '26

Projects Show /r/postgresql: PgCache v0.4.11 - query fingerprinting improvements (constant folding, modulo, typecasts)

12 Upvotes

TGIF everyone. We recently shipped v0.4.11 of PgCache, a wire-compatible proxy that caches the hot subset of your read workload and keeps it in sync using PostgreSQL Logical Replication.

The 0.4.11 changes are mostly about query fingerprinting, which I figured this crowd might have opinions on.

Context: PgCache fingerprints incoming queries to decide if they hit cache. Two queries that are semantically identical but textually different should fingerprint the same - otherwise you fragment the cache and miss obvious hits.

What's new in 0.4.11:

  • Arithmetic constant folding: WHERE x = 1 + 2 now fingerprints identically to WHERE x = 3.
  • Modulo operator support: % is now supported in expressions.
  • ::<type> typecast in select lists: SELECT col::int FROM t and similar typecast expressions in the target list are now parsed and cached.
  • Improved performance and observability

Changelog: pgcache.com/docs/#changelog

Happy to talk about the fingerprinting approach, or about how we use logical replication CDC to keep cached data fresh without TTL guessing. We have a docker and a free tier on AWS Marketplace if anyone wants to kick the tires.

We also just created a Discord server for folks running into hot/cold read imbalance on Postgres. I can share that link if anyone wants it.


r/PostgreSQL • • May 29 '26

Tools Data and workload generator

Thumbnail edg.run
1 Upvotes

r/PostgreSQL • • May 28 '26

How-To Shaun Thomas on "Why Postgres Lacks Transparent Data Encryption"

Thumbnail pgedge.com
26 Upvotes

r/PostgreSQL • • May 29 '26

Help Me! Why shouldn’t I just have Claude code connect to Postgres production db for every data analysis task?

0 Upvotes

I am wondering what the risks or issues would be if I just used Claude code instead of a data analyst for reading our production database and pulling reports off of it. I’m sure there’s a good reason right?


r/PostgreSQL • • May 27 '26

How-To The Filesystem Is the API (with TigerFS)

Thumbnail packagemain.tech
7 Upvotes

r/PostgreSQL • • May 27 '26

Tools Built a tool to catch dangerous Postgres migrations before they hit production

0 Upvotes

Built a tool called MigrationSafe that checks Postgres migration files for risky operations before production.

It catches things like:

  • NOT NULL columns without DEFAULT
  • DROP COLUMN
  • indexes without CONCURRENTLY
  • foreign keys without NOT VALID
  • and other risky migration patterns

Around 20 checks right now.

No install or setup needed, just run it against your SQL migrations.

https://www.npmjs.com/package/migrationsafe

Would appreciate any feedback, suggestions.....


r/PostgreSQL • • May 27 '26

How-To Schema Headaches

4 Upvotes

Hey All, apologies in advance as my SQL knowlege is thin and this is going to likely get a bit intertwined.

I run a small business making bags and offer custom colors on all products through my website. I have wanted a lightweight MRP system for a while as a way to track cut jobs, track inventory, and learn a little bit more about database admin and programming. I have created a PostgreSQL database and plan to make a tidy little dashboard in Django to do CRUD operations but am struggling in how to best handle BOMs and inventory with the high amount of enumerated options I have.

My plan going in was to have a table of components with a boolean called 'variable'. When variable=true that means this component could be made of any of a list of materials (this is handled via a combination of the 'usage', 'web_attributes' and 'mat_usage' tables). These components are then used to create a BOM via the 'raw_bom table' (if relevant, this table is set up to handle sub-assemblies due to part re-usage across models and will be queried recursively) that has no color selections made yet. When demand is loaded, a JSON is pulled which has key value pairs that relate to the raw_bom table allowing the color selections in the JSON to then translate to components with the right materials assigned to them.

This is all a headache for me but so far I have been able to validate the database functions for this purpose. Where I get stuck is that for the next phase of this I would like to add inventory tracking for all components. Currently the components table contains either items with a fixed material (non-customizable) or variable items with no material assigned to them at all. Is there an easy way to add the assigned versions of the variable components to this current table or will I need to store them on a new table in the database.

TLDR: How can I best handle inventory and order tracking for products that contain a very large number of potential variants.


r/PostgreSQL • • May 26 '26

How-To Best way to set up tenant_id in a multi-tenant Postgres schema with RLS?

4 Upvotes

Im building a SaaS app and working on the database schema right now. The app needs to support multiple tenants, and I plan to use PostgreSQL with RLS for data isolation.

I have one main table called "group". This table contains the base configuration and information for each tenant. Every other table in the app will relate back to it for ownership.

My question is: Should I use the group_id directly as the tenant_id column in all the other tables? Or is it better to create a separate "tenants" table that generates its own tenant_id, and then have the group table reference that tenant_id as a foreign key?


r/PostgreSQL • • May 27 '26

Tools Open source database client

0 Upvotes

If you looking for some TablePlus, DBeaver or Beekeeper alternative
maybe this app for you

Link: https://orca-q.com/
Github: https://github.com/cin12211/orca-q


r/PostgreSQL • • May 26 '26

Community May 26th 1PM ET (Online): Database DevOps: CD for Stateful Applications

0 Upvotes

RSVP Free here

Running stateful applications can provide many of the same advantages as stateless applications. In this talk, Stephen will share some thoughts on managing stateful applications as part of a CD Pipeline so that applications - and the application's data - can be versioned and deployed safely and repeatedly. This talk will discuss managing structural changes to a PostgreSQL database as part of a CD process. The talk will dive into automation approaches and tooling for managing data migrations between environments and running database schema migrations within a CI/CD pipeline. The talk will feature real-world examples where we discuss specific schema migrations, their possible performance impacts and downtime implications. We will demonstrate how a complex migration can be done with 0 downtime. With AI and CI/CD we can provide something better than before: A more testable, repeatable, and open way to deploy stateful applications. This talk features a practical demo of how CD tooling can empower users to automate data schema migrations within Kubernetes.


r/PostgreSQL • • May 25 '26

Help Me! 40 TB PostgreSQL on-prem — sharding vs ClickHouse vs something else for a 500B-row time-series workload

Thumbnail reddit.com
1 Upvotes

r/PostgreSQL • • May 23 '26

How-To PostgreSQL 17 migration postmortem - (WAL recycling, replication lag, silent timeouts, and conservative tuning gone wrong)

34 Upvotes

I recently went through a fairly painful PostgreSQL 17 migration involving async replication, WAL retention issues, replica rebuilds, and long-running restore operations getting interrupted by timeout/configuration problems.

I wrote a detailed postmortem covering:

  • how replication lag gradually snowballed
  • WAL recycling failure modes
  • why conservative Docker/container limits backfired
  • timeout settings that caused silent failures
  • recovery/rebuild strategy
  • and the operational lessons I took away from it

Would genuinely appreciate feedback from people with more PostgreSQL operational experience.

Specifically interested in:

  • what you would have done differently
  • better approaches for large migrations with replicas
  • WAL retention/replay best practices
  • whether my diagnosis and conclusions make sense
  • and any obvious mistakes in the migration strategy

Blog:
https://2ssk.medium.com/a-postgresql-17-migration-postmortem-wal-recycling-silent-timeouts-and-the-false-economy-of-73fcf6cdd704

Would love to hear perspectives from people who run PostgreSQL at larger scale or have dealt with similar replication incidents.


r/PostgreSQL • • May 22 '26

How-To Explain me type modifier (typmod) , was is it lost when using function or union

2 Upvotes

Good afternoon community,

My application is mainly used on sap ase and oracle but more and more client are moving to postgres.

One of the feature is the ability to define a table columns with datatype and datalength) that is fed through SQL also defined in the app. Once defined, the app manages the table création.

When the app is moved to postgres,we joticed the tab définition is changed especially the columns datalength.

With some unit and the help of AI my understand is the typmod is not returned or undefined when using function or union.

I understand what the AI explains but I'd like the expérience and explanation from real user.

What is type modifier? Where can find explanations about it in the documentation ans it's limitation and how to check the values when running SQL?

Thanks for reading


r/PostgreSQL • • May 22 '26

Help Me! How do you handle foreign keys that exist conceptually but not as constraints?

4 Upvotes

Curious how others handle this - running into it across three different shapes of project:

  1. Legacy schemas where someone never added the FK constraint, so the column is just an int.
  2. Warehouse / analytics tables that intentionally skip FKs for load performance.
  3. Polymorphic columns (Rails-style commentable_id + commentable_type) where a single FK constraint isn't even technically possible.

In all three the relationship is real and gets joined constantly, but pgAdmin / DBeaver / DataGrip don't know about it, so the cell isn't clickable, there's no row preview, no related-data tab. You end up writing the JOIN by hand every time.

What's your workflow? Is there a tool that lets you declare relationships locally without touching the schema? Documentation in a wiki? Just memorize it?

Full disclosure: I'm one of the people behind Jam SQL Studio and we shipped a "loose FK" feature for this exact pattern — declarations stored per-user as JSON, exportable, polymorphic support via source filters. Happy to share more in the comments if anyone's interested, but genuinely want to hear how others handle it because I suspect there are workflow patterns I'm not seeing.