Code Snippet

Just another Code Snippet site

[PostgreSQL] How To

Enable access from remote host :
vi /var/lib/pgsql/data/pg_hba.conf

# "local" is for Unix domain socket connections only
host    all             all             0.0.0.0/0               md5
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 ident

vi /var/lib/pgsql/data/postgresql.conf

listen_addresses = '*'

Change port (default = 5432) :
vi /var/lib/pgsql/data/postgresql.conf

port = 5432 

Stop / Start / Restart :

service postgresql start
service postgresql stop
service postgresql restart

Create user :

createuser USERNAME --pwprompt
Enter password for new role: <enter password>
Enter it again: <enter password>
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n

Create database:

createdb -O rails DATABASE_NAME

or 

psql postgres USERNAME
postgres => CREATE DATABASE DATABASE_NAME;
CREATE DATABASE


Leave a Reply

Your email address will not be published. Required fields are marked *