User Tools

Site Tools


Postgres Snippet

I'm a MySQL user so remembering the Postgres stuff is hard ;-)

Enable Network Access

In /etc/postgresql/8.1/main/pg_hba.conf add:

host    all         all        md5

In /etc/postgresql/8.1/main/postgresql.conf add:

listen_addresses = '*'

Then restart postgres.

Create new User and DB

$> sudo -u postgres createuser <user>
$> sudo -u postgres createdb --owner <user> <database>

Add password for user

$> sudo -u postgres psql
ALTER USER <user> WITH PASSWORD '<password>';

Database Backup

Useful to make a fresh database install on another machine.

Do the backup

Create a backup of astj_dev_0 that we will call astj_dev_0.bak

pg_dump -U postgres astj_dev_0 >/tmp/astj_dev_0.bak

Create the database

Create a new database with username and desired encoding. createdb –username=<oneusername> –encoding=latin1 <databasename>

Do the restore

 psql --username=<username> -d <databasename> </tmp/astj_dev_0.bak
postgressnippets.txt · Last modified: 2006/11/13 17:13 by andi