PostgreSQL Get Started


For Mac users, we have several choices

  • Installer
  • homebrew

The link is here

I tried installer (.app)
Installation is under /Applications
If you want to use psql command, please add PATH to your .bash_profile

# Postgresql
export PATH="/Applications/$PATH"

9.5 is version


To access from command, we can use psql comamnd

psql -h hostanme
psql -h hostname -U username -d databasename

If you skip hostname etc…, just run psql, use current mac username and
access default database



List Database


Check current user


Create database

create database database_name;
create database database_name owner dbower_name;
create database database_name encoding 'UTF8';

Create user

create user user_name;

Connect database

\c databasename;

Configuration file

Dump and Restore

Use pg_dump


pg_dump database_name > database_name.sql

Restore database

psql dbname < database_name.sql

Table backup

pg_dump -d database_name -t table_name > test.sql