Skip to content

Instantly share code, notes, and snippets.

@sroysf
Created October 12, 2011 06:04
Show Gist options
  • Save sroysf/1280410 to your computer and use it in GitHub Desktop.
Save sroysf/1280410 to your computer and use it in GitHub Desktop.
Creating and configuring a new postgres database for an app

Search and replace

Replace DB_USER
Replace DB_NAME
Replace DB_PASS
Replace PROJ_NAME

Create and setup the database

sudo adduser DB_USER
su postgres
psql template1
create database DB_NAME;
CREATE USER DB_USER WITH PASSWORD 'DB_PASS';
GRANT ALL PRIVILEGES ON DATABASE DB_NAME to DB_USER;
\q

Generate schema file from Hibernate

mvn clean install
mvn hibernate3:hbm2ddl

Create the schema from hibernate generated DDL file

su DB_USER
psql -d ckarchive
\i /home/sroy/dev/git/PROJ_NAME/target/hibernate3/sql/schema.ddl

Resulting DATABASE URL

postgres://DB_USER:DB_PASS@localhost/DB_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment