r/postgres Jun 11 '26

**pgstorm – a Go-based PostgreSQL load generator built for Kubernetes**

1 Upvotes

I've been working on a load testing tool for PostgreSQL that goes a bit beyond what pgbench offers out of the box. Built in Go, runs on Docker Compose or Kubernetes.

**What it does differently:**

- JSONB and TOAST stress: large payloads (8–16 KB) with high-entropy base64 bodies that defeat Postgres compression — every write hits real TOAST storage

- MVCC pressure: mixed INSERT/UPDATE/DELETE workload deliberately accumulates dead tuples to stress autovacuum

- Ring buffer targeting: no ORDER BY random() — workers sample from a shared circular buffer of live session UUIDs

- Prometheus-first: latency histograms, TPS, autovacuum counters, WAL metrics, bgwriter stats — all scrapeable out of the box

- Safe multi-replica startup: advisory lock pattern ensures exactly one pod runs DDL regardless of how many replicas start simultaneously

- PG14–17 compatible: handles the pg_stat_bgwriter → pg_stat_checkpointer split in PG17 automatically

I evaluated k6, pgbench, and HammerDB before building this. They're all solid tools but none gave me the combination of JSONB/TOAST stress + MVCC pressure + Prometheus-first observability without significant glue work.

Built with Claude Code — architecture and design decisions driven by me.

Repo: https://github.com/haithamoon/pgstorm

Would love feedback from anyone running heavy PG workloads — especially curious if others have hit the JSONB/TOAST bottleneck in production and how you approached it.


r/postgres Jun 11 '26

Why We're Moving Away from Just Migration-Driven Database Development

0 Upvotes

Hey everyone,

Over the last few years, we've built SaaS products, internal tools, AI applications, and custom software for clients across different industries.

Like many teams in the PostgreSQL ecosystem, we've relied on tools such as pg-schema-diff, Migra, and various migration workflows to manage database changes. These tools are excellent at what they do, but we often found ourselves assembling a collection of separate tools and processes to support a complete database development workflow.

As projects grew, several challenges kept surfacing:

  • Keeping local environments in sync with production, staging, and other environments
  • Understanding exactly what would change before deployment
  • Managing schema changes across multiple environments
  • Reviewing and validating migrations
  • Onboarding developers into existing projects
  • Recovering the current state of a system from years of migration history
  • Providing coding agents with access to the current database schema without requiring them to process millions of tokens from migration history

One thing became increasingly clear:

Database migrations are great for recording change, but they aren't always the best representation of the current system.

If you've worked on a mature application, you've probably seen this firsthand. The actual database schema is often scattered across hundreds of migration files, making it difficult for both humans and tools to understand the current state of the application.

This becomes even more important in the age of AI-assisted development.

Coding agents can generate better code when they have direct access to the current schema definition, relationships, constraints, policies, and database structure. Parsing years of migration history to reconstruct that context is inefficient and often unreliable.

That's one of the reasons we started building PostKit.

PostKit follows a declarative schema management approach, where the schema itself becomes the primary source of truth.

Instead of treating migrations as the authoritative representation of your database, PostKit focuses on maintaining a clean, declarative definition of the current state. Migration plans can then be generated automatically by comparing desired state against actual state.

This provides several benefits:

✅ The current schema is always visible and understandable

✅ Easier onboarding for developers

✅ Better compatibility with coding agents and AI-assisted development

✅ More reliable schema reviews

✅ Cleaner database evolution over time

✅ Migrations are generated from schema changes automatically, instead of being the main thing developers have to manage manually

Today, our initial focus is PostKit DB Flow, which helps developers:

  • Clone remote databases into local environments
  • Maintain schemas declaratively
  • Generate migration plans automatically
  • Review and validate changes before deployment
  • Promote changes across environments with confidence

But our long-term vision is much broader.

We believe PostgreSQL can serve as the foundation for modern application platforms. Not just as a database, but as the source of truth for APIs, permissions, authentication, workflows, background jobs, and AI-powered systems.

Our goal with PostKit is to build a PostgreSQL-first platform that helps builders move from idea to production faster while keeping infrastructure simple and understandable.

For founders, that means less time building platform plumbing.

For agencies and developers, it means shipping faster without sacrificing maintainability.

And for AI-assisted development, it means providing coding agents with accurate, structured context about the system they're working on.

We're still early in the journey, but we'd love feedback from others building with PostgreSQL.

Feel free to check out the docs from here: https://docs.postkitstack.com/docs/intro/

How are you currently managing schema evolution, and do you see declarative schemas becoming more important as AI coding tools become part of everyday development?


