User Quota Implementation

Started by Jonah H. Harrisalmost 22 years ago70 messageshackers
Jump to latest
#1Jonah H. Harris
jharris@tvi.edu

All,

Out of necessity, I've implemented user quotas in 7.4.3. What would the
process be for having this reviewed and combined? I have a patch for
7.4.3 ready, but wanted to know if you suggest that I patch the latest
cvs instead. Below if some information on the implementation.

=======================================================================
-- FACTS --------------------------------------------------------------
=======================================================================

1. Only a superuser can modify user quotas.
2. The minimum quota size is 1K.
3. The maximum quota size is (currently) the maximum of int4*1024 bytes.
4. Altering a user's quota does not make a change to their current data.
5. If you modify a user's quota to smaller than their current amount,
they will be unable to add any more data... but their current schema is
not truncated.

=======================================================================
-- SQL CHANGES --------------------------------------------------------
=======================================================================

COMMAND: ALTER USER

*** NEW SYNTAX ***

ALTER USER name [ [ WITH ] option [ ... ] ]

where option can be:

[ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password'
| CREATEDB | NOCREATEDB
| CREATEUSER | NOCREATEUSER
| VALID UNTIL 'abstime'
| QUOTA file_size | NOQUOTA

where file_size is:

integer[K | M | G]

K = Kilobytes
M = Megabytes
G = Gigabytes

=======================================================================
-- USAGE EXAMPLES -----------------------------------------------------
=======================================================================

*** VARIATIONS OF QUOTA SIZES ***
ALTER USER someuser QUOTA 50M;
ALTER USER someuser QUOTA 1G;
ALTER USER someuser QUOTA 500K;

*** GIVE USER AN UNLIMITED QUOTA ***
ALTER USER someuser NOQUOTA;

=======================================================================
-- INTERNAL CHANGES ---------------------------------------------------
=======================================================================

pg_shadow has added attribute userquota of type int4
pg_user view has added attribute (pg_shadow.userquota) to selection.

ADDED KEYWORDS

QUOTA
NOQUOTA

--
Jonah H. Harris, UNIX Administrator | phone: 505.224.4814
Albuquerque TVI | fax: 505.224.3014
525 Buena Vista SE | jharris@tvi.edu
Albuquerque, New Mexico 87106 | http://w3.tvi.edu/~jharris/

"All great truths begin as blasphemies."
-- George Bernard Shaw

#2Stephen Frost
sfrost@snowman.net
In reply to: Jonah H. Harris (#1)
Re: User Quota Implementation

* Jonah H. Harris (jharris@tvi.edu) wrote:

Out of necessity, I've implemented user quotas in 7.4.3. What would the
process be for having this reviewed and combined? I have a patch for
7.4.3 ready, but wanted to know if you suggest that I patch the latest
cvs instead. Below if some information on the implementation.

Personally, I would love to see this in PostgreSQL. It'd be great if it
could get into 7.5. An issue I see with that is that (similar to
Oracle...) I think people would want to be able to specify
per-tablespace quotas. Perhaps that wouldn't be too hard to add?

Stephen

#3Christopher Kings-Lynne
chriskl@familyhealth.com.au
In reply to: Stephen Frost (#2)
Re: User Quota Implementation

Personally, I would love to see this in PostgreSQL. It'd be great if it
could get into 7.5. An issue I see with that is that (similar to
Oracle...) I think people would want to be able to specify
per-tablespace quotas. Perhaps that wouldn't be too hard to add?

7.5 is already closed for new features I believe...

Chris

#4Stephen Frost
sfrost@snowman.net
In reply to: Christopher Kings-Lynne (#3)
Re: User Quota Implementation

* Christopher Kings-Lynne (chriskl@familyhealth.com.au) wrote:

Personally, I would love to see this in PostgreSQL. It'd be great if it
could get into 7.5. An issue I see with that is that (similar to
Oracle...) I think people would want to be able to specify
per-tablespace quotas. Perhaps that wouldn't be too hard to add?

7.5 is already closed for new features I believe...

Quotas is part of a sane tablespace implementation, right? O;)

Stephen

#5The Hermit Hacker
scrappy@hub.org
In reply to: Christopher Kings-Lynne (#3)
Re: User Quota Implementation

On Fri, 9 Jul 2004, Christopher Kings-Lynne wrote:

Personally, I would love to see this in PostgreSQL. It'd be great if it
could get into 7.5. An issue I see with that is that (similar to
Oracle...) I think people would want to be able to specify
per-tablespace quotas. Perhaps that wouldn't be too hard to add?

7.5 is already closed for new features I believe...

Very much so ...

----
Marc G. Fournier Hub.Org Networking Services (http://www.hub.org)
Email: scrappy@hub.org Yahoo!: yscrappy ICQ: 7615664

#6The Hermit Hacker
scrappy@hub.org
In reply to: Stephen Frost (#4)
Re: User Quota Implementation

On Fri, 9 Jul 2004, Stephen Frost wrote:

* Christopher Kings-Lynne (chriskl@familyhealth.com.au) wrote:

Personally, I would love to see this in PostgreSQL. It'd be great if it
could get into 7.5. An issue I see with that is that (similar to
Oracle...) I think people would want to be able to specify
per-tablespace quotas. Perhaps that wouldn't be too hard to add?

7.5 is already closed for new features I believe...

Quotas is part of a sane tablespace implementation, right? O;)

So its still considered a 'missing feature', not a bug ...

----
Marc G. Fournier Hub.Org Networking Services (http://www.hub.org)
Email: scrappy@hub.org Yahoo!: yscrappy ICQ: 7615664

#7Rod Taylor
rbt@rbt.ca
In reply to: Stephen Frost (#4)
Re: User Quota Implementation

On Fri, 2004-07-09 at 09:29, Stephen Frost wrote:

* Christopher Kings-Lynne (chriskl@familyhealth.com.au) wrote:

Personally, I would love to see this in PostgreSQL. It'd be great if it
could get into 7.5. An issue I see with that is that (similar to
Oracle...) I think people would want to be able to specify
per-tablespace quotas. Perhaps that wouldn't be too hard to add?

7.5 is already closed for new features I believe...

Quotas is part of a sane tablespace implementation, right? O;)

I would think having would allow us to take advantage of all of the
various kernel level filesystem features without needing to implement
them directly within PostgreSQL (crypto, quotas, data mirror, etc.).

Simply setup a tablespace for a given user with permissions to allow
only that user to create new objects within it and make it the default
location) -- tie their schema to their tablespace? -- then set a kernel
level quota on their tablespace.

Or do we expect a PostgreSQL implementation to do more than that, to
only count active data by ignoring data pending a vacuum?

#8Klaus Naumann
kn@mgnet.de
In reply to: Jonah H. Harris (#1)
Re: User Quota Implementation

On Thu, 8 Jul 2004, Jonah H. Harris wrote:

Hi,

3. The maximum quota size is (currently) the maximum of int4*1024 bytes.

why is this? This is very limiting ...
Using a 64bit value would be a lot more straight foreward.

Greetings, Klaus

--
Full Name : Klaus Naumann | (http://www.mgnet.de/) (Germany)
Phone / FAX : ++49/177/7862964 | E-Mail: (kn@mgnet.de)

#9Rod Taylor
rbt@rbt.ca
In reply to: Rod Taylor (#7)
Re: User Quota Implementation

On Fri, 2004-07-09 at 10:14, Rod Taylor wrote:

On Fri, 2004-07-09 at 09:29, Stephen Frost wrote:

* Christopher Kings-Lynne (chriskl@familyhealth.com.au) wrote:

Personally, I would love to see this in PostgreSQL. It'd be great if it
could get into 7.5. An issue I see with that is that (similar to
Oracle...) I think people would want to be able to specify
per-tablespace quotas. Perhaps that wouldn't be too hard to add?

7.5 is already closed for new features I believe...

Quotas is part of a sane tablespace implementation, right? O;)

I would think having would allow us to take advantage of all of the

^^^

having tablespaces would

#10Stephen Frost
sfrost@snowman.net
In reply to: Rod Taylor (#7)
Re: User Quota Implementation

* Rod Taylor (pg@rbt.ca) wrote:

I would think having would allow us to take advantage of all of the
various kernel level filesystem features without needing to implement
them directly within PostgreSQL (crypto, quotas, data mirror, etc.).

Simply setup a tablespace for a given user with permissions to allow
only that user to create new objects within it and make it the default
location) -- tie their schema to their tablespace? -- then set a kernel
level quota on their tablespace.

Since the user accessing/writing to the tablespaces would be the
postgres user I don't really think this 'solution' works in reality.

Or do we expect a PostgreSQL implementation to do more than that, to
only count active data by ignoring data pending a vacuum?

Certainly, it should.

Stephen

#11Rod Taylor
rbt@rbt.ca
In reply to: Stephen Frost (#10)
Re: User Quota Implementation

Simply setup a tablespace for a given user with permissions to allow
only that user to create new objects within it and make it the default
location) -- tie their schema to their tablespace? -- then set a kernel
level quota on their tablespace.

Since the user accessing/writing to the tablespaces would be the
postgres user I don't really think this 'solution' works in reality.

I had assumed it would be a directory based quota rather than a user
based one.

Or do we expect a PostgreSQL implementation to do more than that, to
only count active data by ignoring data pending a vacuum?

Certainly, it should.

Okay. But just so we all know that this means the user with a 5MB quota
could still (potentially) fill 1TB of physical diskspace.

#12Stephen Frost
sfrost@snowman.net
In reply to: Rod Taylor (#11)
Re: User Quota Implementation

* Rod Taylor (pg@rbt.ca) wrote:

Simply setup a tablespace for a given user with permissions to allow
only that user to create new objects within it and make it the default
location) -- tie their schema to their tablespace? -- then set a kernel
level quota on their tablespace.

Since the user accessing/writing to the tablespaces would be the
postgres user I don't really think this 'solution' works in reality.

I had assumed it would be a directory based quota rather than a user
based one.

It's been a while since I played with quotas but I don't recall this
option being available.

Or do we expect a PostgreSQL implementation to do more than that, to
only count active data by ignoring data pending a vacuum?

Certainly, it should.

Okay. But just so we all know that this means the user with a 5MB quota
could still (potentially) fill 1TB of physical diskspace.

Hmm, interesting point. What are the options? Make sure the user
understands they have to vacuum their tables in order to regain the
space? Have two seperate values (similar to soft vs. hard limits) that
the admin sets? Either (or both) of those seem reasonable to me.

Stephen

#13Rod Taylor
rbt@rbt.ca
In reply to: Stephen Frost (#12)
Re: User Quota Implementation

Since the user accessing/writing to the tablespaces would be the
postgres user I don't really think this 'solution' works in reality.

I had assumed it would be a directory based quota rather than a user
based one.

It's been a while since I played with quotas but I don't recall this
option being available.

Group quotas should be sufficient. Create directory readable/writable to
only the pgsql user, but have the group ownership be representative of
the user in question.

#14Stephen Frost
sfrost@snowman.net
In reply to: Rod Taylor (#13)
Re: User Quota Implementation

* Rod Taylor (pg@rbt.ca) wrote:

Since the user accessing/writing to the tablespaces would be the
postgres user I don't really think this 'solution' works in reality.

I had assumed it would be a directory based quota rather than a user
based one.

It's been a while since I played with quotas but I don't recall this
option being available.

Group quotas should be sufficient. Create directory readable/writable to
only the pgsql user, but have the group ownership be representative of
the user in question.

Rather ugly, and you'll run out of groups if you have alot of users (the
postgres user can only be in so many groups). It's a cute idea but I
really don't see it as being viable.

Stephen

#15Alvaro Herrera
alvherre@dcc.uchile.cl
In reply to: Jonah H. Harris (#1)
Re: User Quota Implementation

On Thu, Jul 08, 2004 at 03:27:34PM -0600, Jonah H. Harris wrote:

Out of necessity, I've implemented user quotas in 7.4.3. What would the
process be for having this reviewed and combined? I have a patch for
7.4.3 ready, but wanted to know if you suggest that I patch the latest
cvs instead. Below if some information on the implementation.

At exactly what time is the quota enforced? Does the enforcement
somehow serialize that operation?

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
Thou shalt study thy libraries and strive not to reinvent them without
cause, that thy code may be short and readable and thy days pleasant
and productive. (7th Commandment for C Programmers)

#16Stephen Frost
sfrost@snowman.net
In reply to: Klaus Naumann (#8)
Re: User Quota Implementation

* Klaus Naumann (kn@mgnet.de) wrote:

On Thu, 8 Jul 2004, Jonah H. Harris wrote:

3. The maximum quota size is (currently) the maximum of int4*1024 bytes.

why is this? This is very limiting ...

It's 2TB...

Using a 64bit value would be a lot more straight foreward.

It sounded to me like it might be a limitation forced by some other part
of postgres, but I don't really know... Good question though.

Stephen

#17Jonah H. Harris
jharris@tvi.edu
In reply to: Stephen Frost (#14)
Re: User Quota Implementation

There are a couple of modifications that I'd still like to make to user
quotas. Because 7.5 is locked, this may be a good time to discuss the
implementation (possibly for 7.6?)

I have seen some discussion about using OS-level quotas on a user or
group level, however, like our Oracle system, not all database users
have a system account. This is why I needed to implement user-specific
quota functionality within the database itself.

Also note, my quota implementation currently expects a well-vacuumed
database. I always use pg_autovacuum but don't know about most other
people.

I'd like to make the following changes... Let me know your thoughts.

- Change userquota from int4 to int8.

- userquota is stored in units of kilobytes... is this adequate? Would
anyone ever use a quota < 1K other than for allowing a user no space?
If the user has no space, why not just disable the account and/or make
them read-only?

- Would anyone want to use a group quota in PGSQL (rather than user-only)?

- I assume that, based on discussion, not everyone sets up
auto-vacuuming and therefore I would need to change the way I perform
calculations.

- Quota acts on any object owned by the user. Is this adequate for
everyone?

- Hard limits vs. soft limits... does anyone think it's a good idea to
truncate someone's data? I personally don't think it's a good idea.

- What do you think about userquota being the attribute in pg_shadow...
would you rather see something else.

Is there any additional functionality you would like to see in a quota
implementation?

Would you rather see ALTER USER SET for quota rather than ALTER USER?
Likewise, I had originally used ALTER USER username QUOTA UNLIMITED (in
Oracle style) but found that it didn't meet PostgreSQL's common
syntax... which is why I changed it to ALTER USER username NOQUOTA...
does everyone agree with NOQUOTA over QUOTA UNLIMITED?

-Jonah

Stephen Frost wrote:

* Rod Taylor (pg@rbt.ca) wrote:

Since the user accessing/writing to the tablespaces would be the
postgres user I don't really think this 'solution' works in reality.

I had assumed it would be a directory based quota rather than a user
based one.

It's been a while since I played with quotas but I don't recall this
option being available.

Group quotas should be sufficient. Create directory readable/writable to
only the pgsql user, but have the group ownership be representative of
the user in question.

Rather ugly, and you'll run out of groups if you have alot of users (the
postgres user can only be in so many groups). It's a cute idea but I
really don't see it as being viable.

Stephen

--
Jonah H. Harris, UNIX Administrator | phone: 505.224.4814
Albuquerque TVI | fax: 505.224.3014
525 Buena Vista SE | jharris@tvi.edu
Albuquerque, New Mexico 87106 | http://w3.tvi.edu/~jharris/

"All great truths begin as blasphemies."
-- George Bernard Shaw

#18Rod Taylor
rbt@rbt.ca
In reply to: Stephen Frost (#14)
Re: User Quota Implementation

Group quotas should be sufficient. Create directory readable/writable to
only the pgsql user, but have the group ownership be representative of
the user in question.

Rather ugly, and you'll run out of groups if you have alot of users (the
postgres user can only be in so many groups). It's a cute idea but I
really don't see it as being viable.

The postgres user doesn't need to be in any of the groups, the group
simply exists simply to give the directory representation for a quota.

#19Jonah H. Harris
jharris@tvi.edu
In reply to: Alvaro Herrera (#15)
Re: User Quota Implementation

Quota is currently enforced on commit. I've considered checking during
insert/update/copy and throwing an abort but within a transaction they
may be deleting data as well.

However, even as a delete may take place before a massive insert/update,
a vacuum cannot be run within a transaction block and therefore the
commit would fail at the same point as an insert/update within the
transaction itself.

So, essentially, there is no difference at which point to check other
than to reduce the calculation overhead by placing the check at the
commit point.

What's the consensus on when to check?

Alvaro Herrera wrote:

On Thu, Jul 08, 2004 at 03:27:34PM -0600, Jonah H. Harris wrote:

Out of necessity, I've implemented user quotas in 7.4.3. What would the
process be for having this reviewed and combined? I have a patch for
7.4.3 ready, but wanted to know if you suggest that I patch the latest
cvs instead. Below if some information on the implementation.

At exactly what time is the quota enforced? Does the enforcement
somehow serialize that operation?

--
Jonah H. Harris, UNIX Administrator | phone: 505.224.4814
Albuquerque TVI | fax: 505.224.3014
525 Buena Vista SE | jharris@tvi.edu
Albuquerque, New Mexico 87106 | http://w3.tvi.edu/~jharris/

"All great truths begin as blasphemies."
-- George Bernard Shaw

#20Rod Taylor
rbt@rbt.ca
In reply to: Stephen Frost (#16)
Re: User Quota Implementation

On Fri, 2004-07-09 at 11:47, Stephen Frost wrote:

* Klaus Naumann (kn@mgnet.de) wrote:

On Thu, 8 Jul 2004, Jonah H. Harris wrote:

3. The maximum quota size is (currently) the maximum of int4*1024 bytes.

why is this? This is very limiting ...

It's 2TB...

Okay.. that is good for a few years. What do we do after 2007?

#21James Robinson
jlrobins@socialserve.com
In reply to: Jonah H. Harris (#17)
#22Klaus Naumann
kn@mgnet.de
In reply to: Stephen Frost (#16)
#23Alvaro Herrera
alvherre@dcc.uchile.cl
In reply to: Jonah H. Harris (#19)
#24Alvaro Herrera
alvherre@dcc.uchile.cl
In reply to: Jonah H. Harris (#17)
#25Stephen Frost
sfrost@snowman.net
In reply to: Rod Taylor (#18)
#26Jonah H. Harris
jharris@tvi.edu
In reply to: James Robinson (#21)
#27Stephen Frost
sfrost@snowman.net
In reply to: Rod Taylor (#20)
#28Jonah H. Harris
jharris@tvi.edu
In reply to: Stephen Frost (#27)
#29The Hermit Hacker
scrappy@hub.org
In reply to: Jonah H. Harris (#17)
#30Jonah H. Harris
jharris@tvi.edu
In reply to: Stephen Frost (#12)
#31Josh Berkus
josh@agliodbs.com
In reply to: Jonah H. Harris (#30)
#32Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#23)
#33Jonah H. Harris
jharris@tvi.edu
In reply to: Tom Lane (#32)
#34Doug McNaught
doug@mcnaught.org
In reply to: Jonah H. Harris (#33)
#35Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jonah H. Harris (#33)
#36Yann Michel
yann-postgresql@spline.de
In reply to: Tom Lane (#35)
#37Bruce Momjian
bruce@momjian.us
In reply to: Yann Michel (#36)
#38Yann Michel
yann-postgresql@spline.de
In reply to: Bruce Momjian (#37)
#39Bruce Momjian
bruce@momjian.us
In reply to: Yann Michel (#38)
#40Yann Michel
yann-postgresql@spline.de
In reply to: Bruce Momjian (#39)
#41Bruce Momjian
bruce@momjian.us
In reply to: Yann Michel (#40)
#42Yann Michel
yann-postgresql@spline.de
In reply to: Bruce Momjian (#41)
#43Bruce Momjian
bruce@momjian.us
In reply to: Yann Michel (#42)
#44Josh Berkus
josh@agliodbs.com
In reply to: Bruce Momjian (#43)
#45Tom Lane
tgl@sss.pgh.pa.us
In reply to: Josh Berkus (#44)
#46Yann Michel
yann-postgresql@spline.de
In reply to: Josh Berkus (#44)
#47Yann Michel
yann-postgresql@spline.de
In reply to: Tom Lane (#45)
#48Josh Berkus
josh@agliodbs.com
In reply to: Yann Michel (#46)
#49Jonah H. Harris
jharris@tvi.edu
In reply to: Josh Berkus (#48)
#50Yann Michel
yann-postgresql@spline.de
In reply to: Josh Berkus (#48)
#51Dave Page
dpage@pgadmin.org
In reply to: Yann Michel (#50)
#52Yann Michel
yann-postgresql@spline.de
In reply to: Dave Page (#51)
#53Josh Berkus
josh@agliodbs.com
In reply to: Yann Michel (#52)
#54Jonah H. Harris
jharris@tvi.edu
In reply to: Josh Berkus (#53)
#55Josh Berkus
josh@agliodbs.com
In reply to: Jonah H. Harris (#54)
#56Stephen Frost
sfrost@snowman.net
In reply to: Josh Berkus (#55)
#57Yann Michel
yann-postgresql@spline.de
In reply to: Josh Berkus (#55)
#58Jonah H. Harris
jharris@tvi.edu
In reply to: Yann Michel (#57)
#59Josh Berkus
josh@agliodbs.com
In reply to: Jonah H. Harris (#58)
#60Tom Lane
tgl@sss.pgh.pa.us
In reply to: Josh Berkus (#55)
#61Yann Michel
yann-postgresql@spline.de
In reply to: Josh Berkus (#59)
#62Jonah H. Harris
jharris@tvi.edu
In reply to: Yann Michel (#61)
#63Josh Berkus
josh@agliodbs.com
In reply to: Jonah H. Harris (#62)
#64Josh Berkus
josh@agliodbs.com
In reply to: Josh Berkus (#63)
#65Jonah H. Harris
jharris@tvi.edu
In reply to: Josh Berkus (#64)
#66Yann Michel
yann-postgresql@spline.de
In reply to: Jonah H. Harris (#65)
#67Yann Michel
yann-postgresql@spline.de
In reply to: Jonah H. Harris (#58)
#68Jonah H. Harris
jharris@tvi.edu
In reply to: Yann Michel (#67)
#69Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jonah H. Harris (#68)
#70Jonah H. Harris
jharris@tvi.edu
In reply to: Tom Lane (#69)