pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
create db from a template
2+ messages / 2 participants
[nested] [flat]

* create db from a template
@ 2008-03-20 18:41 Marc Fromm <Marc.Fromm@wwu.edu>
  2008-03-21 00:45 ` Re: create db from a template Shane Ambler <pgsql@Sheeky.Biz>
  0 siblings, 1 reply; 2+ messages in thread

From: Marc Fromm @ 2008-03-20 18:41 UTC (permalink / raw)
  To: pgsql-admin

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




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: create db from a template
  2008-03-20 18:41 create db from a template Marc Fromm <Marc.Fromm@wwu.edu>
@ 2008-03-21 00:45 ` Shane Ambler <pgsql@Sheeky.Biz>
  0 siblings, 0 replies; 2+ messages in thread

From: Shane Ambler @ 2008-03-21 00:45 UTC (permalink / raw)
  To: Marc Fromm <Marc.Fromm@wwu.edu>; +Cc: pgsql-admin

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2008-03-21 00:45 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-03-20 18:41 create db from a template Marc Fromm <Marc.Fromm@wwu.edu>
2008-03-21 00:45 ` Shane Ambler <pgsql@Sheeky.Biz>

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