create db from a template

From: "Marc Fromm" <Marc(dot)Fromm(at)wwu(dot)edu>
To: <pgsql-admin(at)postgresql(dot)org>
Subject: create db from a template
Date: 2008-03-20 18:41:09
Message-ID: 81FEAB8CDDC62B42B6E8AA258228BC8804E925FF@EVS2.univ.dir.wwu.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Marc Fromm 2008-03-20 19:17:41 exceeds max_fsm_pages
Previous Message Shane Ambler 2008-03-20 18:04:19 Re: Postgres database and firewall