Thursday, November 22, 2012

Starting Postgress SQL


Install It
apt-get install postgresql-9.1

Create a user
sudo -u postgres createuser -d -R -P

Give a password for the user.
sudo -su postgres

postgres$  psql -U postgres

ALTER USER postgres with password 'secure-password';

now you can directly connect from Super User like this
psql -U postgres -h localhost


Create a database

createdb mydb


Export from one db to another
pg_dump -C -h localhost -U localuser dbname | psql -h remotehost -U remoteuser 
Take a dump
pg_dump -c -U postgres ${fromDataBase} -f ABIMS9JAN13tabledump.sql -h ${fromHost}
Execute the dump
psql -d ${toDataBase} -f dumpfilename.sql -h ${toHost} -U postgres -w password




Install GUI
sudo apt-get install pgadmin3

pgadmin3

pg_dump --username "postgres" -Fc origin > origin.dump


pg_restore --username "postgres" -d target origin.dump

No comments:

Post a Comment