The Postgres Mistakes
We All Still Make

Scott Mead
Senior Staff Engineer · Lakebase · Databricks

NYC Postgres Meetup · November 18, 2026

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

The Premise

  • Postgres is thirty years old.

  • I've been working on it for 22.

  • We're all doing the same [bad] things over and over.


  • Every mistake here "works on my laptop"
  • Every one shows up in metrics
  • They all seem innocent at first
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Mistake #0: it's always connections

Postgres runs a process per connection.


  • connect is fork(), memory, authentication, a cold catalog cache, before any row is touched
  • a 5 ms query connect:~2ms run: 5 ms
    • Without a pool, every request is a connect / disconnect
  • rate is the issue. A number of connections is one problem, a high rate of connections grinds the system

A pool connects once and reuses the backend

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Where the rate comes from

def handle(request):
    conn = psycopg2.connect(DSN)        # a new connection per request, no pool
    try:
        with conn.cursor() as cur:
            cur.execute("SELECT ... WHERE id = %s", (request.user_id,))
            return cur.fetchone()
    finally:
        conn.close()                    # torn down again. Next request: fork again
  • Or forty app servers, each with a pool of fifty per core
  • Or reconnect with no delay
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Use a pooled connection

from psycopg2 import pool

db = pool.ThreadedConnectionPool(minconn=2, maxconn=10, dsn=DSN)   # once, at startup

def handle(request):
    conn = db.getconn()                 # borrow an open connection, no fork
    try:
        with conn.cursor() as cur:
            cur.execute("SELECT ... WHERE id = %s", (request.user_id,))
            return cur.fetchone()
    finally:
        db.putconn(conn)                # give it back, still connected

Same pattern in psycopg 3, HikariCP in Java, and database/sql in Go

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Detection

-- PG 14+. sample twice, a minute apart; the difference is the churn
SELECT now(), datname, sessions,
       sessions_abandoned, sessions_fatal,
       sessions_killed, stats_reset
  FROM pg_stat_database
  • sessions: sessions established on this database since stats_reset
  • sessions_abandoned: the client went away without disconnecting
  • sessions_fatal: ended by a FATAL error
  • sessions_killed: ended by an operator
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Deployment Options

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Mistake #1: ignoring MVCC

users, heap page 0 8,192 bytes, 48 free 8,192 bytes, 56 free 8,192 bytes, 0 free 8,192 bytes, 48 free 8,192 bytes, 0 free 8,192 bytes, 48 free 8,192 bytes, 48 free xmin is the xid that wrote the version. xmax is the xid that deleted or replaced it xmin xmax id first_name last_name and the other 150 rows on this page 500 500 502 502 502 1 Jane Smith Smith 48 bytes xmax 502, in flight old version dead until VACUUM 48 bytes free. Nothing coming is that small: bloat free space, 48 bytes free space, 48 bytes, as VACUUM left it 48 bytes free. Nothing coming is that small: bloat 504 3 Susie Rivera 48 bytes, reused 500 500 2 Mike Rivera Rivera 48 bytes 48 bytes 502 502 502 1 Jane Smith-Rivera Smith-Rivera Smith-Rivera 56 bytes 56 bytes, in flight 56 bytes, live 56 bytes 48 bytes free that no row fits. The table grew a page instead xid 500 wrote both rows and committed. 56 bytes left on the page UPDATE wrote a second version of row 1 and set xmax on the first. Page full COMMIT changed nothing on this page. It marked 502 committed in the clog two live versions, one dead. Every reader steps over it until VACUUM VACUUM removed the dead version. 48 bytes free the INSERT reused the 48 bytes. The table did not grow rewind: the page as VACUUM left it, 48 bytes free 48 bytes free that no row fits. The table grew a page instead users, heap page 1, new 7500 4 Bartholomew Featherstonehaugh 8,192 bytes, 8,128 free 64 bytes free space map (FSM), one entry per page page 0: 48 bytes free. Too small for any row that comes in page 0: 56 bytes free page 0: 0 bytes free page 0: 48 bytes free page 0: 0 bytes free page 0: 48 bytes free page 0: 48 bytes free. Too small for any row that comes in page 1: 8,128 bytes free page 1: 8,128 bytes free transaction 501, the reader BEGIN; SELECT * FROM users; BEGIN; SELECT * FROM users; SELECT * FROM users; BEGIN; SELECT * FROM users; SELECT * FROM users; SELECT * FROM users; BEGIN; SELECT * FROM users; SELECT * FROM users; SELECT * FROM users; SELECT * FROM users; id | first_name | last_name ----+------------+---------- 1 | Jane | Smith 2 | Mike | Rivera (2 rows) id | first_name | last_name ----+------------+------------- 2 | Mike | Rivera 1 | Jane | Smith-Rivera (2 rows) id | first_name | last_name ----+------------+------------- 3 | Susie | Rivera 2 | Mike | Rivera 1 | Jane | Smith-Rivera (3 rows) id | first_name | last_name ----+-------------+------------------ 2 | Mike | Rivera 1 | Jane | Smith-Rivera 4 | Bartholomew | Featherstonehaugh (3 rows) heap order: page 0 top to bottom, then page 1. No ORDER BY snapshot: everything committed before now still Smith. 502 is in flight, its version is invisible Smith-Rivera. New statement, new snapshot. Note the order three rows, in the order they sit on the page two rows, the page as VACUUM left it heap order: page 0 top to bottom, then page 1. No ORDER BY transaction 7500, months later, a new user transaction 502, marry me autovacuum, or VACUUM users transaction 504, a new user take two: same page, a different newcomer transaction 7500, months later, a new user BEGIN; VACUUM users; BEGIN; rewind to step 8: page 0 has 48 bytes free BEGIN; INSERT INTO users UPDATE users SET last_name = 'Smith-Rivera' dead versions become free space on the page INSERT INTO users VALUES (3, 'Susie', 'Rivera'); the FSM still points at page 0 INSERT INTO users VALUES (4, 'Bartholomew', 'Featherstonehaugh'); WHERE id = 1; the free space map (FSM) records how much VALUES (4, 'Bartholomew', 'Featherstonehaugh'); COMMIT; COMMIT; COMMIT; COMMIT; 64 bytes. Page 0 has 48 free, so the table grows a page in flight: holds xid 502 and a connection committed no lock on the table, readers and writers carry on 48 bytes after padding. The FSM sent her to page 0 what if the next row had been bigger 64 bytes. Page 0 has 48 free, so the table grows a page the whole story 1. Bulk load 2. A reader takes a snapshot 3. UPDATE writes a new version 4. The reader still sees Smith 5. COMMIT 6. New statement, new snapshot 7. A dead version 8. VACUUM frees 48 bytes 9. A row that fits 10. Rewind to the vacuumed page 11. A row that does not fit dead versions become free bytes. A row that fits reuses them; a row that does not grows the table and leaves the gap behind xid 500 bulk-loads the table in one transaction and commits. The page is otherwise full 501 reads. Its snapshot is everything committed before the statement started 502 updates row 1. Postgres never overwrites: a new version is written, and the old one gets xmax = 502 501 reads again and still sees Smith. 502 has not committed, so its version is invisible to everyone else 502 commits. The page does not change; the commit log now says 502 is committed 501's next statement takes a new snapshot and sees Smith-Rivera (READ COMMITTED, the default) the old version is dead. It stays on the page until VACUUM, and every reader steps over it until then VACUUM compacts the page, frees the dead version's 48 bytes, and records them in the free space map 504 inserts Susie Rivera, 48 bytes after padding. The FSM points at page 0, so she takes the freed space rewind to step 8. Same page, 48 bytes free. Now a different newcomer, months later 7500 inserts a 64-byte row. 48 is not enough, so the table grows a page. The 48 bytes stay empty: bloat back (b) next (n) play (a) step 1 of 11
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

The users table in 2026

CREATE TABLE users (
                id bigint PRIMARY KEY,
                profile jsonb );

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

One year in

-- row 1, version 2, after a year of features: 688 bytes
{"id": 1, "name": "Jane Smith-Rivera", "email": "[email protected]",
 "spouse": {"id": 2, "name": "Mike Rivera"},
 "addresses": [{"type": "home", "line1": "14 Bryant Park Pl",
                "city": "New York", "zip": "10018"},
               {"type": "work", "line1": "350 Fifth Ave",
                "city": "New York", "zip": "10118"}],
 "preferences": {"theme": "dark", "language": "en-US",
                 "notifications": {"email": true, "sms": false, "push": true}},
 "login_history": ["2026-11-01T08:12:00Z", "2026-11-03T18:40:11Z",
                   "2026-11-09T07:55:43Z", "2026-11-14T21:03:27Z",
                   "2026-11-17T06:48:09Z"],
 "updated_at": "2026-11-18T18:30:00Z"}
  • Version 1 of row 1 is dead. Its 110 bytes fit nothing in this table any more
  • profile || '{"theme": "light"}' rewrites all 688 bytes, not the 17 you changed
  • One login a day in login_history: 250 KB of dead versions per user per year
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

A year of logins on one row

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

It's always connections

  • The reader steps over 364 dead versions to find the live one
  • 221 pages where there should be one. The row is a disk read, not a cache hit
  • Every query holds its connection for the extra pages. Same traffic, longer holds
  • The pool opens more connections to keep up, months after the schema decision
  • Autovacuum reads and rewrites the same pages, competing with the queries for the disk
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Same traffic, longer holds

app instance pool of 20 clients app instance pool of 20 clients app instance pool of 20 clients users table 1 page per row 20 pages per row 80 pages per row 150 pages per row 221 pages per row Postgres: 5 server connections, grows to 20 query query query query query query new query new query new query new query new query new query new query new query new query new query new query new query new query new query new green: free orange: busy, reading dead versions to find the live row query query query query every query reads one page, holds its connection for a millisecond, and gives it back the table bloats. The same query reads 20 pages, then 80. Each one holds its connection longer no free connection, so the pool opens a few more. They fill the same way: same traffic, longer holds every server connection is busy reading dead versions. The pool is exhausted and the app is down 221 pages per row. The database is saturated, the app is down, and not a line of code changed pause (a) restart (r)
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

The fix

  • The document grows with every login, so every version is bigger than the gap the last one freed
  • Facts that accumulate go in a table. The users row never changes again
-- before: one login rewrites the whole profile, 9,296 bytes by day 365
UPDATE users
   SET profile = jsonb_set(profile, '{login_history}',
                           profile->'login_history' || to_jsonb(now()))
 WHERE id = 1;

-- after: a table. INSERT one 40-byte row, UPDATE nothing
CREATE TABLE login_history (
       user_id       bigint       NOT NULL REFERENCES users (id),
       logged_in_at  timestamptz  NOT NULL DEFAULT now(),
       PRIMARY KEY (user_id, logged_in_at)
);

INSERT INTO login_history (user_id) VALUES (1);
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Better, not best

  • Overwrite a field instead of appending to a list. Every version is the same 110 bytes
  • The gap vacuum frees fits the next version, so the table stops growing
  • Still one dead version per login. Vacuum has to keep up, and a pinned horizon still bites
-- same size every time: replace last_login, keep no history in the document
UPDATE users
   SET profile = jsonb_set(profile, '{last_login}', to_jsonb(now()))
 WHERE id = 1;
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Mistake #2: we leave transactions open

cur.execute("SELECT * FROM orders WHERE id = %s FOR UPDATE", (oid,))

resp = requests.post("https://api.payments-provider.com/v1/charges",     # HTTP to a third party
                     json={"card": card, "amount": amount})

cur.execute("UPDATE orders SET status = 'paid' WHERE id = %s", (oid,))
conn.commit()
  • Autocommit is off*; the SELECT opened a transaction
  • It holds the row lock, and it holds a transaction id
  • In READ COMMITTED an xid pins the horizon the way a snapshot does

* in psycopg2/3. JDBC, others differ here

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

What vacuum tells you

INFO:  finished vacuuming "app.public.orders": index scans: 0
tuples: 0 removed, 1483112 remain, 612004 are dead but not yet removable
removable cutoff: 982144, which was 61930 XIDs old when operation ended

"dead but not yet removable" with an old cutoff: someone holds the horizon.

Holder What it pins Where to look
Report running 40 minutes * snapshot (xmin) pg_stat_activity
Nightly batch in one transaction xid and snapshot pg_stat_activity
pg_dump at noon snapshot pg_stat_activity
Physical slot with hot_standby_feedback xmin for every table pg_replication_slots
Logical slot nobody consumes catalog_xmin; WAL is retained pg_replication_slots
Prepared transaction nobody finished xmin, indefinitely pg_prepared_xacts

* A read-only transaction holds one too.

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

What happens when you can't vacuum

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Add a timeout?

cur.execute("SELECT * FROM orders WHERE id = %s FOR UPDATE", (oid,))

resp = requests.post("https://api.payments-provider.com/v1/charges",     # HTTP to a third party
                     json={"card": card, "amount": amount}, timeout=30)  # ? to 30 seconds, sometimes never

cur.execute("UPDATE orders SET status = 'paid' WHERE id = %s", (oid,))
conn.commit()
  • Autocommit is off*; the SELECT opened a transaction
  • <= 30 second idle in transaction. At 300 commits a second, 9,000 can pile up
  • It holds the row lock, and it holds a transaction id
  • In READ COMMITTED an xid pins the horizon the way a snapshot does

* in psycopg2/3. JDBC, others differ here

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

It's always connections

app instance pool of 20 clients app instance pool of 20 clients app instance pool of 20 clients payments API response: 50 ms response: 200 ms response: 800 ms response: 2 s response: 5 s response: 10 s response: 20 s Postgres: 5 server connections, grows to 20 idle in txn idle in txn idle in txn idle in txn idle in txn idle in txn new idle in txn new idle in txn new idle in txn new idle in txn new idle in txn new idle in txn new idle in txn new idle in txn new idle in txn new idle in txn new idle in txn new idle in txn new idle in txn new idle in txn new green: serving requests orange: held by a transaction waiting on HTTP idle in txn idle in txn idle in txn idle in txn transactions open, call the payments API, and commit in 50 ms. A connection is idle in transaction for a moment, then free the payments API slows down. A request opens a transaction, calls it, and holds its server connection while it waits no free connection, so the pool opens a few more. Each request calls the API inside its transaction, and holds one every server connection is held by a transaction waiting on HTTP. The pool is exhausted and the database is idle the payments API recovers. Every connection is still held and every app instance is still stuck pause (a) restart (r)
Don't ignore MVCC
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Detection

-- backends holding a snapshot or an xid, oldest first
SELECT pid, datname, application_name, state,
       age(backend_xmin) AS xmin_age,
       age(backend_xid) AS xid_age,
       now() - xact_start AS xact_time
  FROM pg_stat_activity
WHERE backend_type = 'client backend'
  AND (backend_xmin IS NOT NULL OR backend_xid IS NOT NULL)
ORDER BY greatest(age(backend_xmin), age(backend_xid)) DESC;



  • xmin_age is how many transactions committed since this one started.
  • xact_time 10s * 500 xact/sec = 5,000 commits
  • Slots and prepared transactions: pg_replication_slots, pg_prepared_xacts, both in the demo file
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

The fix

  • FOR UPDATE plus the charge was never one transaction. Postgres cannot roll back an HTTP call
  • Autocommit on. Charge first with an idempotency key, then one guarded UPDATE
# borrow a connection. The pool was built with autocommit on
conn = pool.getconn()

# the charge runs with no transaction open
resp = requests.post("https://api.payments-provider.com/v1/charges",
                     headers={"Idempotency-Key": f"order-{oid}"},
                     data={"amount": amount, "currency": "usd",
                           "customer": cust, "confirm": "true"}, timeout=30)

# one UPDATE. The status guard replaces the row lock
cur.execute("UPDATE orders SET status = 'paid' "
            "WHERE id = %s AND status = 'pending'", (oid,))

# the only transaction. SQL only, milliseconds
with conn.transaction():
    cur.execute("INSERT INTO ledger ...")
    cur.execute("UPDATE balances ...")
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

The gateway goes down, Postgres goes idle

app instance pool of 20 clients app instance pool of 20 clients app instance pool of 20 clients payments API response: 50 ms response: 2 s down threads waiting on HTTP, no transaction open Postgres: 5 server connections, all free idle green: free UPDATE UPDATE UPDATE UPDATE autocommit on. A request charges first, with no transaction open, then runs one UPDATE in a few milliseconds the payments API slows down. Requests wait on HTTP. No transaction is open, so no server connection is held the payments API is down. Every request is waiting on HTTP. Postgres has five free connections and nothing to do the payments API recovers. The waiting requests run their UPDATE and finish. Nothing to clean up pause (a) restart (r)
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

The fix, server side

ALTER ROLE app_rw SET idle_in_transaction_session_timeout = '30s';
ALTER ROLE app_rw SET transaction_timeout = '5min';      -- PG 17+: the whole transaction, idle or not



  • Per role: the app and the reports need different numbers
  • Pick the seconds from your commit rate. 30 seconds at 300 commits a second is 9,000 transactions held back
