Getting Started

Starting Database with Docker

docker run --name <docker_name> 
 -e POSTGRES_PASSWORD=<password>
 -d -p 5432:5432 postgres:13.3

docker exec -it <docker_name> bash

psql -U postgres

Installing PostgreSQL on windows


Installing PostgreSQL on MacOS

Setup and Basics : using apt


sudo apt-get install postgresql

Usage commands

service postgresql

Switch to default user

sudo su postgres

Getting Started

Connect to a database

Connection options:
  -h, --host=HOSTNAME      
# database server host or socket directory 
# (default: "local socket")
  -p, --port=PORT          
# database server port 
# (default: "5432")
  -U, --username=USERNAME  
# database user name (default: "root")
  -w, --no-password        
# never prompt for password
  -W, --password           
  # force password prompt (should happen automatically)
  1. Here port : 5432 is default and can be get from psql --help

  2. postgres is the super user. Create another user and connect using that.

  3. to connect to database with user :

\c db_name user_name


-- to list all tables

-- to list all databases

-- to list all table spaces

-- to list all schemas

-- to list all indices

-- to list all sequences

-- to list all roles

-- to list data types

-- to list all domain datatypes

-- to list all views

-- to list previous commands

-- to list Command History

-- to run command from file
\i filename 
-- it should be inside the server

-- to list help
\h create table

-- to display null
\pset null (null)

-- to make terminal better
\pset linestyle unicode
\pset border 2

-- to watch a command in time
\watch 2

-- to turn on timing

Load Data

Download the sample data file from here

Last updated