Re: Separation of clients' data within a database

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: John McCawley <nospam(at)hardgeus(dot)com>
Cc: Rodrigo Gonzalez <rjgonzale(at)gmail(dot)com>, Leonel Nunez <lnunez(at)enelserver(dot)com>, pgsql general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Separation of clients' data within a database
Date: 2006-11-30 19:47:57
Message-ID: 1164916076.14565.271.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 2006-11-30 at 13:45, John McCawley wrote:
> Note that my in my current code, application-level permissions are
> completely detached from database permissions. The entire web app uses
> one user/pass to login to the database. The web app is used both by
> individual companies who can only view their data, and also the
> overseeing company who is capable of viewing everything. While they
> are logging in with different application-level users, they are querying
> with the same database-level user. My question regarding database
> user-level permission was for the purpose of the IT departments going
> "under the hood" rather than for security in my web app.
>
> As the app is currently written, I have dropdown filters for what data
> the report will produce. The "lesser' companies' filter forces them to
> view only their data (where tbl_foo.company_id = bar), whereas the
> overseeing company runs the same report without a filter, and the data
> is organized with a group by. Right now, the addition of a company is
> simply an addition of a row in the client table, and the app adjusts
> without modification. If I add a schema per company, every time I add a
> company I would have to modify every query in the system to also pull
> from this additional schema, or modify my entire application to pull
> from views which must be modified every time a company is added...

That's just the point of search_path.

For me, it can be:

alter user smarlowe set search_path='common','smarlowe';

for joe user it might be

alter user joe_user set search_path='common','joe_user';

and all you have to change is the connection statement for your app
depending on who logged in. voila!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vivek Khera 2006-11-30 19:54:31 Re: Stripping kernel FreeBSD - postgres
Previous Message John McCawley 2006-11-30 19:45:48 Re: Separation of clients' data within a database