The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Adds blog post
Copple7da62740658c
diff --git a/apps/www/_blog/2023-04-27-postgres-pluggable-strorage.mdx b/apps/www/_blog/2023-04-27-postgres-pluggable-strorage.mdxnew file mode 100644index 00000000000..8a12175bda0--- /dev/null+++ b/apps/www/_blog/2023-04-27-postgres-pluggable-strorage.mdx@@ -0,0 +1,61 @@+---+title: 'Postgres pluggable storage'+description: Exploring history of Postgres pluggable storage and the possibility of landing it in the Postgres core.+author: paul_copplestone+image: lw7-hackathon-winners/lw7-hackathon-winner.jpg+thumb: lw7-hackathon-winners/lw7-hackathon-winner.jpg+tags:+ - database+date: '2023-04-27'+toc_depth: 2+---++You might have recently read “[The Part of PostgreSQL We Hate the Most](https://ottertune.com/blog/the-part-of-postgresql-we-hate-the-most/)” which highlights some of the deficiencies with Postgres storage. Luckily, there is some work in Postgres ecosystem to solve this using “pluggable storage”.++This article explores the history of Postgres pluggable storage and the possibility of landing it in the Postgres core.++## What is pluggable storage?++Pluggable storage gives developers the ability to use different storage engines for different tables within the same database.++Developers will be able to choose a storage method that is optimized for their specific needs. Some tables could be optimized for high transactional loads, others for analytics workloads, while yet another for archiving.++Something like this is already [available in MySQL](https://en.wikipedia.org/wiki/Comparison_of_MySQL_database_engines), which uses the [InnoDB](https://en.wikipedia.org/wiki/InnoDB) as the default storage engine since MySQL 5.5. This replaced [MyISAM](https://en.wikipedia.org/wiki/MyISAM) which had it’s own [set of problems](https://www.percona.com/blog/using-myisam-in-production/).++The “pluggable” part refers to the ability for developers to develop their own storage methods, similar to Postgres Extensions. While some databases offer multiple built-in storage methods by default, Postgres follows a core philosophy of flexibility and extensibility, and using a pluggable approach makes a lot of sense.++## Current progress for pluggable storage++PostgreSQL received basic support for pluggable storage in version 12 with the goal of [adding ZHeap](https://anarazel.de/talks/2019-05-30-pgcon-pluggable-table-storage/pluggable.pdf). Andres Freund and several contributors provided some excellent refactoring, improving various APIs for table access methods (TAM).++ZHeap offered a lot of promise, providing an undo log and solving some long-term table bloat issues in Postgres. The code [was released](https://github.com/EnterpriseDB/zheap) with [promising results](https://www.pgcon.org/2018/schedule/attachments/501_zheap-a-new-storage-format-postgresql-5.pdf).++This implementation requires more work for a true pluggable storage solution. In particular:++- The TAM API doesn’t provide much flexibility for working with indexes. For example, when you update a row, an index update is an all-or-nothing procedure. This was infamously highlighted by Uber in their “[switching from Postgres to MySQL](https://www.uber.com/blog/postgres-to-mysql-migration/)” in 2016.+- Row versions need to be identified the pairing of a block number and offset number. This means you can’t implement useful functions, like an index-organized table or undo-based versioning.++While It was a great start, it appears that the [work on ZHeap has stalled](https://twitter.com/andy_pavlo/status/1590703943176589312).++Even without a full API for pluggable storage, there are a couple of solutions available on the market today:++- **Citus’s** [Columnar Storage](https://docs.citusdata.com/en/v11.1/admin_guide/table_management.html#columnar-storage), which powers Microsoft’s [Hyperscale](https://azure.microsoft.com/en-us/updates/azure-database-for-postgresql-hyperscale-citus-is-now-available/) offering. Citus has a few [limitations](https://docs.citusdata.com/en/v11.1/admin_guide/table_management.html#limitations) due to the limitations of the current API.+- EDB’s [Advanced Storage Pack](https://www.infoworld.com/article/3681112/3-key-features-in-edb-postgresql-15.html), which is appears to provide some enhancements to heap storage, although the source is not available for us to confirm.++## The future of pluggable storage++Right now, pluggable storage requires a a fork of Postgres. But there are several initiatives in the Postgres community that we’re excited about.++- There have been community updates for [custom resource managers](https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=5c279a6d350205cc98f91fb8e1d3e4442a6b25d1) that expand WAL support for TAM.+- The creators at [OrioleDB](https://github.com/orioledb/orioledb) started with a fork of Postgres and have been quietly upstreaming the code that is required to make pluggable storage a reality. They are solving many “[wicked Postgres problems](https://www.slideshare.net/AlexanderKorotkov/solving-postgresql-wicked-problems)” with [dual pointers](https://www.orioledata.com/blog/buffer-management/) instead of buffer mapping, row-level WAL instead of block-level WAL, undo logs instead of bloat-prone MVCC, and index-organized tables instead of heap. In Postgres 14 their patchset was about 5,000 lines of code (this represents the total number of changes required in their fork). In the upcoming Postgres 16 release, it is around 2,000 lines of code. That means that around 60% of the code is already committed to the Postgres core. (Disclosure: Supabase started [sponsoring OrioleDB](https://supabase.com/blog/supabase-series-b#where-were-going) in 2022).++<aside>+ℹ️ Alexander Korotkov, the maintainer of OrioleDB, will be talking at PGCON 23 about some of the [changes](https://www.pgcon.org/events/pgcon_2023/schedule/session/470-future-of-table-access-methods/) they are making.++</aside>++## Timelines for pluggable storage++Ambitiously, many of the changes required for pluggable storage could land in Postgres 17. If that happens, new storage engines like OrioleDB would be available as a simple extension for developers to use in any Postgres instance. This paves the way for other Pluggable Storage Engines, just like MySQL’s [support for multiple storage engines](https://dev.mysql.com/doc/refman/5.7/en/storage-engines.html).++As a community project, Postgres mostly requires support for these initiatives. The best way to support these initiatives is to get involved with Postgres [Commitfests](https://supabase.com/blog/postgresql-commitfest). Postgres is already one of the best database engines in the world, and pluggable storage would make it even more attractive and maintanable.