alerting today oldest idle-in-transaction age > 30 s; transactions open > 60 s yes
xid age in transactions, the measure that matters; replication slots, prepared transactions no
verify rerun the detection query; xmin_age falls back to the hundreds
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Mistake #3: bulk DELETE instead of partitioning

Replication lag and a WAL spike at 02:00

-- the nightly retention job
DELETE FROM events WHERE created_at < now() - interval '90 days';

events: 2,000,000,000 rows, 90 days retention, 6 indexes



daily rows removed ~22,000,000 one day's worth
dead tuples in the heap 22,000,000 DELETE only marks them
WAL at delete time 22,000,000 also replayed on every replica
transaction hours holding an xid and a snapshot the whole time (Mistake #2)
vacuum WAL traffic (heap + all indexes)
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Detection

-- which statement wrote last night's WAL spike?
SELECT queryid, calls, rows, wal_bytes, total_exec_time
  FROM pg_stat_statements
ORDER BY wal_bytes DESC
LIMIT 5;

-- dead rows by table
SELECT relname, n_dead_tup, n_live_tup, last_autovacuum
  FROM pg_stat_user_tables
ORDER BY n_dead_tup DESC
LIMIT 5;
  • wal_bytes over 1 GB for one statement with rows in the millions
  • n_dead_tup above a fifth of n_live_tup and last_autovacuum hours old (dead rows).
  • Until you can partition: bounded batches, commit each one
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

The fix

-- events already exists. Build the partitioned table next to it; the key must include created_at
CREATE TABLE events_p (LIKE events INCLUDING DEFAULTS, PRIMARY KEY (id, created_at))
  PARTITION BY RANGE (created_at);
CREATE TABLE events_p_2026_08 PARTITION OF events_p FOR VALUES FROM ('2026-08-01') TO ('2026-09-01');
-- one partition per month back to the retention edge, indexes on events_p; pg_partman keeps the calendar
INSERT INTO events_p SELECT * FROM events WHERE created_at >= '2026-08-01' AND created_at < '2026-09-01';   -- a month per batch
SET lock_timeout = '2s';                                          -- the swap is two renames
BEGIN; ALTER TABLE events RENAME TO events_old; ALTER TABLE events_p RENAME TO events; COMMIT;
-- from now on retention is a catalog change. PG 14+. not in a transaction block. waits for open transactions (Mistake #2)
ALTER TABLE events DETACH PARTITION events_p_2026_08 CONCURRENTLY;
DROP TABLE events_p_2026_08;
rows removed ~680,000,000, a month
dead tuples 0
WAL catalog rows only
wall clock milliseconds, once open transactions on events finish
alerting today dead tuple ratio > 20% on large tables; replication lag yes, hours later
the statement itself (WAL bytes per statement, rows deleted) no
verify n_tup_del stays flat on the parent; the drop is a catalog change
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

It's always connections

  • The bulk DELETE is one long-running transaction. Its xid pins the horizon for hours
  • Vacuum is held back the whole time. Dead versions pile up in every table, not just this one
  • The index pages the DELETE empties stay allocated. Every INSERT and UPDATE walks a bigger index
  • Slower writes hold their connection longer. Same traffic, longer holds, the pool opens more
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Mistake #4: unused indexes

  • UPDATE latency slowly increasing
  • Connection counts up 1% month-over-month

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Write amplification

Measured on 1M rows. Extrapolated to 1B

1M rows, measured 1B rows at 5,000 UPDATE/s
heap + primary key on disk 179 MB 179 GB
seven int indexes on disk 141 MB 141 GB
page writes per UPDATE, primary key only 2 10,000 per second
page writes per UPDATE, seven indexes 9 45,000 per second
WAL per UPDATE, primary key only 311 B 134 GB per day
WAL per UPDATE, seven indexes 855 B 369 GB per day

  • 1M: UPDATE takes 0.2 ms with 0 indexes or 7. Everything is in RAM
  • 1B: indexes compete with heap for RAM.
  • The UPDATE holds its connection through every one of those reads
  • Every replica and the WAL archive carry the extra 235 GB a day
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Detection

-- indexes with zero scans since the stats reset, largest first
SELECT s.relname, s.indexrelname, s.idx_scan, s.last_idx_scan,       -- last_idx_scan: PG 16+
       pg_relation_size(s.indexrelid) AS bytes
  FROM pg_stat_user_indexes s
  JOIN pg_index i USING (indexrelid)
WHERE s.idx_scan = 0
  AND NOT i.indisunique
  AND NOT i.indisprimary
ORDER BY pg_relation_size(s.indexrelid) DESC;

  • idx_scan = 0 with bytes over 100 MB: a write tax on every INSERT and non-HOT UPDATE
  • Zero counts only since stats_reset in pg_stat_database; a short window is not proof
  • Each replica counts its own scans; check every node before dropping
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

The index that turns off HOT

HOT: Only update the HEAP (Heap Only Tuples) if the new version fits on the same page and no indexed column change


UPDATE pgbench_accounts SET abalance = abalance + 1 WHERE aid = $1;
CREATE INDEX ON pgbench_accounts (abalance);                          -- second run only

no index on abalance one index on abalance
update HOT update every update changes abalance → no HOT
indexes no index touched; old version pruned in place on the next visit an index entry every time
dead tuples stay flat, even with autovacuum off every update leaves a dead tuple behind
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Watch the HOT ratio, then drop the index

SELECT relname, n_tup_upd, n_tup_hot_upd, n_tup_newpage_upd,   -- n_tup_newpage_upd: PG 16+
       n_dead_tup
  FROM pg_stat_user_tables
WHERE n_tup_upd > 0
ORDER BY n_tup_upd DESC;

  • n_tup_hot_upd under half of n_tup_upd: an indexed column is updated, or the page is full
  • Counters are cumulative; diff two samples
  • Save pg_get_indexdef() first, then DROP INDEX CONCURRENTLY

alerting today unused index bytes (daily); invalid indexes (hourly) yes
HOT ratio no
verify hot_pct recovers on the next sample; the index is gone from pg_index
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

It's always connections!

Actually - it's efficiency

Thirty years of the same response, raise max_connections.

  • Just raising your connections glosses over the problem.
  • Make every interaction with the database direct, fast and with consistent latency
  • Your app depends on external services. Don't force your DB to as well.

Mistake What it does to connections The efficiency fix
connection storms one per request, the CPU forks Properly Sized pool
ignoring MVCC every reader steps over the dead versions a key that only grows gets its own table
long-running transactions held for the whole wait only SQL inside the transaction
bulk DELETE one held for hours, every query slower partition and DROP
unused indexes every write holds longer, the pool grows no index without a SELECT

Make each transaction cheaper and the connection count follows

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Questions?

Scott Mead · [email protected]

Slides and the SQL from this talk will be posted: https://www.meetup.com/postgres-nyc/

Slides: Creative Commons Attribution License (CC BY 4.0). SQL and scripts: PostgreSQL License.

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

What vacuum tells you

INFO:  finished vacuuming "app.public.orders": index scans: 0
tuples: 0 removed, 1483112 remain, 612004 are dead but not yet removable
removable cutoff: 982144, which was 61930 XIDs old when operation ended

"dead but not yet removable" with an old cutoff: someone holds the horizon.

Holder What it pins Where to look
Report running 40 minutes * snapshot (xmin) pg_stat_activity
Nightly batch in one transaction xid and snapshot pg_stat_activity
pg_dump at noon snapshot pg_stat_activity
Physical slot with hot_standby_feedback xmin for every table pg_replication_slots
Logical slot nobody consumes catalog_xmin; WAL is retained pg_replication_slots
Prepared transaction nobody finished xmin, indefinitely pg_prepared_xacts

* A read-only transaction holds one too.

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Appendix: all eleven indexes behind the page diagram, May vs October 2026.

Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License

Appendix: know your defaults

You see nothing, until one query holds a connection for hours.

  • statement_timeout
  • lock_timeout
  • idle_in_transaction_session_timeout
  • transaction_timeout (PG 17)
  • idle_session_timeout (PG 14)

All five default to 0: a connection can be held forever.

ALTER ROLE reporting  SET statement_timeout = '15min';
SELECT rolname                                             -- login roles with no statement_timeout override
  FROM pg_roles r
WHERE rolcanlogin
  AND NOT EXISTS (SELECT 1 FROM pg_db_role_setting s
                  WHERE s.setrole = r.oid AND s.setconfig::text LIKE '%statement_timeout%');
alerting today login roles with unlimited timeouts no
verify the query above returns no application roles
Scott Mead · [email protected] · NYC Postgres Meetup · 2026 · Creative Commons Attribution License