</>CodeWithKarani
All of Databases
Databases

PostgreSQL

Connections, vacuum, wraparound and the Postgres-specific gotchas.

21 articles

AI Engineering9 min read

Building RAG Over Your ERP Data: The Architecture That Actually Survives Production

Most ERP chatbots fail the moment someone asks for a total. Here is the two-plane architecture, the hybrid retrieval SQL, the reranking step and the permission model that separate a demo from a system finance will actually trust.

Read
Engineering Craft7 min read

Your Migration Will Run Twice: Write It That Way

Retried deploys, scaled replicas and tired humans all re-run migrations. Advisory locks, idempotent DDL, resumable batched backfills, the CREATE INDEX CONCURRENTLY trap, and a CI check that runs it three times.

Read
Databases8 min read

HikariCP Connection Timeouts Are Not a Pool Size Problem

Connection is not available, request timed out after 30000ms almost never means the pool is too small. Here is how to find what is holding connections and fix it properly.

Read
Databases7 min read

Postgres 'Could Not Resize Shared Memory Segment' Is Not Your Disk

No space left on device from Postgres in Docker means a 64MB /dev/shm, not a full volume. Here is the mechanism, the shm-size fix, and how to size it without inviting the OOM killer.

Read
Databases10 min read

Postgres Won't Accept Writes: The Transaction ID Wraparound Runbook

Postgres refuses every write to avoid wraparound data loss. Why single-user mode is usually the wrong first move, what pins the freeze horizon, and the online fix.

Read
Databases8 min read

FATAL: sorry, too many clients already - and why raising max_connections is wrong

Every Postgres connection is a separate OS process, so raising max_connections trades a clear error for an OOM. Here is the connection maths and the PgBouncer fix.

Read
Databases8 min read

Postgres Reserved Connection Slots: Why 97 Counts as Full

Postgres subtracts superuser_reserved_connections from max_connections, so your app never had the number you configured. Here is the arithmetic and the fix that actually holds.

Read
Databases9 min read

Prisma Connection Pool Timeouts in Production: What Actually Fixes Them

P2024 is a queueing symptom, not a pool-size problem. Why raising connection_limit turns a slow service into an outage, and what to do instead on serverless.

Read
Databases10 min read

Your Redis Cache Is Serving Yesterday's Data: Fixing Invalidation Properly

Stale cache incidents have no error message, only a DEL that returns 0. Here is why Redis invalidation breaks, the structural fix, and how to prove it worked.

Read
Databases9 min read

Docker Compose Postgres connection refused: localhost is not your database

Inside a container, localhost means that container. Why your app cannot reach the Postgres service, the service-name fix, and the healthcheck that stops the race condition.

Read
Databases7 min read

FATAL: role "postgres" does not exist in Docker: the POSTGRES_USER volume trap

The Postgres Docker image only reads POSTGRES_USER the first time it initializes an empty volume. Change it later and you get a role error that looks like a permissions bug but isn't.

Read
Databases8 min read

Postgres Table Bloat: Why the Default Autovacuum Settings Are Too Passive

Postgres waits until 20% of a busy table is dead tuples before autovacuum fires, so bloat piles up silently. Here is how to tune it per table and confirm vacuum is keeping up.

Read
Databases9 min read

Postgres PANIC 'No space left on device': do not delete pg_wal

A full disk PANICs Postgres into a crash loop, and deleting WAL files to free space turns it into a restore from backup. The safe recovery order, and the slot that caused it.

Read
Python & FastAPI9 min read

QueuePool Limit Reached Under FastAPI Load: pool_size Is Not the Fix

The SQLAlchemy QueuePool timeout under FastAPI load is about how long connections are held, not how many exist. Why raising pool_size fails, and the async session scoping that works.

Read
Linux & Servers7 min read

'The Server Is Slow' With Zero Budget and No APM: A Command-Line Triage

No Datadog, no New Relic, no dashboards. Here is a free, repeatable command-line order to find why a production server is slow, using tools already on the box.

Read
Databases6 min read

pg_upgrade Fails on Extensions, Not Core: the Pre-Flight Check Teams Skip

pg_upgrade migrates Postgres core but not extensions, so PostGIS version gaps make the new cluster fail to start. Here is the inventory-and-match checklist to run first.

Read
Databases6 min read

Idle in Transaction: The Postgres Sessions Quietly Bloating Your Database

A Postgres session sitting idle in transaction holds its snapshot and locks, blocks autovacuum, and grows table bloat for hours. Here is how to find them, kill them, and stop them coming back.

Read
Databases6 min read

Reading Postgres EXPLAIN ANALYZE Correctly: the 'loops' Multiplier Everyone Misses

The 'actual time' on a plan node is per loop, not total. Miss the loops=N multiplier and you will underestimate a node's real cost by orders of magnitude and tune the wrong query.

Read
Databases8 min read

Postgres timestamp vs timestamptz: the DST bug that only breaks twice a year

A plain timestamp column drops the time zone, so records shift by an hour at daylight saving changes and the bug hides for months. Here is the root cause, the fix, and a safe migration to timestamptz.

Read
Databases7 min read

Postgres 'no pg_hba.conf entry for host': the scoped fix, not 0.0.0.0/0

The FATAL: no pg_hba.conf entry error has a two-minute fix that also opens your database to the whole internet. Here is the scoped rule to add instead.

Read
Databases7 min read

The Postgres JSONB Anti-Pattern: When Flexible Schema Becomes No Schema

Burying queried fields in a JSONB column feels like skipping migrations until you cannot index or join them. Why the blob costs you, and the four-step migration out.

Read