Skip to content

Instantly share code, notes, and snippets.

@EhsanZ
Forked from ibraheem4/postgres-brew.md
Last active October 25, 2019 18:46
Show Gist options
  • Save EhsanZ/ebe63d54b8a44d75c89ae84942fc0f0f to your computer and use it in GitHub Desktop.
Save EhsanZ/ebe63d54b8a44d75c89ae84942fc0f0f to your computer and use it in GitHub Desktop.
Installing Postgres via Brew (OSX)

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update

Installing

  1. In your command-line run the command: brew install postgresql

  2. Run the command: ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

  3. Create two new aliases to start and stop your postgres server. They could look something like this:

    alias pg_start="brew services start postgres"
    alias pg_stop="brew services stop postgres"
    
  4. Run the alias you just created: pg_start. Use this comment to start your database service.

    • alternatively, pg_stop stops your database service.
  5. Run the command: createdb `ehsan`

  6. Run the command createuser -s postgres

  7. Test with psql command

    $ psql
    psql (10.0)
    Type "help" for help.
    
    ehsan=# 
    

Details

What is this ln command I ran in my Terminal?

from the man ln command

The ln utility creates a new directory entry (linked file) which has the same modes as the original file. It is useful for maintaining multiple copies of a file in many places at once without using up storage for the copies''; instead, a link points'' to the original copy. There are two types of links; hard links and symbolic links. How a link ``points'' to a file is one of the differences between a hard and symbolic link.

Commands

Create database

createdb <database_name>

List databases

psql -U postgres -l

Show tables in database

psql -U postgres -d <database_name>

Drop database

dropdb <database_name>

Restart database

dropdb <database_name> && createdb <database_name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment