PostgreSQL cheat-sheet

Create DB and user

postgres@kuro:$ createdb "doggo"
postgres@kuro:$ psql
psql (9.6.4)
Type "help" for help.

postgres=# create user doggo;
CREATE ROLE
postgres=# ALTER USER doggo WITH PASSWORD 'doggo';
ALTER ROLE
postgres=# grant all privileges on database "doggo" to doggo;
GRANT
postgres=# \q

Connect

PGUSER=doggo PGHOST=localhost PGPASSWORD=doggo PGDATABASE=doggo psql

PostGIS

sudo apt install postgis

\c doggo;

ALTER TABLE public.tweets ADD COLUMN location geography(POINT);

Create Tables

ALTER TABLE public.locations ADD COLUMN id bigserial primary key;

Commands

list

\l

List tables

\dt