Partition database between users and implement disk quotas
От | Brice André |
---|---|
Тема | Partition database between users and implement disk quotas |
Дата | |
Msg-id | CAOBG12mysVWSiEWUOCv2RHJ=doJyLfc++=D4W5odk5aDm9LDUw@mail.gmail.com обсуждение исходный текст |
Список | pgsql-sql |
Hello,<br /><br />I wrote an aplication where I store data from different users whithin the same database. There is no linkbetween data of different users.<br /><br />In my current implementation, I added a column "user_id" in each table, and,with views and rules mechanisms, I am able to hide data from other users. Everything works fine and I am happy with thissolution. But I now have another need : I would want to measure the disk usage of each user such that I can restrictthe access to the database when a user exceeds its limit.<br /><br />I envisaged three solutions to solve this problem,but I do not know which one would be the best : <br /><br />Solution1 : keep the same database layout, and countthe size of each record of a user. As some columns have variable sizes, this is not a really simple solution. And Ihave no idea on how to take into account index and stuff like that. I am not sure this solution is feasible and, if yes,I fear it will not be efficient to compute disk usage on this way.<br /><br />Solution 2 : use a separate database foreach client. This solution is probably the simplest one. But, one of the advantage of my previous solution was that Iwas able to use connection pool to connect to my database as all users are using the same database with same db user (accessis provided via a web service). With this solution, this will no more be possible: I will need a dedicated connectionfor each user. A second problem I am fearing is that I have a lot of clients (several hundreds) and I am not surethis is a good idea to create so much database on the same server.<br /><br />Solution 3 : use the table partitionningmechanism. I never used this feature, but from what I read in the doc, it seems that I could use this mechanismto put data from different clients in different partitions. As each partition is a dedicated sub-table, I supposeI could use dedicated postgresql mechanism to compute its size (including associated index and so on). I really thinkthis solution is well fitted to my need. The only thing that I fear is that I don't know if it's a good idea to partitiona table in hundreds of different partitions ?<br /><br />So, does someone has good advices to solve my problem ?Maybe there is another solution that I am not aware of ?<br /><br />Thanks in advance for your help,<br />Brice<br />
В списке pgsql-sql по дате отправления: