X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id B040F9FA169 for ; Tue, 23 May 2006 17:17:29 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 37726-05 for ; Tue, 23 May 2006 17:17:12 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wx-out-0102.google.com (wx-out-0102.google.com [66.249.82.195]) by postgresql.org (Postfix) with ESMTP id 45A099FA279 for ; Tue, 23 May 2006 17:17:12 -0300 (ADT) Received: by wx-out-0102.google.com with SMTP id s17so403715wxc for ; Tue, 23 May 2006 13:17:11 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:from:to:subject:date:user-agent:mime-version:content-type:content-transfer-encoding:content-disposition:message-id:x-virus-scanned; b=XjJNHBOwEOoaCnHaFw6yyELpwaxPFmiK2zpTH+3BBw/8Xsix8H3tJNfs+A9nrTeH8o1b7XE+O6j9VKlttUx/Orfl8O3CIHzb72L3J0yTzhDhrbeG4RHJYKDZnQHnNdrJicjyOWBrcM9KS3OhE9R8CKJcq6j62/8mySb4SLuTNWY= Received: by 10.70.65.9 with SMTP id n9mr6829344wxa; Tue, 23 May 2006 13:17:11 -0700 (PDT) Received: from strongwill.g2ctech ( [201.22.53.94]) by mx.gmail.com with ESMTP id h39sm6685024wxd.2006.05.23.13.17.09; Tue, 23 May 2006 13:17:10 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by strongwill.g2ctech (Postfix) with ESMTP id 626A2947B1 for ; Tue, 23 May 2006 18:16:18 -0300 (BRT) Received: from strongwill.g2ctech ([127.0.0.1]) by localhost (strongwill [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 11976-02-2 for ; Tue, 23 May 2006 18:16:18 -0300 (BRT) Received: from jupiter.g2ctech (unknown [10.0.0.240]) by strongwill.g2ctech (Postfix) with ESMTP id 43E0B12038 for ; Tue, 23 May 2006 18:16:18 -0300 (BRT) Received: from localhost (localhost [IPv6:::1]) by jupiter.g2ctech (Postfix) with ESMTP id CF733113B05 for ; Tue, 23 May 2006 17:17:03 -0300 (BRT) From: Jorge Godoy To: pgsql-sql@postgresql.org Subject: (Ab)Using schemas and inheritance Date: Tue, 23 May 2006 17:16:54 -0300 User-Agent: KMail/1.9.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200605231716.58784.jgodoy@gmail.com> X-Virus-Scanned: amavisd-new at g2ctech.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/180 X-Sequence-Number: 25211 Hi! I'm modelling an application that will have data -- financial data, human resources, etc. -- for several hundred (even thousands) of companies. This is for an accounting office. I could put some kind of "company_id" column in all of my tables to separate data in a more standard way, I could create a separate schema for each client and then create all needed tables in there (could I? I'd be abusing schemas here and this is part of my doubt) and, finally, I could create a "base" schema, define all my standard tables and create an individual schema for each client where I'd inherit from those base.tables. This would allow me to separate all information with a "SET search_path TO company" without having to make the restriction "by hand" (on "company_id", for example). It would also allow me to view some complete statistics grouping all clients by SELECTing data from the base schema. We're testing views and functions to see how they behave with inherited tables and changes on "search_path", and it looks like we can do that for, at least, a small number of schemas. Of course, this has implications on permissions as well, so there will be a large number of groups -- probably at least one per schema + some common groups -- and roles as well... Is this a good idea? Would this be too bad, performance-wise, if I had thousands of schemas to use like that? Any advice on better approaches? Any expected problems? TIA, -- Jorge Godoy