PostgreSQL Extensions in Go

160 points · 29 comments on HN · read original →

Points and comments are a snapshot, not live.

gopgext builds PostgreSQL extensions from plain Go code using TinyGo.

gopgext is an experimental tool that compiles Go functions into PostgreSQL extensions via TinyGo. Functions marked with `//gopgext:function` become SQL functions. It supports standard library packages, maps Go types to SQL types, and handles queries through SPI with SQLSTATE error codes. It can write triggers, aggregates, operator classes, index methods, foreign data wrappers, and query hooks. Ports of contrib modules like pgcrypto and hstore pass upstream regression tests. Multiple Go extensions can load in one backend. The project is a sibling of gokm, which builds Linux kernel modules from Go.

What commenters are saying

Commenters praised the mascot and noted similar projects like plgo. A top commenter detailed runtime friction with Postgres's process model: signal handling conflicts, memory context vs. Go GC, and process-per-connection overhead. They noted pgrx (Rust) has gained traction due to zero runtime and direct palloc integration. Another commenter argued LLMs make such shoehorning unnecessary, suggesting AI-generated PL/pgSQL instead. Others defended plv8 and pljs as useful alternatives. A commenter observed that TinyGo avoids Go runtime threads, making it practical inside a Postgres backend.