Re: Copying a database. - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Copying a database.
Date
Msg-id 53CC1058.7000801@aklaver.com
Whole thread Raw
In response to Re: Copying a database.  (Steve Atkins <steve@blighty.com>)
List pgsql-general
On 07/20/2014 11:28 AM, Steve Atkins wrote:
>
> On Jul 20, 2014, at 11:09 AM, maillists0@gmail.com wrote:
>
>> I send a nightly dump of my production database to a development server. A script drops the existing development
databaseand replaces it with the current production copy. 
>>
>> Each dev uses her own copy of the database. Is there a way to copy the current development database to a differently
nameddb on the same machine, including the data,  without using the sql dump? 
>
> Look at CREATE DATABASE developer_db WITH TEMPLATE production_copy;

Just be aware of this caveat:

http://www.postgresql.org/docs/9.3/interactive/sql-createdatabase.html

"Although it is possible to copy a database other than template1 by
specifying its name as the template, this is not (yet) intended as a
general-purpose "COPY DATABASE" facility. The principal limitation is
that no other sessions can be connected to the template database while
it is being copied. CREATE DATABASE will fail if any other connection
exists when it starts; otherwise, new connections to the template
database are locked out until CREATE DATABASE completes. See Section
21.3 for more information."

>
> createdb with the --template option is a convenient way to do that from the commandline.
>
> Cheers,
>    Steve
>
>
>


--
Adrian Klaver
adrian.klaver@aklaver.com


pgsql-general by date:

Previous
From: Steve Atkins
Date:
Subject: Re: Copying a database.
Next
From: Torsten Förtsch
Date:
Subject: Re: check database integrity