500X Memory Reduction In Rails With Postgres Schemas And Apartment
summary
A Rails app using Postgres multi‑schema with Apartment cuts memory by 500x memory reduction after changing how Postgres types are loaded: ActiveRecord no longer loads duplicate composite types per schema, reducing pg_type rows from ~420,000 to ~163 in a 10,000‑schema test, and avoiding repeated expensive OID lookups by adding a cache pg_type results layer and a small patch to filter pg_type entries; production with ~200k schemas becomes stable and migrations remain painful but possible.
AI-written summary · about
chapters (12)
- 0:00Introduction and speaker intro
- 1:38About the company and speaker
- 3:28Memory problem overview
- 5:37Multi-tenancy and schema structure
- 8:10Debugging production memory issues
- 9:11Database size impact on memory
- 11:21Root cause of memory consumption
- 13:51Solution and code modifications
- 16:22Caching mechanism implementation
- 17:08Why others don't face this issue
- 19:39Refactoring multi-schema structure
- 21:06Q&A session begins
related talks
30mPuny to Powerful PostgreSQL Rails Apps
01h 01mNew Approach to Resolve objectrelational impedance mismatch
26mBiggish Data With Rails and Postgresql
46mUse PostgreSQL, not Rails, to make Rails Faster!
48mAdvanced Postgres Schema Design (For Scalable Application Development) bySehrope Sarkuni
25mSaaS on Rails on PostgreSQL
23mSupercharging ActiveRecord with PostreSQL
48mPractical Memory Tuning for PostgreSQL
