Contents

Install PostgreSQL on OSX using brew

Contents
  • Install PostgreSQL using brew If you don’t have homebrew, install it first. Then simply run the command:
1
brew install postgres
  • Initialize PostgreSQL
1
initdb ~/pg-data
  • Start PostgreSQL service
1
postgres -D ~/pg-data
  • Create a user
1
2
# If you wish to create a user without a password just take the --pwprompt off the command.
createuser --pwprompt username
  • Create a database
1
2
# The -O indicates the user that will become the owner of the database.
createdb -Ousername -Eutf8 dev-db
  • Access the Database
1
2
# The -U means to login using that username and the -W means to prompt for a password.
psql -U username -W dev-db
  • Remote Connection to PostgreSQL Database using psql
1
2
# edit pg_hba.conf at pg-data
host    all         all         192.168.1.10/24    trust

This will allow connection from 192.168.1.10 ip-address. If you want to allow connection from multiple client machines on a specific network, specify the network address here in the CIDR-address format.