Subscribe free
Morning Merge Ruby · Friday, November 20, 20262 min read

PostgreSQL 19 adds get-or-create SQL

Also: local S3 tests with AWS Emulator, and an nginx origin check.

PostgreSQL 19 can return the row that blocked an insert. If your Rails app already handles duplicate inserts, start there when you test the upgrade.

The main thing

A jeweler’s press lowers a ruby into a metal strip.

PostgreSQL 19 can return an existing row on insert

The November 19 release adds INSERT ... ON CONFLICT DO SELECT. With RETURNING, the database can return the row it inserted or the existing row that caused the conflict. If your code fetches the existing row in a second query, that's a round trip you can skip.

If all you need from a conflict is an ID, an update just to get a row back is a strange bargain: you asked a question and paid for a write. The new clause lets you ask the question directly.

Start with one Rails write path that already relies on a unique constraint. On a branch, send two requests that try to create the same key and check that both callers get the same row back. Treat this as a SQL option, not an Active Record upgrade.

Keep the experiment narrow. If you're replacing a path that relies on model callbacks or validations, account for those before switching to direct SQL. If there isn't a second query worth removing, leave the code alone.

There's a separate win for Rails apps that route reads to replicas. A standby can now WAIT FOR LSN until it has replayed the primary's write-ahead log through a specified position.

Consider the wait for a read that must see a just-completed write. Don't make it the default for every replica query: waiting moves replication lag onto the request.

Try this

A ruby reservoir connects to a bench-top water pump.

Try AWS Emulator on one Active Storage test. If you use S3 in Rails, try an upload-and-read test against the local emulator without real AWS credentials. InfoQ reports that S3, SQS and DynamoDB scored roughly 60 to 70 percent in Kento Ikeda's early service-level fidelity tests.

That's enough to try it for a fast feedback loop, not enough to retire your AWS sandbox. The emulator doesn't evaluate IAM policies the way AWS does. Keep permissions and any production-critical S3 behavior in the suite you run against real AWS.

Patch check

An inspection lens holds a ruby above a ventilation duct seam.

Check whether clients can reach nginx without Cloudflare. The November 18 nginx patches still apply. Cloudflare explains what its proxy covers: when traffic has to go through it, client HTTP/2 and HTTP/3 connections end at its edge. The affected code on your Rails origin doesn't receive that traffic directly.

Check whether your origin can also be reached directly. Cloudflare traces the broadest HTTP/2 flaw back to nginx 1.9.5 and says to upgrade to 1.30.7, 1.31.9 or a fixed distributor build, then restart. It doesn't claim its HTTP proxy covers the resolver or mail proxy flaws.

If your proxy comes from Docker Hardened Images, Docker reports that it rebuilt its nginx images on the fixed releases. Pull the rebuilt image or update the pinned tag, then redeploy.

Try the Postgres change where a duplicate insert buys you a second query, not in every model.

← All Morning Merge Ruby issues

Get this in your inbox every morning.

Free. Five minutes. Unsubscribe in one click.

Subscribe free →