pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedAlternate database locations
11+ messages / 4 participants
[nested] [flat]
* Alternate database locations
@ 2001-05-31 20:30 Tauren Mills <tauren@servlets.net>
2001-06-06 01:15 ` RE: Alternate database locations Tauren Mills <tauren@servlets.net>
0 siblings, 1 reply; 11+ messages in thread
From: Tauren Mills @ 2001-05-31 20:30 UTC (permalink / raw)
To: pgsql-admin
I'm new to PostgreSQL and am trying to implement it in a shared web
application hosting environment. Ideally, I'd like each customer to have
their databases stored within their own user area. For instance, the
/home/user1/.pgsql would contain all of user1's databases.
It looks like this could be done by using an environment variable for each
customer, running initlocation for each. For instance:
PGDATA2=/home/user1/.pgsql; export PGDATA2
initlocation PGDATA2
createdb -D PGDATA2 user1_test
However, since I'll have around 50 different database locations, I'll have
to start the postmaster with PGDATA2, PGDATA3, PGDATA4, ..., PGDATA50 all
defined. This doesn't seem like a good solution.
There also appears to be a way to create databases with an absolute path,
but this is turned off by default for security reasons. I haven't tried
this yet, but it looks like I'd have to recompile with different settings
for ALLOW_ABSOLUTE_DBPATHS. This URL has more info:
http://www.postgresql.org/idocs/index.php?managing-databases.html
However, this page indicates that there are security risks in doing this.
What are those risks? If I prevent users other than the superuser
"postgres" from being able to create and drop databases, are there any
security risks?
Lastly, I've even tried creating a database normally, then moving it to the
user's area and creating a symlink to it. But this didn't seem to work.
Any ideas why it wouldn't work?
The main reason for putting the databases in each user's directory is for
billing purposes. It makes it easier to determine how much disk space a
customer is using. I would also consider keeping all of the databases in a
common location if there are easy ways to determine the following:
* Is there an easy way to map database directories in the file system to
database names? The directories names in /var/lib/pgsql/data/base/ are not
very helpful.
* Is there any command or tool that reports how much space a database is
taking up? Obviously du will work, but it would be nice if there was a
reporting tool that would output the database name instead of the directory
name.
Are there any other options that I'm missing? Any suggestions for a
different approach? Anyone know what other hosting providers are doing?
Thanks!
Tauren
^ permalink raw reply [nested|flat] 11+ messages in thread
* RE: Alternate database locations
2001-05-31 20:30 Alternate database locations Tauren Mills <tauren@servlets.net>
@ 2001-06-06 01:15 ` Tauren Mills <tauren@servlets.net>
2001-06-06 05:25 ` Re: Alternate database locations Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 11+ messages in thread
From: Tauren Mills @ 2001-06-06 01:15 UTC (permalink / raw)
To: pgsql-admin
I'm not sure how this message got posted again. I think it is because I
posted it to the newsgroup first but it was rejected since I was not a
member of the list. Now that I'm a member, I'm assuming it went through.
However, I'd already sent it directly to the list as an email after joining.
Sorry for the noise.
Tauren
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: Alternate database locations
2001-05-31 20:30 Alternate database locations Tauren Mills <tauren@servlets.net>
2001-06-06 01:15 ` RE: Alternate database locations Tauren Mills <tauren@servlets.net>
@ 2001-06-06 05:25 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-06-06 05:59 ` RE: [ADMIN] Alternate database locations Tauren Mills <tauren@servlets.net>
0 siblings, 1 reply; 11+ messages in thread
From: Tom Lane @ 2001-06-06 05:25 UTC (permalink / raw)
To: Tauren Mills <tauren@servlets.net>; +Cc: pgsql-admin
"Tauren Mills" <tauren@servlets.net> writes:
> I'm not sure how this message got posted again. I think it is because I
> posted it to the newsgroup first but it was rejected since I was not a
> member of the list. Now that I'm a member, I'm assuming it went through.
If you get a response about "you're not a list member", that actually
means that your message is sitting in Marc's queue to approve for
posting. Seems like he sifts through the queue every couple or three
days. So, if you in the meantime subscribe and repost your message,
we'll see it again when Marc approves the original. (Unless he happens
to notice it's a duplicate, which more often than not he doesn't.)
Fear not, we're used to this. It beats having the lists inundated by
spam, which is what would happen if Marc weren't filtering nonmember
postings :-(
regards, tom lane
^ permalink raw reply [nested|flat] 11+ messages in thread
* RE: [ADMIN] Alternate database locations
2001-05-31 20:30 Alternate database locations Tauren Mills <tauren@servlets.net>
2001-06-06 01:15 ` RE: Alternate database locations Tauren Mills <tauren@servlets.net>
2001-06-06 05:25 ` Re: Alternate database locations Tom Lane <tgl@sss.pgh.pa.us>
@ 2001-06-06 05:59 ` Tauren Mills <tauren@servlets.net>
0 siblings, 0 replies; 11+ messages in thread
From: Tauren Mills @ 2001-06-06 05:59 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general@postgresql.org
> Fear not, we're used to this. It beats having the lists inundated by
> spam, which is what would happen if Marc weren't filtering nonmember
> postings :-(
Thanks, I figured it was something like that!
T.
^ permalink raw reply [nested|flat] 11+ messages in thread
* Alternate database locations
@ 2001-06-04 09:16 Tauren Mills <tauren@servlets.net>
2001-06-04 10:11 ` Re: Alternate database locations Peter Eisentraut <peter_e@gmx.net>
0 siblings, 1 reply; 11+ messages in thread
From: Tauren Mills @ 2001-06-04 09:16 UTC (permalink / raw)
To: pgsql-general@postgresql.org; pgsql-admin
I've sent this to both pgsql-general and pgsql-admin. Please advise which
is the proper list for this type of question.
I'm new to PostgreSQL and am trying to implement it in a shared web
application hosting environment. Ideally, I'd like each customer to have
their databases stored within their own user area. For instance, the
/home/user1/.pgsql would contain all of user1's databases.
It looks like this could be done by using an environment variable for each
customer, running initlocation for each. For instance:
PGDATA2=/home/user1/.pgsql; export PGDATA2
initlocation PGDATA2
createdb -D PGDATA2 user1_test
However, since I'll have around 50 different database locations, I'll have
to start the postmaster with PGDATA2, PGDATA3, PGDATA4, ..., PGDATA50 all
defined. This doesn't seem like a good solution.
There also appears to be a way to create databases with an absolute path,
but this is turned off by default for security reasons. I haven't tried
this yet, but it looks like I'd have to recompile with different settings
for ALLOW_ABSOLUTE_DBPATHS. This URL has more info:
http://www.postgresql.org/idocs/index.php?managing-databases.html
However, this page indicates that there are security risks in doing this.
What are those risks? If I prevent users other than the superuser
"postgres" from being able to create and drop databases, are there any
security risks?
Lastly, I've even tried creating a database normally, then moving it to the
user's area and creating a symlink to it. But this didn't seem to work.
Any ideas why it wouldn't work?
The main reason for putting the databases in each user's directory is for
billing purposes. It makes it easier to determine how much disk space a
customer is using. I would also consider keeping all of the databases in a
common location if there are easy ways to determine the following:
* Is there an easy way to map database directories in the file system to
database names? The directories names in /var/lib/pgsql/data/base/ are not
very helpful.
* Is there any command or tool that reports how much space a database is
taking up? Obviously du will work, but it would be nice if there was a
reporting tool that would output the database name instead of the directory
name.
Are there any other options that I'm missing? Any suggestions for a
different approach? Anyone know what other hosting providers are doing?
Thanks!
Tauren
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: Alternate database locations
2001-06-04 09:16 Alternate database locations Tauren Mills <tauren@servlets.net>
@ 2001-06-04 10:11 ` Peter Eisentraut <peter_e@gmx.net>
2001-06-04 14:15 ` Re: Alternate database locations Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 11+ messages in thread
From: Peter Eisentraut @ 2001-06-04 10:11 UTC (permalink / raw)
To: Tauren Mills <tauren@servlets.net>; +Cc: pgsql-admin
Tauren Mills writes:
> I've sent this to both pgsql-general and pgsql-admin. Please advise which
> is the proper list for this type of question.
-admin probably
> There also appears to be a way to create databases with an absolute path,
> but this is turned off by default for security reasons. I haven't tried
> this yet, but it looks like I'd have to recompile with different settings
> for ALLOW_ABSOLUTE_DBPATHS.
> However, this page indicates that there are security risks in doing this.
> What are those risks? If I prevent users other than the superuser
> "postgres" from being able to create and drop databases, are there any
> security risks?
No. The risks are related to the fact that non-superusers can also be
allowed to create databases.
> Lastly, I've even tried creating a database normally, then moving it to the
> user's area and creating a symlink to it. But this didn't seem to work.
It should, since that is what the "official" mechanisms do as well.
> * Is there an easy way to map database directories in the file system to
> database names? The directories names in /var/lib/pgsql/data/base/ are not
> very helpful.
In 7.1 and later, there is one database per directory and the directories
are named $PGDATA/base/<oid>, where <oid> is the oid of the pg_database
entry.
--
Peter Eisentraut peter_e@gmx.net http://funkturm.homeip.net/~peter
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: Alternate database locations
2001-06-04 09:16 Alternate database locations Tauren Mills <tauren@servlets.net>
2001-06-04 10:11 ` Re: Alternate database locations Peter Eisentraut <peter_e@gmx.net>
@ 2001-06-04 14:15 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-06-04 20:27 ` RE: Alternate database locations Tauren Mills <tauren@servlets.net>
0 siblings, 1 reply; 11+ messages in thread
From: Tom Lane @ 2001-06-04 14:15 UTC (permalink / raw)
To: Peter Eisentraut <peter_e@gmx.net>; +Cc: Tauren Mills <tauren@servlets.net>; pgsql-admin
Peter Eisentraut <peter_e@gmx.net> writes:
>> However, this page indicates that there are security risks in doing this.
>> What are those risks? If I prevent users other than the superuser
>> "postgres" from being able to create and drop databases, are there any
>> security risks?
> No. The risks are related to the fact that non-superusers can also be
> allowed to create databases.
If the user's DB area is in his home directory, then he can presumably
rename it, leading to nasty problems when operations like CHECKPOINT try
to write to files in it. At the very least you'd have potential for
denial of service to all the other users.
>> Lastly, I've even tried creating a database normally, then moving it to the
>> user's area and creating a symlink to it. But this didn't seem to work.
> It should, since that is what the "official" mechanisms do as well.
Yes, I'd have thought that would work. Define "didn't seem to work",
please.
regards, tom lane
^ permalink raw reply [nested|flat] 11+ messages in thread
* RE: Alternate database locations
2001-06-04 09:16 Alternate database locations Tauren Mills <tauren@servlets.net>
2001-06-04 10:11 ` Re: Alternate database locations Peter Eisentraut <peter_e@gmx.net>
2001-06-04 14:15 ` Re: Alternate database locations Tom Lane <tgl@sss.pgh.pa.us>
@ 2001-06-04 20:27 ` Tauren Mills <tauren@servlets.net>
2001-06-04 20:35 ` Re: Alternate database locations Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 11+ messages in thread
From: Tauren Mills @ 2001-06-04 20:27 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; Peter Eisentraut <peter_e@gmx.net>; +Cc: pgsql-admin
Thanks for the feedback!
> >> However, this page indicates that there are security risks in
> doing this.
> >> What are those risks? If I prevent users other than the superuser
> >> "postgres" from being able to create and drop databases, are there any
> >> security risks?
>
> > No. The risks are related to the fact that non-superusers can also be
> > allowed to create databases.
>
> If the user's DB area is in his home directory, then he can presumably
> rename it, leading to nasty problems when operations like CHECKPOINT try
> to write to files in it. At the very least you'd have potential for
> denial of service to all the other users.
OK, this makes sense. In the user's home directory, I was going to create a
directory called something like ".db". It would be owned by postgres:root
and have 700 permissions. Within it, would be the "base" directory as
postgres:postgres and 700.
This is very similar to the way that we deploy MySQL. But this does still
allow the user to change the directory name. With MySQL, it would just
cause their database to not work, it wouldn't cause problems with the
server. It sounds like this is not a good idea with PostgreSQL.
Is there any way to keep each customer's database within their user area
without the chance of breaking the database server?
> >> Lastly, I've even tried creating a database normally, then
> moving it to the
> >> user's area and creating a symlink to it. But this didn't
> seem to work.
>
> > It should, since that is what the "official" mechanisms do as well.
>
> Yes, I'd have thought that would work. Define "didn't seem to work",
> please.
Based on what you said, I went back and tried it again. It "seems to work"
correctly now. I think I must not have had the proper permissions set the
first time I tried it.
Even though this is exactly the solution I was looking for, I'm now
reluctant to use it since a user could break things by simply changing a
directory name. I guess I'll have to keep the databases separate from the
user's home area.
Thanks,
Tauren
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: Alternate database locations
2001-06-04 09:16 Alternate database locations Tauren Mills <tauren@servlets.net>
2001-06-04 10:11 ` Re: Alternate database locations Peter Eisentraut <peter_e@gmx.net>
2001-06-04 14:15 ` Re: Alternate database locations Tom Lane <tgl@sss.pgh.pa.us>
2001-06-04 20:27 ` RE: Alternate database locations Tauren Mills <tauren@servlets.net>
@ 2001-06-04 20:35 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 11+ messages in thread
From: Tom Lane @ 2001-06-04 20:35 UTC (permalink / raw)
To: Tauren Mills <tauren@servlets.net>; +Cc: Peter Eisentraut <peter_e@gmx.net>; pgsql-admin
"Tauren Mills" <tauren@servlets.net> writes:
> Is there any way to keep each customer's database within their user area
> without the chance of breaking the database server?
If you want completely decoupled service for each user, then give each
of them their own independent installation, running as their own process.
Anything short of that raises risks of cross-user denial of service.
regards, tom lane
^ permalink raw reply [nested|flat] 11+ messages in thread
* Alternate database locations
@ 2002-04-17 18:49 Charlie Toohey <ctoohey@pacbell.net>
2002-04-18 03:51 ` Re: Alternate database locations Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 11+ messages in thread
From: Charlie Toohey @ 2002-04-17 18:49 UTC (permalink / raw)
To: pgsql-admin
I would like to create multiple databases, each with its own disk location.
I have followed the instructions in the Administrator's Guide and have a
couple of questions.
1. Since the pg_ctl -D option only appears to take a single location, should
this be set to the location of the template1 database created as part of the
Postgres installation, or, do I have to somehow specify the location of each
of my databases in alternate locations when starting Postgres ?
2. As user postgres, I shut down the server, defined the following
environment variable:
PGDATA_ALTERNATE=/home/alternate/pgsql/data
and ran initlocation:
initlocation PGDATA_ALTERNATE
note: /home/alternate/pgsql/data is writeable by postgres
So far so good.
Now, the problem: Per the Administrator's guide, the environment variable
needs to be defined before the backend is started.
I am using the startup script from the contrib/start-scripts/linux directory
of PostgreSQL source (v. 7.1.3), so I define an environment variable within
this file, prior to the command to start the server --- let's say it is
defined as :
PGDATA_ALTERNATE="/home/alternate/pgsql/data"
After starting the server using the script, I switch to user postgres, and I
issue the following command to create a database at the alternate location:
createdb -D 'PGDATA_ALTERNATE'
I get the following error:
ERROR: Postmaster environment variable 'PGDATA_ALTERNATE' not set
createdb: database creation failed
I assumed this environment variable was defined as I put it in the startup
script (just below the line PGDATA="/usr/local/data/pgsql"). Even if I define
the PGDATA_ALTERNATE explicitly in the shell, and then run the createdb
command above, I get the same error.
Any ideas ?
Thanks
Charlie
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: Alternate database locations
2002-04-17 18:49 Alternate database locations Charlie Toohey <ctoohey@pacbell.net>
@ 2002-04-18 03:51 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 11+ messages in thread
From: Tom Lane @ 2002-04-18 03:51 UTC (permalink / raw)
To: Charlie Toohey <ctoohey@pacbell.net>; +Cc: pgsql-admin
Charlie Toohey <ctoohey@pacbell.net> writes:
> 1. Since the pg_ctl -D option only appears to take a single location, should
> this be set to the location of the template1 database created as part of the
> Postgres installation, or, do I have to somehow specify the location of each
> of my databases in alternate locations when starting Postgres ?
-D points at the root of the data directory, a/k/a $PGDATA. This is
where postgresql.conf and some other installation-wide files live.
Individual databases are normally subdirectories under $PGDATA/base/,
but can be relocated elsewhere using the "alternate database location"
mechanism.
> I am using the startup script from the contrib/start-scripts/linux directory
> of PostgreSQL source (v. 7.1.3), so I define an environment variable within
> this file, prior to the command to start the server --- let's say it is
> defined as :
> PGDATA_ALTERNATE="/home/alternate/pgsql/data"
I think you also need "export PGDATA_ALTERNATE"; otherwise it's only a
local variable in that shell script.
regards, tom lane
^ permalink raw reply [nested|flat] 11+ messages in thread
end of thread, other threads:[~2002-04-18 03:51 UTC | newest]
Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-05-31 20:30 Alternate database locations Tauren Mills <tauren@servlets.net>
2001-06-06 01:15 ` Tauren Mills <tauren@servlets.net>
2001-06-06 05:25 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-06-06 05:59 ` Tauren Mills <tauren@servlets.net>
2001-06-04 09:16 Alternate database locations Tauren Mills <tauren@servlets.net>
2001-06-04 10:11 ` Peter Eisentraut <peter_e@gmx.net>
2001-06-04 14:15 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-06-04 20:27 ` Tauren Mills <tauren@servlets.net>
2001-06-04 20:35 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-04-17 18:49 Alternate database locations Charlie Toohey <ctoohey@pacbell.net>
2002-04-18 03:51 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox