Ctrl-C in psql gives me the heebie-jeebies
Postgres cancels queries via a separate CancelRequest connection identified only by a process ID and secret key, and psql still sends it in plaintext even when the main connection uses strict TLS, because libpq's encrypted cancel functions (added in Postgres 17) aren't signal-safe for psql yet. That exposes a denial-of-service risk: anyone observing traffic can replay the request to cancel every future query on the connection, even with protocol 3.2's longer keys. The missing TLS also means no SNI, which broke cancellation in the Elephantshark proxy until v0.3 added a map from (process ID, secret key) to destination host. Recommended mitigations: Postgres 18 with min_protocol_version=3.2, a VPN, avoiding Ctrl-C in psql, and checking whether other drivers encrypt cancels.
Related posts
- Shipping psql without psql: a pure-TypeScript Postgres client in neonctl
Neon mediumAdept
neonctl now embeds a pure-TypeScript reimplementation of psql that activates when no native psql is on the PATH. It covers the REPL, all backslash commands, output formats, connection options, SCRAM and TLS, with no native dependencies, and it was written almost entirely by Claude Code under human review. Correctness rests on a conformance harness that fetches PostgreSQL's own regression scripts and diffs output byte-for-byte against a containerized server across PG 14–18, plus an adversarial security review that caught plausible-looking bugs such as a silent sslmode downgrade and a skippable SCRAM mutual-auth check. Lessons include regression-suite hidden setup (prerequisite tables, injected settings), fixing the first diff mismatch rather than the last, and runtime-dependent TLS behavior (BoringSSL under Bun vs OpenSSL under Node).
- What's New in pg_clickhouse v0.3.2: Postgres 19, TLS, Regex, and Memory
ClickHouse mediumAdept
pg_clickhouse v0.3.2, the Postgres extension for querying ClickHouse, adds support for PostgreSQL 19 Beta1 and needs no restart or ALTER EXTENSION UPDATE. New CREATE SERVER options cover TLS behavior (`secure` on/off/auto, `min_tls_version`) and native protocol compression. Regex flag pushdown has been corrected, with a mapping table and a warning that Postgres and ClickHouse treat negated character classes differently around newlines. The release also fixes memory ballooning in repeatedly re-scanned parameterized foreign scans and in unbuffered HTTP queries, pushes down capture-free regexp_match(), and fixes empty-array ANY() errors on older ClickHouse.
- MITM attacks are easier to avoid with psql (Postgres) 16
Neon mediumAdept
Postgres 16's psql adds `sslrootcert=system`, which uses the OS's trusted CA store and implies `sslmode=verify-full`. Together with the new `require_auth` option, it closes a MITM hole that `sslmode=require` leaves open. `require` encrypts the connection but never checks the server certificate. An attacker who spoofs DNS can then request a cleartext password, and libpq will hand it over even if the real server uses SCRAM-SHA-256. A proof-of-concept Ruby proxy under 100 lines, combined with bettercap DNS spoofing, captured credentials and proxied the session in a few hours. The recommendation is to connect with `sslrootcert=system` (or `verify-full` plus a CA bundle on older psql) and set `PGSSLROOTCERT`, `PGSSLMODE` and `PGREQUIREAUTH=scram-sha-256` as environment defaults.
- Quicker serverless Postgres connections
Neon mediumAdept
Neon cut the network round-trips needed to get a first query result from its WebSocket-based serverless Postgres driver from nine to four. It moved to TLS 1.3, ran Postgres unencrypted inside a secure wss: WebSocket (or pipelined SSLRequest with the TLS Client Hello), and replaced CPU-heavy SCRAM-SHA-256 with plain password auth over TLS, since Neon only issues long random passwords. It also pipelined the startup, password and query messages into a single send. Pipelining at first added up to 50ms of delay over short distances because of Nagle's algorithm, fixed by setting TCP_NODELAY in the proxy. QUIC-based WebSockets or WebTransport might cut the count further.
- Incident Report: April 23rd, 2025
Railway mediumAdeptA Google Cloud SQL maintenance window took Railway's networking control plane Postgres read replica offline for about 10 minutes, destabilizing edge, private networking and TCP proxy traffic across all regions, worst in Asia. Control plane instances crashed on database connection errors because of improper error handling, and each restart evicted the in-memory routing cache, which could not be refetched while Postgres was down. Slow cache warming delayed recovery until 09:28 UTC. Planned fixes include regional control planes to limit blast radius, graceful handling of DB errors, a persistent routing cache as a fallback, faster startup, and Cloud SQL maintenance settings that keep primary and replica from being maintained at the same time.