Обсуждение: Win32 link() function

Поиск
Список
Период
Сортировка

Win32 link() function

От
Bruce Momjian
Дата:
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@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +


Re: Win32 link() function

От
Tom Lane
Дата:
Bruce Momjian <bruce@momjian.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


Re: Win32 link() function

От
Bruce Momjian
Дата:
Tom Lane wrote:
> Bruce Momjian <bruce@momjian.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_ATTRIBUTESlpSecurityAttributes);
 

--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +


Re: Win32 link() function

От
Itagaki Takahiro
Дата:
Bruce Momjian <bruce@momjian.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




Re: Win32 link() function

От
Tom Lane
Дата:
Bruce Momjian <bruce@momjian.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


Re: Win32 link() function

От
Bruce Momjian
Дата:
Tom Lane wrote:
> Bruce Momjian <bruce@momjian.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.3FFor
thisreason, the PostgreSQL installer package will not initialise adatabase cluster on anything but an NTFS partition.
Theserver andutilities may be installed on any partition type. 
 

> What are the implications for Cygwin?

No idea.

--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +


Re: Win32 link() function

От
Tom Lane
Дата:
Bruce Momjian <bruce@momjian.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


Re: Win32 link() function

От
Bruce Momjian
Дата:
Tom Lane wrote:
> Bruce Momjian <bruce@momjian.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@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +


Re: Win32 link() function

От
Tom Lane
Дата:
Bruce Momjian <bruce@momjian.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


Re: Win32 link() function

От
Bruce Momjian
Дата:
Bruce Momjian wrote:
> Tom Lane wrote:
> > Bruce Momjian <bruce@momjian.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@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +


Re: Win32 link() function

От
Bruce Momjian
Дата:
Tom Lane wrote:
> Bruce Momjian <bruce@momjian.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@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +


Re: Win32 link() function

От
Bruce Momjian
Дата:
Bruce Momjian wrote:
> Tom Lane wrote:
> > Bruce Momjian <bruce@momjian.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@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +


Re: Win32 link() function

От
Bruce Momjian
Дата:
Bruce Momjian wrote:
> Tom Lane wrote:
> > Bruce Momjian <bruce@momjian.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@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +


Re: Win32 link() function

От
Bruce Momjian
Дата:
bruce wrote:
> Tom Lane wrote:
> > Bruce Momjian <bruce@momjian.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 implemented your suggestion:
Stopping postmaster servicing old cluster                   okStarting postmaster to service new cluster  waiting for
postmasterto start                           okStopping postmaster servicing new cluster                   okCould not
createhard link between old and new data directories: Cross-device linkIn link mode the old and new data directories
mustbe on the same filesystem volume.
 

--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +