Extending your database server's abilities in a safe and powerful way
Presented by:
Hannu Krosing
Hannu has been working with PostgreSQL since it was called Postgres95 (and also played around with Postgres 4.2 - without the "SQL" - a little before that)
Hannu was the first DBA at Skype, where he wrote patches for making VACUUM able to work on more than one table in parallel and invented the sharding and remote call language pl/proxy to enable using PostgreSQL in infinitely scalable way and also participated in design of other 24/7 enterprise features.
After Skype he did 10+ years of PostgreSQL consulting all over the world as part of 2ndQuadrant.
Currently works as a Database Engineer at Google
No video of the event yet, sorry!
PostgreSQL is build from ground up on extensibility.
Some of it can be done by writing database functions in pl/pgsql or plain SQL but sometimes you need to do more complex thing in highly performant way. For many of these needs implementations of complex algorithms are already available as open source, so all that is needed is packaging them as PostgreSQL extensions and this has been going on for tens of years already, mostly using C and lately also other compiled languages like Rust, Go and Zig.
But not all developers are comfortable with writing a PostgreSQL extension in C which can easily corrupt data or cause security problems when not used in most meticulous ways. Also when using managed servers from either cloud providers or just your IT department the developer may nothave full access to their database servers or are they allowed to install random low-level code which could bring down whole servers.
The solution here is using "trusted" languages, like pl/pgsql or pl/v8.
While pl/pgsql is relatively well known and almost always fast enough when orchestrating SQL queries and DML statements it is not a good choice when implementing complex algorithms by itself.
This is the area where pl/v8 shines - not only does it include safely sandboxed V8 Javascript engine with JIT compilation, it also allows safely running WebAssembly which is designed to be "portable machine code" and very close to native compiled code in speed.
In this talk I will show when to use which approach and how to find and package Javascript packages designed for Browser or Node.js to run inside PostgreSQL server. And how to compile your C or Rust code to WASM do the same.
I will also walk through some practical examples of using Javascript and WASM.
And also present surprising cases where Javascript is faster than even compiled code (not WASM, real compiled x64 code) and explain why this is the case.
And of course I also address the commonly held (mis)belief that "Business Logic should not be in database". Database Schema is the business logic :)
- Date:
- Duration:
- 45 min
- Room:
- Conference:
- PGConf India, 2025
- Language:
- Track:
- Application Developer
- Difficulty:
- Medium