Re: Win32 link() function

Lists: pgsql-hackers
From: Bruce Momjian <bruce(at)momjian(dot)us>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Win32 link() function
Date: 2009-06-01 02:53:59
Message-ID: 200906010253.n512rxV14069@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

pg_migrator needs hard link() capabiity on Win32 to support its --link
option. Can someone create that and hopefully add it to libpgport?
libpgport currently only has symlink capability for Win32.

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

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Win32 link() function
Date: 2009-06-01 03:08:19
Message-ID: 26904.1243825699@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> pg_migrator needs hard link() capabiity on Win32 to support its --link
> option. Can someone create that and hopefully add it to libpgport?

AFAIK hard links simply don't exist on Windows.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Win32 link() function
Date: 2009-06-01 03:14:23
Message-ID: 200906010314.n513ENx16639@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > pg_migrator needs hard link() capabiity on Win32 to support its --link
> > option. Can someone create that and hopefully add it to libpgport?
>
> AFAIK hard links simply don't exist on Windows.

Magnus showed me this:

http://msdn.microsoft.com/en-us/library/aa363860(VS.85).aspx

BOOL WINAPI CreateHardLink(
__in LPCTSTR lpFileName,
__in LPCTSTR lpExistingFileName,
__reserved LPSECURITY_ATTRIBUTES lpSecurityAttributes
);

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

+ If your life is a hard drive, Christ can be your backup. +


From: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: Win32 link() function
Date: 2009-06-01 03:15:31
Message-ID: 20090601121346.79E7.52131E4D@oss.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Bruce Momjian <bruce(at)momjian(dot)us> wrote:

> pg_migrator needs hard link() capabiity on Win32 to support its --link
> option. Can someone create that and hopefully add it to libpgport?
> libpgport currently only has symlink capability for Win32.

Can we use CreateHardLink() ?
http://msdn.microsoft.com/en-us/library/aa363860.aspx

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Win32 link() function
Date: 2009-06-01 03:37:36
Message-ID: 27436.1243827456@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> Tom Lane wrote:
>> AFAIK hard links simply don't exist on Windows.

> Magnus showed me this:
> http://msdn.microsoft.com/en-us/library/aa363860(VS.85).aspx

Hmm, interesting. Are we requiring our DBs to be on NTFS already?
What are the implications for Cygwin?

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Win32 link() function
Date: 2009-06-01 03:43:05
Message-ID: 200906010343.n513h5L19898@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Tom Lane wrote:
> >> AFAIK hard links simply don't exist on Windows.
>
> > Magnus showed me this:
> > http://msdn.microsoft.com/en-us/library/aa363860(VS.85).aspx
>
> Hmm, interesting. Are we requiring our DBs to be on NTFS already?

I think we require NTFS with the installers but you can install the
source on anything:

http://wiki.postgresql.org/wiki/Running_%26_Installing_PostgreSQL_On_Native_Windows#Can_I_install_PostgreSQL_on_a_FAT_partition.3F

For this reason, the PostgreSQL installer package will not initialise a
database cluster on anything but an NTFS partition. The server and
utilities may be installed on any partition type.

> What are the implications for Cygwin?

No idea.

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

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Win32 link() function
Date: 2009-06-01 03:49:51
Message-ID: 200906010349.n513np120636@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian wrote:
> Tom Lane wrote:
> > Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > > Tom Lane wrote:
> > >> AFAIK hard links simply don't exist on Windows.
> >
> > > Magnus showed me this:
> > > http://msdn.microsoft.com/en-us/library/aa363860(VS.85).aspx
> >
> > Hmm, interesting. Are we requiring our DBs to be on NTFS already?
>
> I think we require NTFS with the installers but you can install the
> source on anything:
>
> http://wiki.postgresql.org/wiki/Running_%26_Installing_PostgreSQL_On_Native_Windows#Can_I_install_PostgreSQL_on_a_FAT_partition.3F
>
> For this reason, the PostgreSQL installer package will not initialise a
> database cluster on anything but an NTFS partition. The server and
> utilities may be installed on any partition type.

Oh, yea, we only support tablespaces on Win32 using NTFS.

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

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Win32 link() function
Date: 2009-06-01 03:53:36
Message-ID: 27751.1243828416@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
>> Tom Lane wrote:
>>> Hmm, interesting. Are we requiring our DBs to be on NTFS already?

> Oh, yea, we only support tablespaces on Win32 using NTFS.

Well, the important point there is that we fail gracefully if you try to
use tablespaces when not on NTFS. So you're going to have to make sure
that pg_migrator's --link option fails gracefully when not on NTFS.

(Come to think of it, --link can fail on Unix too, if the user tries to
put the new database on a different filesystem. Have you got guards in
there to make sure this is discovered before the point of no return?)

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Win32 link() function
Date: 2009-06-01 03:57:08
Message-ID: 200906010357.n513v8321575@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> >> Tom Lane wrote:
> >>> Hmm, interesting. Are we requiring our DBs to be on NTFS already?
>
> > Oh, yea, we only support tablespaces on Win32 using NTFS.
>
> Well, the important point there is that we fail gracefully if you try to
> use tablespaces when not on NTFS. So you're going to have to make sure
> that pg_migrator's --link option fails gracefully when not on NTFS.

I will just check the return code and exit on error.

> (Come to think of it, --link can fail on Unix too, if the user tries to
> put the new database on a different filesystem. Have you got guards in
> there to make sure this is discovered before the point of no return?)

Of course:

if ((msg = linkAndUpdateFile(ctx, pageConverter, oldfile, newfile)) != NULL)
pg_log(ctx, PG_FATAL,
"error while creating link from %s.%s(%s) to %s.%s(%s): %s\n",
oldnspname, oldrelname, oldfile, newnspname, newrelname,
newfile, msg);

...
if (pg_link_file(src, dst) == -1)
return strerror(errno);

though you have to delete the new cluster directory and remove the _old
suffixes to get your old cluster back. I don't check before starting
the migration.

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

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Win32 link() function
Date: 2009-06-01 04:02:47
Message-ID: 27945.1243828967@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> Tom Lane wrote:
>> (Come to think of it, --link can fail on Unix too, if the user tries to
>> put the new database on a different filesystem. Have you got guards in
>> there to make sure this is discovered before the point of no return?)

> Of course:
> ...
> though you have to delete the new cluster directory and remove the _old
> suffixes to get your old cluster back.

That wasn't what I had in mind by "before the point of no return".
You should be making some effort to detect obvious failure cases
*before* the user has to do a lot of error-prone manual cleanup.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Win32 link() function
Date: 2009-06-01 04:09:42
Message-ID: 200906010409.n5149gZ23701@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Tom Lane wrote:
> >> (Come to think of it, --link can fail on Unix too, if the user tries to
> >> put the new database on a different filesystem. Have you got guards in
> >> there to make sure this is discovered before the point of no return?)
>
> > Of course:
> > ...
> > though you have to delete the new cluster directory and remove the _old
> > suffixes to get your old cluster back.
>
> That wasn't what I had in mind by "before the point of no return".
> You should be making some effort to detect obvious failure cases
> *before* the user has to do a lot of error-prone manual cleanup.

That is something I will address during beta as I get problem reports.

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

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Win32 link() function
Date: 2009-06-01 04:14:50
Message-ID: 200906010414.n514Eor24135@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian wrote:
> Tom Lane wrote:
> > Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > > Tom Lane wrote:
> > >> (Come to think of it, --link can fail on Unix too, if the user tries to
> > >> put the new database on a different filesystem. Have you got guards in
> > >> there to make sure this is discovered before the point of no return?)
> >
> > > Of course:
> > > ...
> > > though you have to delete the new cluster directory and remove the _old
> > > suffixes to get your old cluster back.
> >
> > That wasn't what I had in mind by "before the point of no return".
> > You should be making some effort to detect obvious failure cases
> > *before* the user has to do a lot of error-prone manual cleanup.
>
> That is something I will address during beta as I get problem reports.

I have added that as a TODO.

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

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Win32 link() function
Date: 2009-06-01 14:34:48
Message-ID: 200906011434.n51EYmf02870@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian wrote:
> Tom Lane wrote:
> > Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > > pg_migrator needs hard link() capabiity on Win32 to support its --link
> > > option. Can someone create that and hopefully add it to libpgport?
> >
> > AFAIK hard links simply don't exist on Windows.
>
> Magnus showed me this:
>
> http://msdn.microsoft.com/en-us/library/aa363860(VS.85).aspx
>
> BOOL WINAPI CreateHardLink(
> __in LPCTSTR lpFileName,
> __in LPCTSTR lpExistingFileName,
> __reserved LPSECURITY_ATTRIBUTES lpSecurityAttributes
> );

Hiroshi Saito emailed me some sample link code I was able to use for
Win32 hard links and I have committed that to pg_migrator CVS.

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

+ If your life is a hard drive, Christ can be your backup. +