Re: Tablespaces in the data directory

Lists: pgsql-hackers
From: Magnus Hagander <magnus(at)hagander(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Tablespaces in the data directory
Date: 2012-12-01 13:45:20
Message-ID: CABUevEwr4RqDk-Ha0nRwMmLX0BosmB593bkw+SsWagepvP4oFw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Someone just reported a problem when they had created a new tablespace
inside the old data directory. I'm sure there can be other issues
caused by this as well, but this is mainly a confusing scenario for
people now.

As there isn't (as far as I know at least) any actual *point* in
creating a tablespace inside the main data directory, should we
perhaps disallow this in CREATE TABLESPACE? Or at least throw a
WARNING if one does it?

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Tablespaces in the data directory
Date: 2012-12-01 13:50:29
Message-ID: CA+U5nML0pmFD9QOi5VUE8J7KBQ3fNcsa_QsKxO8ydXPxPe2jVQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 1 December 2012 13:45, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
> Someone just reported a problem when they had created a new tablespace
> inside the old data directory. I'm sure there can be other issues
> caused by this as well, but this is mainly a confusing scenario for
> people now.
>
> As there isn't (as far as I know at least) any actual *point* in
> creating a tablespace inside the main data directory, should we
> perhaps disallow this in CREATE TABLESPACE? Or at least throw a
> WARNING if one does it?

+1

--
Simon Riggs http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Tablespaces in the data directory
Date: 2012-12-01 17:56:17
Message-ID: 17365.1354384577@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Magnus Hagander <magnus(at)hagander(dot)net> writes:
> Someone just reported a problem when they had created a new tablespace
> inside the old data directory. I'm sure there can be other issues
> caused by this as well, but this is mainly a confusing scenario for
> people now.

> As there isn't (as far as I know at least) any actual *point* in
> creating a tablespace inside the main data directory, should we
> perhaps disallow this in CREATE TABLESPACE? Or at least throw a
> WARNING if one does it?

It could be pretty hard to detect that in general (think symlinks
and such). I guess if we're just trying to print a helpful warning,
we don't have to worry about extreme corner cases. But what exactly
do you have in mind --- complain about any relative path? Complain
about absolute paths that have a prefix matching the DataDir?

regards, tom lane


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Tablespaces in the data directory
Date: 2012-12-03 00:50:11
Message-ID: CABUevEwDeuJ8vadDegcRyR2A-skcZM7WVzz01EP1wPUMg7Pomg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Dec 1, 2012 at 6:56 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Magnus Hagander <magnus(at)hagander(dot)net> writes:
>> Someone just reported a problem when they had created a new tablespace
>> inside the old data directory. I'm sure there can be other issues
>> caused by this as well, but this is mainly a confusing scenario for
>> people now.
>
>> As there isn't (as far as I know at least) any actual *point* in
>> creating a tablespace inside the main data directory, should we
>> perhaps disallow this in CREATE TABLESPACE? Or at least throw a
>> WARNING if one does it?
>
> It could be pretty hard to detect that in general (think symlinks
> and such). I guess if we're just trying to print a helpful warning,
> we don't have to worry about extreme corner cases. But what exactly
> do you have in mind --- complain about any relative path? Complain
> about absolute paths that have a prefix matching the DataDir?

Oh, I hadn't thought quite so far as the implementation :) Was looking
to see if there were going to be some major objections before I even
started thinking about that.

But for the implementation, I'd say any absolute path that have a
prefix matching DataDir. Tablespaces cannot be created using relative
paths, so we don't have to deal with that.

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Tablespaces in the data directory
Date: 2012-12-03 01:55:28
Message-ID: 50BC0690.80600@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On 12/02/2012 07:50 PM, Magnus Hagander wrote:
> On Sat, Dec 1, 2012 at 6:56 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Magnus Hagander <magnus(at)hagander(dot)net> writes:
>>> Someone just reported a problem when they had created a new tablespace
>>> inside the old data directory. I'm sure there can be other issues
>>> caused by this as well, but this is mainly a confusing scenario for
>>> people now.
>>> As there isn't (as far as I know at least) any actual *point* in
>>> creating a tablespace inside the main data directory, should we
>>> perhaps disallow this in CREATE TABLESPACE? Or at least throw a
>>> WARNING if one does it?
>> It could be pretty hard to detect that in general (think symlinks
>> and such). I guess if we're just trying to print a helpful warning,
>> we don't have to worry about extreme corner cases. But what exactly
>> do you have in mind --- complain about any relative path? Complain
>> about absolute paths that have a prefix matching the DataDir?
> Oh, I hadn't thought quite so far as the implementation :) Was looking
> to see if there were going to be some major objections before I even
> started thinking about that.
>
> But for the implementation, I'd say any absolute path that have a
> prefix matching DataDir. Tablespaces cannot be created using relative
> paths, so we don't have to deal with that.
>

I have been known to symlink a tablespace on a replica back to a
directory in the datadir, while on the primary it points elsewhere. What
exactly is the problem?

cheers

andrew


From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Tablespaces in the data directory
Date: 2012-12-03 02:38:20
Message-ID: b66bcb021528daf01b3f25453ac8f12d@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

> As there isn't (as far as I know at least) any actual *point* in
> creating a tablespace inside the main data directory, should we
> perhaps disallow this in CREATE TABLESPACE? Or at least throw a
> WARNING if one does it?

Sure there is a point - emulating some other system. Could be
replication, QA box, disaster recovery, etc. I'd be
cool with a warning, but do not think we should disallow it.

- --
Greg Sabino Mullane greg(at)turnstep(dot)com
End Point Corporation http://www.endpoint.com/
PGP Key: 0x14964AC8 201212022133
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iEYEAREDAAYFAlC8D7kACgkQvJuQZxSWSsj+5gCgsmi6NXue+Hp0gycVOL/JEGUT
anYAoIqwo24JeLfliRHLvwPbdK4F4TXa
=EwgC
-----END PGP SIGNATURE-----


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Tablespaces in the data directory
Date: 2012-12-03 17:33:21
Message-ID: CABUevExkhE+KcQa+fLUeaizP5i5QVCnNjZ2j0ZZQcaMJFheQDw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Dec 3, 2012 2:55 AM, "Andrew Dunstan" <andrew(at)dunslane(dot)net> wrote:
>
>
> On 12/02/2012 07:50 PM, Magnus Hagander wrote:
>>
>> On Sat, Dec 1, 2012 at 6:56 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>>
>>> Magnus Hagander <magnus(at)hagander(dot)net> writes:
>>>>
>>>> Someone just reported a problem when they had created a new tablespace
>>>> inside the old data directory. I'm sure there can be other issues
>>>> caused by this as well, but this is mainly a confusing scenario for
>>>> people now.
>>>> As there isn't (as far as I know at least) any actual *point* in
>>>> creating a tablespace inside the main data directory, should we
>>>> perhaps disallow this in CREATE TABLESPACE? Or at least throw a
>>>> WARNING if one does it?
>>>
>>> It could be pretty hard to detect that in general (think symlinks
>>> and such). I guess if we're just trying to print a helpful warning,
>>> we don't have to worry about extreme corner cases. But what exactly
>>> do you have in mind --- complain about any relative path? Complain
>>> about absolute paths that have a prefix matching the DataDir?
>>
>> Oh, I hadn't thought quite so far as the implementation :) Was looking
>> to see if there were going to be some major objections before I even
>> started thinking about that.
>>
>> But for the implementation, I'd say any absolute path that have a
>> prefix matching DataDir. Tablespaces cannot be created using relative
>> paths, so we don't have to deal with that.
>>
>
> I have been known to symlink a tablespace on a replica back to a
directory in the datadir, while on the primary it points elsewhere. What
exactly is the problem?

That wouldn't be affected by this though, since it would only warn at
create tablespace.

I'd still consider it a bad idea in general to do that, since you're
basically messing with the internal structure of the data directory. Why
not just link it to some place outside the data directory?

One obvious problem with it atm is that pg_basebackup breaks, in that it
backs up your data twice, and throws warnings about things that aren't
links if you actually out it inside pg_tblspc.

/Magnus


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Tablespaces in the data directory
Date: 2012-12-03 18:14:30
Message-ID: 50BCEC06.8060501@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On 12/03/2012 12:33 PM, Magnus Hagander wrote:
>
>
> On Dec 3, 2012 2:55 AM, "Andrew Dunstan" <andrew(at)dunslane(dot)net
> <mailto:andrew(at)dunslane(dot)net>> wrote:
> >
> >
> > On 12/02/2012 07:50 PM, Magnus Hagander wrote:
> >>
> >> On Sat, Dec 1, 2012 at 6:56 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us
> <mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us>> wrote:
> >>>
> >>> Magnus Hagander <magnus(at)hagander(dot)net <mailto:magnus(at)hagander(dot)net>>
> writes:
> >>>>
> >>>> Someone just reported a problem when they had created a new
> tablespace
> >>>> inside the old data directory. I'm sure there can be other issues
> >>>> caused by this as well, but this is mainly a confusing scenario for
> >>>> people now.
> >>>> As there isn't (as far as I know at least) any actual *point* in
> >>>> creating a tablespace inside the main data directory, should we
> >>>> perhaps disallow this in CREATE TABLESPACE? Or at least throw a
> >>>> WARNING if one does it?
> >>>
> >>> It could be pretty hard to detect that in general (think symlinks
> >>> and such). I guess if we're just trying to print a helpful warning,
> >>> we don't have to worry about extreme corner cases. But what exactly
> >>> do you have in mind --- complain about any relative path? Complain
> >>> about absolute paths that have a prefix matching the DataDir?
> >>
> >> Oh, I hadn't thought quite so far as the implementation :) Was looking
> >> to see if there were going to be some major objections before I even
> >> started thinking about that.
> >>
> >> But for the implementation, I'd say any absolute path that have a
> >> prefix matching DataDir. Tablespaces cannot be created using relative
> >> paths, so we don't have to deal with that.
> >>
> >
> > I have been known to symlink a tablespace on a replica back to a
> directory in the datadir, while on the primary it points elsewhere.
> What exactly is the problem?
>
> That wouldn't be affected by this though, since it would only warn at
> create tablespace.
>
> I'd still consider it a bad idea in general to do that, since you're
> basically messing with the internal structure of the data directory.
> Why not just link it to some place outside the data directory?
>
> One obvious problem with it atm is that pg_basebackup breaks, in that
> it backs up your data twice, and throws warnings about things that
> aren't links if you actually out it inside pg_tblspc.
>
>

Well, when I last did it I don't think there was such a thing as
pg_basebackup :-)

I think it would be reasonable for it to complain if it came across a
PG_VERSION file in an unexpected location.

cheers

andrew


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Greg Sabino Mullane <greg(at)turnstep(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Tablespaces in the data directory
Date: 2012-12-04 03:06:11
Message-ID: 20121204030611.GD7675@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Dec 3, 2012 at 02:38:20AM -0000, Greg Sabino Mullane wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: RIPEMD160
>
>
> > As there isn't (as far as I know at least) any actual *point* in
> > creating a tablespace inside the main data directory, should we
> > perhaps disallow this in CREATE TABLESPACE? Or at least throw a
> > WARNING if one does it?
>
> Sure there is a point - emulating some other system. Could be
> replication, QA box, disaster recovery, etc. I'd be
> cool with a warning, but do not think we should disallow it.

FYI, someone put their new cluster inside an existing old tablespace,
and when they ran the script to delete their old install, their new
install was deleted too. My answer was, "Don't do that".

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Tablespaces in the data directory
Date: 2012-12-04 03:41:58
Message-ID: 6FCE516D-3D80-4924-9E3C-9617ED05793F@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On Dec 3, 2012, at 12:33, Magnus Hagander wrote:

> On Dec 3, 2012 2:55 AM, "Andrew Dunstan" <andrew(at)dunslane(dot)net> wrote:
>>
>>
>> On 12/02/2012 07:50 PM, Magnus Hagander wrote:
>>>
>>> On Sat, Dec 1, 2012 at 6:56 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>>>
>>>> Magnus Hagander <magnus(at)hagander(dot)net> writes:
>>>>>
>>>>> Someone just reported a problem when they had created a new tablespace
>>>>> inside the old data directory. I'm sure there can be other issues
>>>>> caused by this as well, but this is mainly a confusing scenario for
>>>>> people now.
>>>>> As there isn't (as far as I know at least) any actual *point* in
>>>>> creating a tablespace inside the main data directory, should we
>>>>> perhaps disallow this in CREATE TABLESPACE? Or at least throw a
>>>>> WARNING if one does it?
>>>>
>>>> It could be pretty hard to detect that in general (think symlinks
>>>> and such). I guess if we're just trying to print a helpful warning,
>>>> we don't have to worry about extreme corner cases. But what exactly
>>>> do you have in mind --- complain about any relative path? Complain
>>>> about absolute paths that have a prefix matching the DataDir?
>>>
>>> Oh, I hadn't thought quite so far as the implementation :) Was looking
>>> to see if there were going to be some major objections before I even
>>> started thinking about that.
>>>
>>> But for the implementation, I'd say any absolute path that have a
>>> prefix matching DataDir. Tablespaces cannot be created using relative
>>> paths, so we don't have to deal with that.
>>>
>>
>> I have been known to symlink a tablespace on a replica back to a
> directory in the datadir, while on the primary it points elsewhere. What
> exactly is the problem?
>
> That wouldn't be affected by this though, since it would only warn at
> create tablespace.
>
> I'd still consider it a bad idea in general to do that, since you're
> basically messing with the internal structure of the data directory. Why
> not just link it to some place outside the data directory?

One reason is that subsequent copies of the data directory then also includes the tablespace data. Saves one step when setting up a standby.

Michael Glaesemann
grzm seespotcode net


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Greg Sabino Mullane <greg(at)turnstep(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Tablespaces in the data directory
Date: 2012-12-04 14:37:46
Message-ID: CA+TgmoamejRYkWUH_CbVqerAK9iFQLZ9o+16E2Pw_39Uja=HgQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Dec 3, 2012 at 10:06 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> FYI, someone put their new cluster inside an existing old tablespace,
> and when they ran the script to delete their old install, their new
> install was deleted too. My answer was, "Don't do that".

Uh, wow. I feel bad for that person, but it does seem like a bit of a
self-inflicted injury.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Greg Sabino Mullane <greg(at)turnstep(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Tablespaces in the data directory
Date: 2012-12-04 14:54:43
Message-ID: 20121204145443.GF30893@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 4, 2012 at 09:37:46AM -0500, Robert Haas wrote:
> On Mon, Dec 3, 2012 at 10:06 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> > FYI, someone put their new cluster inside an existing old tablespace,
> > and when they ran the script to delete their old install, their new
> > install was deleted too. My answer was, "Don't do that".
>
> Uh, wow. I feel bad for that person, but it does seem like a bit of a
> self-inflicted injury.

They wanted pg_upgrade to guard against it, and I said that was
possible, but it would require pg_upgrade to know which files to remove,
and that would make pg_upgrade more fragile.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Andreas Karlsson <andreas(at)proxel(dot)se>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Tablespaces in the data directory
Date: 2012-12-04 21:47:08
Message-ID: 50BE6F5C.3090003@proxel.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2012-12-01 14:45, Magnus Hagander wrote:
> Someone just reported a problem when they had created a new tablespace
> inside the old data directory. I'm sure there can be other issues
> caused by this as well, but this is mainly a confusing scenario for
> people now.
>
> As there isn't (as far as I know at least) any actual *point* in
> creating a tablespace inside the main data directory, should we
> perhaps disallow this in CREATE TABLESPACE? Or at least throw a
> WARNING if one does it?

Does this apply when creating a tablespace in another tablespace too? If
the problem is that pg_basebackup copies that data twice it sounds like
it should.

--
Andreas Karlsson


From: Noah Misch <noah(at)leadboat(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Tablespaces in the data directory
Date: 2012-12-05 01:04:42
Message-ID: 20121205010442.GA16472@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Dec 03, 2012 at 01:14:30PM -0500, Andrew Dunstan wrote:
> I think it would be reasonable for it to complain if it came across a
> PG_VERSION file in an unexpected location.

That sounds like a reliable approach to detecting the hazard. Pseudocode:

chdir(proposed_tablespace_path)
do {
if (stat("PG_VERSION"))
ereport(WARNING, ...)
} while (chdir(".."))