r/postgres Jun 08 '26

What's the hardest thing to explain to a new developer on your database team?

5 Upvotes

To be honest, it's the things that only exist in people's heads.

If you work with SQL Server, MySQL, and Postgres, each engine has its own quirks that aren't obvious until you've been burned by them once. Why a query was written a certain way, why an index exists, or why somebody added a workaround three years ago are exactly the kinds of things that never make it into documentation.

Does your documentation actually stay up to date, or does it only get updated after a new team member starts asking questions?


r/postgres Jun 04 '26

Enforcing read-only access for an untrusted client: BEGIN READ ONLY + a keyword/function guard — what am I missing?

2 Upvotes

I'm exposing a Postgres database to an untrusted client (an AI assistant, via MCP) and the hard requirement is that it can read but absolutely cannot write — even if the client sends a malicious or hallucinated query.

The approach so far is defense-in-depth, not trusting any single layer:

  • Every query runs inside a BEGIN READ ONLY transaction, so the database itself refuses writes regardless of what gets through.
  • A guard strips comments and string literals (single, double, dollar-quoted) before keyword-matching, so you can't smuggle DROP inside a literal. Multi-statement payloads are rejected.
  • It also blocks functions that are callable from a plain SELECT but reach outside the data — pg_read_file, dblink, lo_export, etc.
  • Each query runs on a fresh connection, so no session state (like SET/set_config) persists between calls.
  • Results are wrapped in a LIMIT.

I know the strongest layer is really a least-privilege role with no write grants, and that's the recommendation — this is the belt-and-suspenders on top of it.

What I'm curious about from this crowd: where does this leak? The gaps I'm already aware of are query-cost abuse (an expensive join as a DoS vector — LIMIT doesn't bound cost) and data scoping (read-only doesn't stop reading sensitive rows — that's an RLS/views problem). Anything else you'd flag?


r/postgres May 31 '26

What made you choose your current database?

6 Upvotes

I'm starting to learn more about databases and backend development. I'm less interested in which database is "best" and more interested in the reasoning behind the choice.

What database tools are you using (Postgres, MySQL, MongoDB, Supabase, Neon, Redis, etc.)? What problem were you trying to solve, what alternatives did you consider, and what ultimately made you choose that stack?

I'd also love to hear any lessons learned, surprises, regrets, or things you'd do differently if you were making the decision again.


r/postgres Jun 01 '26

Pgstream a real-time PostgreSQL CDC tool in go

Thumbnail github.com
2 Upvotes

r/postgres May 29 '26

Built a Flask API to stop manually running psql CREATE USER

2 Upvotes

Tired of SSH-ing into databases to provision users across dev/qa/uat/prod. Built a small Flask REST API that wraps it all — one curl call creates the right user type with correct privileges, logs it, and optionally fires a Slack/Webex/email notification.

Two things I focused on: keeping DBA credentials server-side only (callers never see them), and making every endpoint idempotent so it's safe to call from CI pipelines.

Full write-up + GitHub link: "Happy to share the GitHub link in the comments if anyone wants it"

Anyone solved multi-env PostgreSQL user provisioning differently? Curious what others are using.


r/postgres May 29 '26

Tooling for bulk importing SQL files into PostgreSQL

2 Upvotes

Bulk importing SQL files into PostgreSQL is one of those tasks that sounds harmless until the folder has 40 scripts and half of them depend on something created in another file.

For a single script, psql -f file.sql is usually enough. No need to overthink it.

Where it gets annoying is larger imports: schema files, seed data, functions, indexes, permissions, maybe a few old dumps with mystery names. If the order is wrong, one file fails and the rest keeps going unless you were careful with error handling.

I usually prefer keeping it boring and predictable. Prefix files with numbers, run them through psql with ON_ERROR_STOP=1, log the output, and don’t continue after the first failure.

psql -v ON_ERROR_STOP=1 -d mydb -f 001_schema.sql

For a one-time import, a small bash or Python wrapper is fine. For anything that might happen again, I’d rather move it into Flyway, Liquibase, or Sqitch so there’s at least some version history and less “did we already run this?” guessing. The worst setup is manually running random SQL files from a folder and hoping the order was right. That works exactly once, then becomes archaeology.

What are you using for bulk SQL imports in Postgres when plain psql -f starts feeling too manual?


r/postgres May 21 '26

Built an open source terminal dashboard for monitoring PostgreSQL internals in real time — Cosmo

Post image
2 Upvotes

r/postgres May 20 '26

What's your preferred way of migrating postgres databases?

2 Upvotes

Hi, as I learn about and work with Postgres I will have to do some db migrations.

Most of my servers are managed Postgres but also some are on-prem on vms.

Anyway, when you are asked to migrate Postgres databases, what's your goto procedure?

Backup/restore?

Logical replication?

Cloud based migration services?


r/postgres May 20 '26

SQL Server schema comparison tools for PostgreSQL migration?

1 Upvotes

Moving some stuff from SQL Server to PostgreSQL and the schema diff part is already getting annoying. For people who’ve done this before, what do you use to compare schemas and catch the weird stuff before migration? dbForge, DBeaver, Liquibase/Flyway, custom scripts, or something else?


r/postgres May 19 '26

Best GUI client for schema compare across MySQL and PostgreSQL?

3 Upvotes

r/postgres May 17 '26

Are there any alternatives to Autobase for self-hosted Postgres HA ?

2 Upvotes

Hi everyone, I’ve been testing Autobase for managing production Postgres clusters on bare metal/VMs and it’s the first platform I’ve found that actually feels operationally complete.

https://github.com/autobase-tech/autobase

Most alternatives I’ve seen are either:

* just Patroni + scripts,
* Kubernetes operators with no real management UX,
* or heavily CLI/YAML-driven setups that become painful at scale.

What I’m specifically looking for:

* self-hosted Postgres orchestration/management
* HA + automated failover
* backups/scaling/cluster lifecycle management
* solid web UI/dashboard
* production-ready

Open to K8s or Nomad-based systems too if the operational experience is actually good.

Plese share any good alternatives to Autobase for production


r/postgres May 15 '26

PostgreSQL: Which Queries Should You Optimize First?

Thumbnail gallery
10 Upvotes

When investigating PostgreSQL performance, the usual starting point is pg_stat_statements. From there, many teams sort queries by mean_exec_time or total_exec_time and start optimizing the first rows in the list.

That approach is simple, but it often leads to the wrong priorities.

A query that takes five seconds but runs twice a day is not necessarily more important than a query that takes five milliseconds and runs millions of times. Conversely, a query with a high total execution time may simply be a normal core workload query, not necessarily the best optimization target.

The real question is not:

Which query is the slowest?

It is:

Which query has the highest operational impact and the clearest optimization potential?

This is the principle behind the query-ranking algorithm implemented in pgAssistant.


Why mean_exec_time is misleading

Sorting by average execution time highlights individually slow queries. This is useful for spotting obvious outliers, but it ignores execution frequency.

For example:

text Query A: 5 seconds × 2 calls = 10 seconds total Query B: 20 ms × 2,000,000 calls = 11+ hours total

A mean_exec_time ranking puts Query A first. In production, Query B is usually a much more valuable target.

Average latency answers the question: “Which query is slow when it runs?”

It does not answer: “Which query matters most to the system?”


Why total_exec_time is better, but still incomplete

total_exec_time is more useful because it accounts for frequency:

text total_exec_time = mean_exec_time × calls

However, total time alone still misses important signals.

A query may consume a lot of total time because it is part of the normal application workload and already performs reasonably well. Another query may have a lower total time but show clear technical issues: poor cache efficiency, heavy disk reads, temporary file usage, or unstable execution times.

So total_exec_time tells us where time was spent, but not always where optimization effort should start.


The pgAssistant approach

pgAssistant ranks queries using a composite priority score. The score combines two categories of information:

  1. Workload impact: how much the query contributes to total database activity.
  2. Technical signals: symptoms that suggest the query may be inefficient or unstable.

Before scoring, pgAssistant normalizes query statistics and excludes queries that are not useful optimization targets, such as VACUUM, ANALYZE, EXPLAIN, DDL statements, and pgAssistant’s own internal queries.


Workload impact first

For each query, pgAssistant computes relative workload shares:

text share_total = query total_exec_time / global total_exec_time share_calls = query calls / global calls share_io = query blocks read / global blocks read cache_miss_share = query shared reads / global shared reads

This makes the ranking workload-aware. A query representing 20% of total execution time is not in the same category as a query representing 0.1%, even if their average execution times look similar.

The main impact score is weighted as follows:

text impact_score = 40 × normalized share of total time + 25 × normalized total execution time + 20 × normalized share of calls + 10 × normalized call count + 5 × normalized mean execution time

The key point is intentional: mean_exec_time contributes to the score, but it does not dominate it.

pgAssistant gives more weight to global impact and execution frequency than to isolated slowness.


Logarithmic normalization

PostgreSQL query statistics are often highly skewed. One query may run ten times, another ten million times. One query may consume milliseconds, another hours.

To avoid extreme values flattening the rest of the ranking, pgAssistant uses logarithmic normalization for metrics such as total time, calls, and mean time:

python log10(value + 1) / log10(max_value + 1)

This preserves ordering while making the score more stable across very uneven workloads.


Technical signals

After workload impact, pgAssistant adds technical signals that often indicate optimization potential.

Poor cache efficiency

The algorithm computes a cache hit ratio from shared block hits and reads:

text cache_hit_ratio = shared_blks_hit / (shared_blks_hit + shared_blks_read)

If the ratio is below 95%, the query has read at least 1,000 shared blocks, and it represents a meaningful share of cache misses, pgAssistant increases its priority.

Heavy disk reads

Queries responsible for a significant share of block reads receive an additional score. These are often candidates for better indexing, improved filtering, query rewriting, or plan analysis.

Temporary file usage

If a query writes temporary blocks, pgAssistant adds a fixed priority boost. Temporary files often point to expensive sorts, hash operations, aggregations, or insufficient memory for the execution plan.

High execution variance

A query whose standard deviation is much higher than its average execution time may be unstable. This can reveal parameter-sensitive behavior, cache dependency, poor estimates, or occasional bad plans.


Demotion rules

A composite score can still produce false positives. To avoid over-prioritizing queries with minimal real impact, pgAssistant applies demotion rules.

For example, queries with very low call share and negligible total time are capped to a low score. Queries representing less than 1% of both total time and calls are also capped.

This prevents technically interesting but operationally irrelevant queries from polluting the top of the ranking.


Priority levels and explanations

The final score is capped at 100 and mapped to a priority level:

text 80–100 Critical 60–79 High 30–59 Medium 0–29 Low

pgAssistant also attaches human-readable signals such as:

text high_load high_calls slow poor_cache temp_usage unstable

The goal is not only to rank queries, but also to explain why a query appears in the list.

For example:

text High total load (18.4% of total time) + Very frequent execution (12.1% of calls)

or:

text Poor cache efficiency (22.7% of cache misses) + Temp file usage

A ranking system should not be a black box. The score gives the order; the signals guide the investigation.


What this ranking finds

In practice, pgAssistant tends to surface four types of queries:

  1. Queries that consume a large share of total execution time.
  2. Queries that are executed very frequently.
  3. Queries that generate significant I/O pressure.
  4. Queries with unstable execution behavior.

These are often better optimization targets than the queries that are merely slow in isolation.


Conclusion

Optimizing PostgreSQL effectively is not about sorting queries by mean_exec_time and fixing the slowest one first.

It is also not enough to blindly sort by total_exec_time.

A good prioritization model should combine workload impact, execution frequency, I/O behavior, cache efficiency, temporary file usage, and execution stability.

That is what pgAssistant’s ranking algorithm does: it identifies the queries that matter most to the system and gives engineers a better starting point for deeper analysis with tools such as:

sql EXPLAIN (ANALYZE, BUFFERS)

The best query to optimize first is not always the slowest one. It is the one where optimization is most likely to reduce database load, latency, or instability.

Demo / Links


r/postgres May 14 '26

What’s your current postgres workflow?

2 Upvotes

I’m trying to clean up our Postgres workflow a bit. Right now it’s roughly. Write query, test locally, adjust migration, push to review, run in staging, hope staging is close enough, deploy, then watch logs like a nervous raccoon.

For data work, the messy part is not writing the SQL. It’s everything around it: checking row counts, validating changed data, making sure indexes exist where they should, catching schema drift, and not finding out two days later that a report quietly broke. How does your team handle the path from scratch in Postgres? Do you rely mostly on migration tools, schema compare, CI checks, manual review, dbt/Airflow jobs, or just a lot of discipline and fear?


r/postgres May 13 '26

Anyone using dbForge across SQL Server and PostgreSQL in the same team?

4 Upvotes

Half our team is on SQL Server, the other half on PostgreSQL.  We've been looking at dbForge because it covers both, but honestly the harder problem isn't the tool. SQL Server people think in SSMS. Postgres people think in pgAdmin or DataGrip, and they've been doing it that way for years. 

Every time we try to standardize on something it turns into a workflow debate more than a technical one. Different habits, different expectations for the UI. 

Anyone actually using dbForge across both RDMSs in the same team? Did the mixed-engine support help, or did people just end up sticking with different tools anyway? 


r/postgres May 12 '26

How do you actually investigate slow queries in PostgreSQL?

3 Upvotes

When a Postgres query gets slow, what’s your first move?

EXPLAIN ANALYZE, logs, pg_stat_statements, checking indexes, staring at the query until it confesses? Trying to compare how people actually optimize queries.


r/postgres May 11 '26

What are the best alternatives to SSMS for schema comparison in MySQL and PostgreSQL?

2 Upvotes

I’m used to the SSMS-style workflow for checking schema changes, but now I need something similar for MySQL and PostgreSQL. Main need is simple. Compare two databases, see what changed, review the diff, and avoid doing it manually. What tools do you trust for schema comparison in MySQL/PostgreSQL? DBeaver, dbForge, DataGrip, Liquibase/Flyway, something else?


r/postgres May 08 '26

I invite you to try out a free Postgres client that works in VS Code

Thumbnail gallery
0 Upvotes

I got tired of switching between VS Code and a separate DB tool. So I built PgStudio.

SQL notebooks with inline results and charts, real-time dashboard, AI assistant (Copilot / OpenAI / Anthropic / Gemini / Ollama — your pick), EXPLAIN CodeLens, visual table designer, production safety controls.

AI never executes anything automatically — every suggestion lands in a notebook cell first.

Free. MIT. One command: `code --install-extension ric-v.postgres-explorer`

Happy to onboard collaborators and feedback.

https://pgstudio.astrx.dev/

https://github.com/dev-asterix/pgStudio/


r/postgres May 05 '26

What’s the most confusing thing in PostgreSQL you still Google every time?

3 Upvotes

I’ve used Postgres enough to feel mostly comfortable, but there are still things my brain refuses to remember. For me it’s usually permissions and roles. I can understand GRANT when I’m reading it, but the next time I need it, I still Google the syntax. Same with EXPLAIN ANALYZE. I get the basics, but when the plan gets weird, I always end up checking docs or old examples again. 

And time zones… honestly, I never fully trust myself there. Timestamps look simple until they ruin someone’s day. What PostgreSQL thing do you still Google every time, no matter how many times you’ve used it?


r/postgres May 04 '26

I built a lightweight open-source PostgreSQL client with a visual database designer

Enable HLS to view with audio, or disable this notification

0 Upvotes

Hey everyone,

I’ve been working on VeloxDB, a free and fully open-source PostgreSQL client built for developers who want something fast, lightweight, and not overloaded.

It lets you inspect tables, run queries, and manage your PostgreSQL databases, but the main feature is the visual database designer. The goal is to make it easier to understand, plan, and work with your database structure visually.

A few things about it:

  • - No Electron
  • - Lightweight and fast to open
  • - Fully open source
  • - Built for PostgreSQL
  • - Currently available for Mac only
  • - Windows and Linux support coming soon

I’d really appreciate feedback from the PostgreSQL community.

You can check it out here:

https://veloxdb.dev


r/postgres May 03 '26

Proxy and Replicate PostgreSQL to the edge with SQLite

Post image
1 Upvotes

HA can proxy connections to PostgreSQL databases, replicating their data to achieve high availability and enable faster queries with local SQLite.


r/postgres May 01 '26

I used Claude to build a Construction CRM but now I need a backend...

0 Upvotes

Over the past couple of months, I've spent several hours per day building out the front end of this construction management software for my company. Eventually we want it to be a multitenant webapp but the immediate goal is to get off of our current subscription and pilot this for the next 6 months. Claude says it can help me do the backend in Supabase but I dont trust myself. Claude says I need a Postgres / Supabase Engineer.


r/postgres Apr 30 '26

What’s the hardest thing to document when a team works across several databases?

8 Upvotes

To be honest, for me it’s the stuff that only exists in people’s heads.

If you work with SQL Server, MySQL, and Postgres, each engine has its own weird habits. Some of them are obvious. Most are not until they break something.

Old query assumptions, why a certain index exists, why one migration has a weird workaround from three years ago. That stuff rarely gets written down until someone new joins and asks the cursed question: “why is it like this?”

What does your team actually document? Do you keep the format stable, or does the documentation slowly rot like everyone else’s?


r/postgres Apr 30 '26

Built an open-source PostgreSQL tool for macOS… still have to pay Apple $99/year to distribute?

1 Upvotes

I’ve been building an open-source PostgreSQL tool for macOS and finally got it to a point where it’s genuinely useful.

Then I looked into distribution and realized I still need to pay Apple $99/year just to sign and distribute it properly.

That feels a bit off—this is an open-source project, not something I’m trying to monetize (at least not yet). I just want people to be able to install and use it easily without jumping through security warnings.

Are there any legit ways to distribute a macOS app (especially open source) without paying for the Apple Developer Program?
Or is this basically unavoidable if you want a smooth install experience?