PostgreSQL

About

  • developed by the PostgreSQL Global Development Group
  • ACID (Atomicity, Consistency, Isolation, Durability) Compliance
  • SQL Compliance

Setup

  • Create VM instance in Google Cloud platform using ubuntu 14.04 LTS 
  • sudo apt-get update
  • sudo apt-get -y install postgresql postgresql-client postgresql-contrib
  • sudo -i
  • sudo -u postgres psql postgres
  • \password postgres
  • vi/etc/postgresql/9.3/main/pg_hba.conf
    • local   all   postgres   md5
  • sudo /etc/init.d/postgresql reload

Quick references / Cheatsheet

postgres -U postgres -W login
/etc/init.d/postgresql reload reload
\q quit

\list or \l

select datname from pg_database;

list databases
\c db_xxx connect database xxx
\d tb_yyy show table definition
\dn list schemas
\df list functions
\dv list views
\du [username] list user(s)
\dt list table
CREATE DATABASE db_xxx; create database

CREATE TABLE tb_ttt (

ID INT PRIMARY KEY NOT NULL,

NAME TEST);

create table
insert into tb_ttt (ID, NAME) values (1,'a'); insert query
select * from tb_ttt; select query
update tb_ttt set NAME = 'b' where ID = 1; update query
delete from tb_ttt where ID = 1; delete query
drop table tb_ttt; drop table
drop database db_xxx; drop database
\set variable=1; set variable
\timing on set timer on

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer