pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Shane Ambler <pgsql@Sheeky.Biz>
To: Marc Fromm <Marc.Fromm@wwu.edu>
Cc: pgsql-admin@postgresql.org
Subject: Re: create db from a template
Date: Fri, 21 Mar 2008 11:15:40 +1030
Message-ID: <47E30534.20702@Sheeky.Biz> (raw)
In-Reply-To: <81FEAB8CDDC62B42B6E8AA258228BC8804E925FF@EVS2.univ.dir.wwu.edu>
References: <81FEAB8CDDC62B42B6E8AA258228BC8804E925FF@EVS2.univ.dir.wwu.edu>

Marc Fromm wrote:
> Is there a better way to create a database from the schema of another
> database, to have a copy of a database without the data?
> 
> 1.) I get the schema from a database
> pg_dump -s -U postgres -O databasename > /tmp/template_name
> 
> 2.) I create a new database.
> createdb -U postgres newdb
> 
> 3.) I restore the schema to the newdb.
> psql -U postgres newdb < /tmp/template_name
> 
> 4.) I create a database, using the newdb as a TEMPLATE  
> CREATE DATABASE databasename2 TEMPLATE newdb;
> 
> 
> Marc
> 
> 

You only need those 4 steps once to start with then each new one will 
just use step 4.

So you can either setup the database as you have done and use it as the 
template for all the similar db's you want which means each new one will 
only need step 4.

The other way is do 4 without using the TEMPLATE and then adjust 3 to 
import the schema dump into the db just created (databasename2 in this case)



-- 

Shane Ambler
pgSQL (at) Sheeky (dot) Biz

Get Sheeky @ http://Sheeky.Biz



view thread (2+ messages)

Message-ID: <47E30534.20702@Sheeky.Biz>
Permalink:  ../47E30534.20702@Sheeky.Biz/
Also on:    postgresql.org/message-id/47E30534.20702@Sheeky.Biz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: pgsql@Sheeky.Biz, Marc.Fromm@wwu.edu
  Subject: Re: create db from a template
  In-Reply-To: <47E30534.20702@Sheeky.Biz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox