Skip to content

Instantly share code, notes, and snippets.

@thefonso
Created July 2, 2019 05:06
Show Gist options
  • Save thefonso/c26b49d2d8542267a8dc8d5f17733ea8 to your computer and use it in GitHub Desktop.
Save thefonso/c26b49d2d8542267a8dc8d5f17733ea8 to your computer and use it in GitHub Desktop.
Getting Started with PostgreSQL on Mac OS X

PostgreSQL on Mac OS X

Install, and verify the installation.

$ brew install postgresql
$ postgres —help
postgres is the PostgreSQL server.
...
$ psql --help
psql is the PostgreSQL interactive terminal.
...

Start server instance

$ postgres -D /usr/local/var/postgres

In a separate terminal, create a DB with the same name as the current UNIX user. This makes it easier to access the server with the psql command.

createdb `whoami`

Connect via the CLI

$ psql

Appendix: Adding additional users

Create a database user named fsuser with a password fspass.

$ createuser fsuser --createdb --password
Password: fspass

Then create a database named fsbook with the newly created user.

$ createdb --username=fsuser --password fsbook
Password: fspass

Connect.

$ psql --username=fsuser --password fsbook

Appendix: Versions used when creating this document

$ postgres --version
postgres (PostgreSQL) 9.4.0
$ sw_vers -productVersion # Mac OS X
10.9.5

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment