SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Downloaden Sie, um offline zu lesen
A practical (pragmatic) multi-tenant cluster

             (Mental meandering)

                      by

                 Rod Anderson
               raanders@acm.org
Credits

  •   Thomas Jacobs
      http://wiki.postgresql.org/wiki/Shared_Database_Hosting
      http://www.internet24.de/

  •   Thomas Jacobs
      Scott Marlowe
      Robert Treat
      http://archives.postgresql.org/pgsql-admin/2008-08/msg00049.php

  •   Tom Lane
      For the gentle suggestion to just try it when I asked about using '@' in role names.
What is a multi-tenant cluster?

  •   A single PostgreSQL database cluster.

  •   One (or more) databases per customer.

  •   One chunk of hardware.

  •   Allowing many tenants to run the same applications in their own database.
Why a multi-tenant cluster?

  •   Single superuser (postgres?) for all databases, customers, clients.

  •   Sharing of memory and processor(s).

  •   Low impact applications or low usage needs, i.e. smaller businesses.

  •   Hardware goes further.

  •   Even a server inside a company/organization could benefit by having a database per department.
Issues with a multi-tenant cluster

  •   Missing - per database users/roles

      Actually there is a method in 8.4 but it doesn't play well with md5 requires the use of password. So if there is a
      possibility or concern of password "sniffing" this can't be used unless you use a SSL encrypted connection.

      See the following two links for the gory details.
      http://www.postgresql.org/docs/current/static/runtime-config-connection.html#GUC-DB-USER-NAMESPACE
      http://www.postgresql.org/docs/current/static/auth-methods.html


  •   No method to add database roles when there is only a cluster superuser? That is allow create role but restrict those
      roles to a specific database.

  •   If createuser is granted to a database administrator, what controls and options are there on role naming.

  •   When deleting/removing users/roles how to clean up database spanning ACLs.
•   Database resources controls.

        •   Bad queries eating the database engine alive.

        •   Disk and storage quotas

                •   In PostgreSQL?

                •   File system

                •   OS?

        •   CPU and memory quotas

                •   PostgreSQL

                •   OS
What can be done and what can we do to make it easier.

  •   Identify applications that can be modified to support or do support installation into a schema instead of a
      database.

  •   Get around the global user/roles

  •   Give each database it's own tablespace for data.
Other multi-tenant options

Though not what I'd consider true multi-tenant solutions there are

    •   Multiple PostgreSQL instances

    •   Linux-Vservers

    •   XEN

    •   BSD jails(?)

    •   Others?
Steps to create a multi-tenant cluster.

  1. Come up with a database and role naming system.

  2. Develop scripts to build the database and roles.

  3. Method to control access to the cluster as painless as possible.

  4. Modify application scripts to use a schema in a database instead of a database.
Here is what I came up with.

Databases and their controlling(?) role have short, almost mnemonic, names: acme, tsmg, snoi, etc.

       Tenant user/role names are in the form dba@acme, rt_user@acme, or ledgersmb@acme.

pg_hba.conf has these four entries:

     local      all                   postgres                                  md5
     local      samerole              all                                       md5
     host       all                   postgres             0/0                  md5
     host       samerole              all                  0/0                  md5
To install LedgerSMB I did a manual install and skipped/modified those steps that conflicted with the schema-based
install.

That is: I created the database, role, and schema then ran the LedgerSMB INSTALL steps manually.

To create the database I use a shell script that makes the TABLESPACE directory and builds the SQL script. Here are some
excerpts from the file.

TSDIR="/var/lib/pgsql/data/ts"
TENANT="$1"
pushd "$TSDIR"

[[ ! -d "$TENANT" ]] && mkdir "$TENANT"

chown postgres:postgres "$TENANT"

chmod 700 "$TENANT"

popd
The script creates and calls this SQL script. (Assuming a tenant called/named acme.)


CREATE ROLE acme NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOLOGIN;

CREATE ROLE "dba@acme" NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN ENCRYPTED PASSWORD
'07cc54da9f666';

GRANT acme TO "dba@acme";

CREATE TABLESPACE acme_ts OWNER "dba@acme" LOCATION '/var/lib/pgsql/data/ts/acme';

CREATE DATABASE acme WITH OWNER="dba@acme";

COMMENT ON DATABASE acme IS 'Database create 20090319';

c acme

GRANT ALL ON SCHEMA public TO "dba@acme" WITH GRANT OPTION;
To create a schema specifically for the application I use a script specific to that application. For LedgerSMB it generates
the following SQL script.

CREATE ROLE "ledgersmb@acme" NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN ENCRYPTED
PASSWORD 'c3c20524a6621';

GRANT USAGE ON SCHEMA public TO "ledgersmb@acme";

GRANT CONNECT, TEMPORARY ON DATABASE acme TO "ledgersmb@acme";

GRANT acme TO "ledgersmb@acme";

c acme

CREATE SCHEMA ledgersmb AUTHORIZATION "ledgersmb@acme";

COMMENT ON SCHEMA ledgersmb IS 'Schema create 20090319';

ALTER ROLE "ledgersmb@acme" SET search_path = ledgersmb, public

Weitere ähnliche Inhalte

Was ist angesagt?

[drupalday2017] - REST in pieces
[drupalday2017] - REST in pieces[drupalday2017] - REST in pieces
[drupalday2017] - REST in piecesDrupalDay
 
Node.js Lightning Talk
Node.js Lightning TalkNode.js Lightning Talk
Node.js Lightning TalkCodeSlice
 
루비가 얼랭에 빠진 날
루비가 얼랭에 빠진 날루비가 얼랭에 빠진 날
루비가 얼랭에 빠진 날Sukjoon Kim
 
Lisp in a Startup: the Good, the Bad, and the Ugly
Lisp in a Startup: the Good, the Bad, and the UglyLisp in a Startup: the Good, the Bad, and the Ugly
Lisp in a Startup: the Good, the Bad, and the UglyVsevolod Dyomkin
 
Mongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricksMongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricksVladimir Malyk
 
Future-proof Development for Classic SharePoint
Future-proof Development for Classic SharePointFuture-proof Development for Classic SharePoint
Future-proof Development for Classic SharePointBob German
 
Getting Started with the Alma API
Getting Started with the Alma APIGetting Started with the Alma API
Getting Started with the Alma APIKyle Banerjee
 
Easy Blogging With Emacs
Easy Blogging With EmacsEasy Blogging With Emacs
Easy Blogging With EmacsDashamir Hoxha
 
Developing CouchApps
Developing CouchAppsDeveloping CouchApps
Developing CouchAppswesthoff
 
PostgreSQL, your NoSQL database
PostgreSQL, your NoSQL databasePostgreSQL, your NoSQL database
PostgreSQL, your NoSQL databaseReuven Lerner
 
Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneSylvain Zimmer
 
Django and Mongoengine
Django and MongoengineDjango and Mongoengine
Django and Mongoengineaustinpublic
 

Was ist angesagt? (15)

CouchApp - Build scalable web applications and relax
CouchApp - Build scalable web applications and relaxCouchApp - Build scalable web applications and relax
CouchApp - Build scalable web applications and relax
 
[drupalday2017] - REST in pieces
[drupalday2017] - REST in pieces[drupalday2017] - REST in pieces
[drupalday2017] - REST in pieces
 
Node.js Lightning Talk
Node.js Lightning TalkNode.js Lightning Talk
Node.js Lightning Talk
 
루비가 얼랭에 빠진 날
루비가 얼랭에 빠진 날루비가 얼랭에 빠진 날
루비가 얼랭에 빠진 날
 
node.js - Fast event based web application development
node.js - Fast event based web application developmentnode.js - Fast event based web application development
node.js - Fast event based web application development
 
Lisp in a Startup: the Good, the Bad, and the Ugly
Lisp in a Startup: the Good, the Bad, and the UglyLisp in a Startup: the Good, the Bad, and the Ugly
Lisp in a Startup: the Good, the Bad, and the Ugly
 
Mongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricksMongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricks
 
Future-proof Development for Classic SharePoint
Future-proof Development for Classic SharePointFuture-proof Development for Classic SharePoint
Future-proof Development for Classic SharePoint
 
Getting Started with the Alma API
Getting Started with the Alma APIGetting Started with the Alma API
Getting Started with the Alma API
 
Easy Blogging With Emacs
Easy Blogging With EmacsEasy Blogging With Emacs
Easy Blogging With Emacs
 
Developing CouchApps
Developing CouchAppsDeveloping CouchApps
Developing CouchApps
 
PostgreSQL, your NoSQL database
PostgreSQL, your NoSQL databasePostgreSQL, your NoSQL database
PostgreSQL, your NoSQL database
 
Scrapy.for.dummies
Scrapy.for.dummiesScrapy.for.dummies
Scrapy.for.dummies
 
Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing one
 
Django and Mongoengine
Django and MongoengineDjango and Mongoengine
Django and Mongoengine
 

Andere mochten auch

Multi-tenancy with Rails
Multi-tenancy with RailsMulti-tenancy with Rails
Multi-tenancy with RailsPaul Gallagher
 
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...Command Prompt., Inc
 
Not Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index ConstraintsNot Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index ConstraintsCommand Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 
2014.10.15 Сергей Бурладян, Avito.ru
2014.10.15 Сергей Бурладян, Avito.ru2014.10.15 Сергей Бурладян, Avito.ru
2014.10.15 Сергей Бурладян, Avito.ruNikolay Samokhvalov
 
Londiste Replication system for PostgreSQL
Londiste Replication system for PostgreSQLLondiste Replication system for PostgreSQL
Londiste Replication system for PostgreSQLelliando dias
 
Scaling PostgreSQL with Skytools
Scaling PostgreSQL with SkytoolsScaling PostgreSQL with Skytools
Scaling PostgreSQL with SkytoolsGavin Roy
 
Monitoreo tunning postgresql_2011
Monitoreo tunning postgresql_2011Monitoreo tunning postgresql_2011
Monitoreo tunning postgresql_2011Lennin Caro
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL AdministrationCommand Prompt., Inc
 
PostgreSQL: Un motor Impulsado por una comunidad
PostgreSQL: Un motor Impulsado por una comunidadPostgreSQL: Un motor Impulsado por una comunidad
PostgreSQL: Un motor Impulsado por una comunidadSantiago Zarate
 
PostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL IIPostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL IICommand Prompt., Inc
 
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...Command Prompt., Inc
 
configuring a warm standby, the easy way
configuring a warm standby, the easy wayconfiguring a warm standby, the easy way
configuring a warm standby, the easy wayCommand Prompt., Inc
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorReplication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorCommand Prompt., Inc
 

Andere mochten auch (20)

Multi-tenancy with Rails
Multi-tenancy with RailsMulti-tenancy with Rails
Multi-tenancy with Rails
 
Bucardo
BucardoBucardo
Bucardo
 
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
 
Basic Query Tuning Primer
Basic Query Tuning PrimerBasic Query Tuning Primer
Basic Query Tuning Primer
 
Not Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index ConstraintsNot Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index Constraints
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
The PostgreSQL Query Planner
The PostgreSQL Query PlannerThe PostgreSQL Query Planner
The PostgreSQL Query Planner
 
2014.10.15 Сергей Бурладян, Avito.ru
2014.10.15 Сергей Бурладян, Avito.ru2014.10.15 Сергей Бурладян, Avito.ru
2014.10.15 Сергей Бурладян, Avito.ru
 
Londiste Replication system for PostgreSQL
Londiste Replication system for PostgreSQLLondiste Replication system for PostgreSQL
Londiste Replication system for PostgreSQL
 
Scaling PostgreSQL with Skytools
Scaling PostgreSQL with SkytoolsScaling PostgreSQL with Skytools
Scaling PostgreSQL with Skytools
 
Monitoreo tunning postgresql_2011
Monitoreo tunning postgresql_2011Monitoreo tunning postgresql_2011
Monitoreo tunning postgresql_2011
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
 
PostgreSQL: Un motor Impulsado por una comunidad
PostgreSQL: Un motor Impulsado por una comunidadPostgreSQL: Un motor Impulsado por una comunidad
PostgreSQL: Un motor Impulsado por una comunidad
 
PostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL IIPostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL II
 
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
 
Go replicator
Go replicatorGo replicator
Go replicator
 
Pg migrator
Pg migratorPg migrator
Pg migrator
 
Backup and-recovery2
Backup and-recovery2Backup and-recovery2
Backup and-recovery2
 
configuring a warm standby, the easy way
configuring a warm standby, the easy wayconfiguring a warm standby, the easy way
configuring a warm standby, the easy way
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorReplication using PostgreSQL Replicator
Replication using PostgreSQL Replicator
 

Ähnlich wie A Practical Multi-Tenant Cluster

Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Michael Renner
 
Architecture by Accident
Architecture by AccidentArchitecture by Accident
Architecture by AccidentGleicon Moraes
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowKarsten Dambekalns
 
NonStop SQL/MX DBS Explained
NonStop SQL/MX DBS ExplainedNonStop SQL/MX DBS Explained
NonStop SQL/MX DBS ExplainedFrans Jongma
 
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...javier ramirez
 
Why databases cry at night
Why databases cry at nightWhy databases cry at night
Why databases cry at nightMichael Yarichuk
 
The Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterThe Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterChris Henry
 
Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)Lucas Jellema
 
Modeling Tricks My Relational Database Never Taught Me
Modeling Tricks My Relational Database Never Taught MeModeling Tricks My Relational Database Never Taught Me
Modeling Tricks My Relational Database Never Taught MeDavid Boike
 
Implementing the Databese Server session 02
Implementing the Databese Server session 02Implementing the Databese Server session 02
Implementing the Databese Server session 02Guillermo Julca
 
Redis and Bloom Filters - Atlanta Java Users Group 9/2014
Redis and Bloom Filters - Atlanta Java Users Group 9/2014Redis and Bloom Filters - Atlanta Java Users Group 9/2014
Redis and Bloom Filters - Atlanta Java Users Group 9/2014Christopher Curtin
 
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...javier ramirez
 
Grabbing the PostgreSQL Elephant by the Trunk
Grabbing the PostgreSQL Elephant by the TrunkGrabbing the PostgreSQL Elephant by the Trunk
Grabbing the PostgreSQL Elephant by the TrunkHarold Giménez
 
Investigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock HolmesInvestigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock HolmesRichard Douglas
 
Introduciton to Apache Cassandra for Java Developers (JavaOne)
Introduciton to Apache Cassandra for Java Developers (JavaOne)Introduciton to Apache Cassandra for Java Developers (JavaOne)
Introduciton to Apache Cassandra for Java Developers (JavaOne)zznate
 
Monitoring MongoDB’s Engines in the Wild
Monitoring MongoDB’s Engines in the WildMonitoring MongoDB’s Engines in the Wild
Monitoring MongoDB’s Engines in the WildTim Vaillancourt
 

Ähnlich wie A Practical Multi-Tenant Cluster (20)

Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014
 
Architecture by Accident
Architecture by AccidentArchitecture by Accident
Architecture by Accident
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 Flow
 
MongoDB
MongoDBMongoDB
MongoDB
 
NonStop SQL/MX DBS Explained
NonStop SQL/MX DBS ExplainedNonStop SQL/MX DBS Explained
NonStop SQL/MX DBS Explained
 
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...
 
Why databases cry at night
Why databases cry at nightWhy databases cry at night
Why databases cry at night
 
The Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterThe Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb Cluster
 
Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)
 
Modeling Tricks My Relational Database Never Taught Me
Modeling Tricks My Relational Database Never Taught MeModeling Tricks My Relational Database Never Taught Me
Modeling Tricks My Relational Database Never Taught Me
 
Implementing the Databese Server session 02
Implementing the Databese Server session 02Implementing the Databese Server session 02
Implementing the Databese Server session 02
 
Redis and Bloom Filters - Atlanta Java Users Group 9/2014
Redis and Bloom Filters - Atlanta Java Users Group 9/2014Redis and Bloom Filters - Atlanta Java Users Group 9/2014
Redis and Bloom Filters - Atlanta Java Users Group 9/2014
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
Revision
RevisionRevision
Revision
 
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
 
Grabbing the PostgreSQL Elephant by the Trunk
Grabbing the PostgreSQL Elephant by the TrunkGrabbing the PostgreSQL Elephant by the Trunk
Grabbing the PostgreSQL Elephant by the Trunk
 
AWS glue technical enablement training
AWS glue technical enablement trainingAWS glue technical enablement training
AWS glue technical enablement training
 
Investigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock HolmesInvestigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock Holmes
 
Introduciton to Apache Cassandra for Java Developers (JavaOne)
Introduciton to Apache Cassandra for Java Developers (JavaOne)Introduciton to Apache Cassandra for Java Developers (JavaOne)
Introduciton to Apache Cassandra for Java Developers (JavaOne)
 
Monitoring MongoDB’s Engines in the Wild
Monitoring MongoDB’s Engines in the WildMonitoring MongoDB’s Engines in the Wild
Monitoring MongoDB’s Engines in the Wild
 

Mehr von Command Prompt., Inc

Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableHowdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableCommand Prompt., Inc
 
Python utilities for data presentation
Python utilities for data presentationPython utilities for data presentation
Python utilities for data presentationCommand Prompt., Inc
 
Implementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with TungstenImplementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with TungstenCommand Prompt., Inc
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksElephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksCommand Prompt., Inc
 
Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2Command Prompt., Inc
 
Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1Command Prompt., Inc
 
Integrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsIntegrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsCommand Prompt., Inc
 
Postgres for MySQL (and other database) people
Postgres for MySQL (and other database) peoplePostgres for MySQL (and other database) people
Postgres for MySQL (and other database) peopleCommand Prompt., Inc
 
Building Grails applications with PostgreSQL
Building Grails applications with PostgreSQLBuilding Grails applications with PostgreSQL
Building Grails applications with PostgreSQLCommand Prompt., Inc
 
Not Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion ConstraintsNot Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion ConstraintsCommand Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 

Mehr von Command Prompt., Inc (17)

Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableHowdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
 
Temporal Data
Temporal DataTemporal Data
Temporal Data
 
Python utilities for data presentation
Python utilities for data presentationPython utilities for data presentation
Python utilities for data presentation
 
Implementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with TungstenImplementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with Tungsten
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksElephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forks
 
5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance
 
Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2
 
Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1
 
Integrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsIntegrating PostGIS in Web Applications
Integrating PostGIS in Web Applications
 
Postgres for MySQL (and other database) people
Postgres for MySQL (and other database) peoplePostgres for MySQL (and other database) people
Postgres for MySQL (and other database) people
 
Building Grails applications with PostgreSQL
Building Grails applications with PostgreSQLBuilding Grails applications with PostgreSQL
Building Grails applications with PostgreSQL
 
Pg amqp
Pg amqpPg amqp
Pg amqp
 
Not Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion ConstraintsNot Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion Constraints
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Database Hardware Benchmarking
Database Hardware BenchmarkingDatabase Hardware Benchmarking
Database Hardware Benchmarking
 
Vertically Challenged
Vertically ChallengedVertically Challenged
Vertically Challenged
 
Simpycity and Exceptable
Simpycity and ExceptableSimpycity and Exceptable
Simpycity and Exceptable
 

A Practical Multi-Tenant Cluster

  • 1. A practical (pragmatic) multi-tenant cluster (Mental meandering) by Rod Anderson raanders@acm.org
  • 2. Credits • Thomas Jacobs http://wiki.postgresql.org/wiki/Shared_Database_Hosting http://www.internet24.de/ • Thomas Jacobs Scott Marlowe Robert Treat http://archives.postgresql.org/pgsql-admin/2008-08/msg00049.php • Tom Lane For the gentle suggestion to just try it when I asked about using '@' in role names.
  • 3. What is a multi-tenant cluster? • A single PostgreSQL database cluster. • One (or more) databases per customer. • One chunk of hardware. • Allowing many tenants to run the same applications in their own database.
  • 4. Why a multi-tenant cluster? • Single superuser (postgres?) for all databases, customers, clients. • Sharing of memory and processor(s). • Low impact applications or low usage needs, i.e. smaller businesses. • Hardware goes further. • Even a server inside a company/organization could benefit by having a database per department.
  • 5. Issues with a multi-tenant cluster • Missing - per database users/roles Actually there is a method in 8.4 but it doesn't play well with md5 requires the use of password. So if there is a possibility or concern of password "sniffing" this can't be used unless you use a SSL encrypted connection. See the following two links for the gory details. http://www.postgresql.org/docs/current/static/runtime-config-connection.html#GUC-DB-USER-NAMESPACE http://www.postgresql.org/docs/current/static/auth-methods.html • No method to add database roles when there is only a cluster superuser? That is allow create role but restrict those roles to a specific database. • If createuser is granted to a database administrator, what controls and options are there on role naming. • When deleting/removing users/roles how to clean up database spanning ACLs.
  • 6. Database resources controls. • Bad queries eating the database engine alive. • Disk and storage quotas • In PostgreSQL? • File system • OS? • CPU and memory quotas • PostgreSQL • OS
  • 7. What can be done and what can we do to make it easier. • Identify applications that can be modified to support or do support installation into a schema instead of a database. • Get around the global user/roles • Give each database it's own tablespace for data.
  • 8. Other multi-tenant options Though not what I'd consider true multi-tenant solutions there are • Multiple PostgreSQL instances • Linux-Vservers • XEN • BSD jails(?) • Others?
  • 9. Steps to create a multi-tenant cluster. 1. Come up with a database and role naming system. 2. Develop scripts to build the database and roles. 3. Method to control access to the cluster as painless as possible. 4. Modify application scripts to use a schema in a database instead of a database.
  • 10. Here is what I came up with. Databases and their controlling(?) role have short, almost mnemonic, names: acme, tsmg, snoi, etc. Tenant user/role names are in the form dba@acme, rt_user@acme, or ledgersmb@acme. pg_hba.conf has these four entries: local all postgres md5 local samerole all md5 host all postgres 0/0 md5 host samerole all 0/0 md5
  • 11. To install LedgerSMB I did a manual install and skipped/modified those steps that conflicted with the schema-based install. That is: I created the database, role, and schema then ran the LedgerSMB INSTALL steps manually. To create the database I use a shell script that makes the TABLESPACE directory and builds the SQL script. Here are some excerpts from the file. TSDIR="/var/lib/pgsql/data/ts" TENANT="$1" pushd "$TSDIR" [[ ! -d "$TENANT" ]] && mkdir "$TENANT" chown postgres:postgres "$TENANT" chmod 700 "$TENANT" popd
  • 12. The script creates and calls this SQL script. (Assuming a tenant called/named acme.) CREATE ROLE acme NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOLOGIN; CREATE ROLE "dba@acme" NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN ENCRYPTED PASSWORD '07cc54da9f666'; GRANT acme TO "dba@acme"; CREATE TABLESPACE acme_ts OWNER "dba@acme" LOCATION '/var/lib/pgsql/data/ts/acme'; CREATE DATABASE acme WITH OWNER="dba@acme"; COMMENT ON DATABASE acme IS 'Database create 20090319'; c acme GRANT ALL ON SCHEMA public TO "dba@acme" WITH GRANT OPTION;
  • 13. To create a schema specifically for the application I use a script specific to that application. For LedgerSMB it generates the following SQL script. CREATE ROLE "ledgersmb@acme" NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN ENCRYPTED PASSWORD 'c3c20524a6621'; GRANT USAGE ON SCHEMA public TO "ledgersmb@acme"; GRANT CONNECT, TEMPORARY ON DATABASE acme TO "ledgersmb@acme"; GRANT acme TO "ledgersmb@acme"; c acme CREATE SCHEMA ledgersmb AUTHORIZATION "ledgersmb@acme"; COMMENT ON SCHEMA ledgersmb IS 'Schema create 20090319'; ALTER ROLE "ledgersmb@acme" SET search_path = ledgersmb, public