Skip to content

Instantly share code, notes, and snippets.

@nakaz
Forked from sgnl/postgres-brew.md
Last active July 22, 2017 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nakaz/03abe25b9353ce16dd74 to your computer and use it in GitHub Desktop.
Save nakaz/03abe25b9353ce16dd74 to your computer and use it in GitHub Desktop.

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the command: brew update

Installing

  1. In your command-line run the command: brew install postgresql
  2. Read the Caveats section that is outputted to the Terminal.
  3. Run the command: ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
  4. Open your zsh config file: subl ~/.zshrc
  5. At the bottom of the file, create two new aliases to start and stop your postgres server. They could look something like this:
alias pg-start="launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist"
alias pg-stop="launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist"

Run the command: source ~/.zshrc to reload your configuration.

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.

What is launchctl?

from the man launchctl command

launchctl interfaces with launchd to manage and inspect daemons, angents and XPC services.

Install Postgres for Ubunutu

Link: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04~

Ubuntu Installation Process:

sudo apt-get update
sudo apt-get install postgresql postgresql-contrib

Once that is complete run the command: psql

You will see an error. Read the error, what is it saying?

It says that the "...role [yourusername] doesn't exist" so we will create one with the needed permissions.

enter the command: $ sudo -u postgres -c 'psql' this should log you into the postgres server.

To create a user, enter this command and replace yourusername with your username from the error message previous: CREATE ROLE yourusername WITH LOGIN CREATEDB CREATEDB

enter: \q to exit out

You should be able to run the command psql now and have permissions to create/modify/delete databases and roles.

TLDR;

$ sudo su - postgresql

$ createuser --interactive

(enter your machine username at the first prompt and y at the second)

$ createdb yourusername

$ exit

$ psql //This will allow you to be able to run this psql command as your user and connect to Postgres

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