Re: Use of 'cp -r' in CREATE DATABASE - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: Use of 'cp -r' in CREATE DATABASE
Date
Msg-id 3FEF8CF4.2030801@dunslane.net
Whole thread Raw
In response to Re: Use of 'cp -r' in CREATE DATABASE  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Use of 'cp -r' in CREATE DATABASE  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers

Tom Lane wrote:

>A final point is that implementing CREATE DATABASE via "cp -r" is and
>always has been fundamentally broken anyway, because of the lack of
>interlocking against other backends changing the source database.
>We have a very half-baked defense against that (erroring out if anyone
>else is connected to the source DB at the start of the copy) which
>I would dearly love to get rid of.  
>

It struck me this morning that we could strengthen that defense 
considerable with the addition of some checks after the copy on the 
mtimes of the copied files. The additional code could be quite small and 
fast.

Longer term, a robust mechanism for DB level locks would probably be 
preferable, I guess, so I'm not sure if my idea is worth doing in the 
mean time. Presumably it hasn't caused much of a problem up to now, 
since most people are not likely to monkey with their template dbs at 
the same time as trying to create dbs based on them.

cheers

andrew



pgsql-hackers by date:

Previous
From: Christopher Kings-Lynne
Date:
Subject: Re: select from table with unique values
Next
From: Tom Lane
Date:
Subject: Re: Use of 'cp -r' in CREATE DATABASE