Skip to content

Instantly share code, notes, and snippets.

@zhiyao
Forked from ibraheem4/postgres-brew.md
Last active August 25, 2020 15:40
Show Gist options
  • Save zhiyao/d1f32d420a20d9e0e968dad4fb3730d2 to your computer and use it in GitHub Desktop.
Save zhiyao/d1f32d420a20d9e0e968dad4fb3730d2 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 postgres

  2. Run the command: brew services list to check if postgres is started

  3. Run the command: brew services start postgresql to start postgresql services

  4. Run the command: createdb `whoami`

  5. Connect to your postgres with the command: psql

  6. brew reinstall readline - ONLY IF NEEDED

  7. createuser -s postgres - fixes role "postgres" does not exist

  8. Test with psql command

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

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.

Commands

Create database

createdb <database_name>

createdb mydjangoproject_development

List databases

psql -U postgres -l

Show tables in database

psql -U postgres -d <database_name>

psql -U postgres -d mydjangoproject_development

Select database

psql
postgres=# \c testdb;

Create table in database

psql -U postgres -d <database_name>
CREATE TABLE accounts (
	user_id serial PRIMARY KEY,
	username VARCHAR ( 50 ) UNIQUE NOT NULL,
	password VARCHAR ( 50 ) NOT NULL,
	email VARCHAR ( 255 ) UNIQUE NOT NULL,
	created_on TIMESTAMP NOT NULL,
        last_login TIMESTAMP 
);

Drop database

dropdb <database_name>

dropdb mydjangoproject_development

Restart database

dropdb <database_name> && createdb <database_name>

dropdb mydjangoproject_development && createdb mydjangoproject_development

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