This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Multi-tenancywith PostgreSQL
Requirements
Three waysbit.ly/msn-multitenant-arch
Shared Database, Shared Namespace
Separate Databases
Shared Database,Separate Namespace
hasschemas
hasnamespaces
Guy Naor on Multi-tenancyhttp://bit.ly/guy-naor-multitenant-2009
App
carding.app.com/products/1-grapes
SET SEARCH_PATH = 'carding'
'carding'
SELECT * FROM products where id = 1;
Common Tables
"public"
'carding'
SELECT * FROM public.invoices where tenant_id = 1;
Apartmentgithub.com/bradrobertson/apartment
bob.sql
carding
alice.sql
carding
carding assimo
assimo
Storeygithub.com/ramontayag/storey
Gotchas
Problem: Testing
● transactions do not play well with schemas
Answer: Testing
● in tests, treat the public schema as a tenant
Problem: Migrations
● migrate every schema
Answer: Apartment/Storey
● loops through the namespaces and migrates each one
Problem: Background Jobs
● how do the workers know which schema contains the data?
Answer: Pass schema name
● Pass the schema name along with the rest of the job arguments