Unix Technical Forum

Re: create db from a template

This is a discussion on Re: create db from a template within the pgsql Admins forums, part of the PostgreSQL category; --> Marc Fromm wrote: > Is there a better way to create a database from the schema of another > ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Admins

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 09:19 AM
Shane Ambler
 
Posts: n/a
Default Re: create db from a template

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

--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:10 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com