Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6921315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:15:41+00:00 2026-05-27T10:15:41+00:00

have an application in which many companies post information. the data from each company

  • 0

have an application in which many companies post information. the data from each company is self contained – there is no data overlap.

performance-wise, is it better to:

  • keep the company ID on each row of each table and have each index use it?
  • partition each table according to the company ID
  • partition and create a user to access each company to ensure security
  • create multiple databases, one for each company

web-based application with persistent connections.

my thoughts:

  • new pg connections are expensive, so a single database creates less new connections
  • having only one copy of the dictionary seems more efficient than 200 or so
  • multiple databases are certainly safer from programmer error
  • if application specs should change so companies share, multiple data
    base would be difficult to implement
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:15:42+00:00Added an answer on May 27, 2026 at 10:15 am

    I’d recommend searching for info on the PostgreSQL mailing lists about multi-tenanted design. There’s been lots of discussion there, and the answer boils down to “it depends”. There are trade-offs every way between guaranteed isolation, performance, and maintainability.

    A common approach is to use a single database, but one schema (namespace) per customer with the same table structure in each schema, plus a shared or common schema for data that’s the same across all of them. A PostgreSQL schema is like a MySQL “database” in that you can query across different schema but they’re isolated by default. With customer data in separate schema you can use the search_path setting, usually via ALTER USER customername SET search_path = 'customerschema, sharedschema' to ensure each customer sees their data and only their data.

    For additional protection, you should REVOKE ALL FROM SCHEMA customerschema FROM public then GRANTALL ON SCHEMA customerschema TO thecustomer so they’re the only one with any access to it, doing the same to each of their tables. Your connection pool then can log in with a fixed user account that has no GRANTed access to any customer schema but has the right to SET ROLE to become any customer. (Do that by giving them membership of each customer role with NOINHERIT set so rights have to be explicitly claimed via SET ROLE). The connection should immediately SET ROLE to the customer it’s currently operating as. That’ll allow you to avoid the overhead of making new connections for each customer while maintaining strong protection against programmer error leading to access to the wrong customer’s data. So long as the pool does a DISCARD ALL and/or a RESET ROLE before handing connections out to the next client, that’s going to give you very strong isolation without the frustration of individual connections per-user.

    If your web app environment doesn’t have a decent connection pool built-in (say, you’re using PHP with persistent connections) then you really need to put a good connection pool in place between Pg and the web server anyway, because too many connections to the backend will hurt your performance. PgBouncer and PgPool-II are the best options, and handily can take care of doing the DISCARD ALL and RESET ROLE for you during connection hand-off.

    The main downside of this approach is the overhead with maintaining that many tables, since your base set of non-shared tables is cloned for each customer. It’ll add up as customer numbers grow, to the point where the sheer number of tables to examine during autovacuum runs starts to get expensive and where any operation that scales based on the total number of tables in the DB slows down. This is more of an issue if you’re thinking of having many thousands or tens of thousands of customers in the same DB, but I strongly recommend you do some scaling tests with this design using dummy data before committing to it.

    The ideal approach is likely to be single tables with automatic row-level security controlling tuple visibility, but unfortunately that’s something PostgreSQL doesn’t have yet. It looks like it’s on the way thanks to the SEPostgreSQL work adding suitable infrastructure and APIs, but it’s not in 9.1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application which extracts data from an XML file using XPath. If
I have an application which has many stories Each story has and belongs to
I have Richfaces application which I deploy to Glassfish v3. For many weeks (almost)
I'm writing a WinForms application. I have many labels which represent some status (Enabled/Disabled
We have a project with many dll files which get loaded when the application
I have an application which has many services and one UI module. All these
I have a GUI application which can create many similar windows on desktop. All
I have an application which can only have 1 instance running at each time,
I have an application which periodically (after each 1 or 2 seconds) takes checkpoints
I have an iPad application which has many categorized images I need to switch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.