Introduction to PostgreSQL

PostgreSQL is an object-RDBMS (ORDBMS) developed by the PostgreSQL Global Development Group.

Installation on CentOS 6.9

Installation

1
2
3
sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm

sudo yum -y install postgresql95-server postgresql95 libpqxx-devel postgresql-devel

Initializing database

1
sudo service postgresql-9.5 initdb

Starting Server

1
sudo service  postgresql-9.5 start

Auto-starting postgresql on server restart

1
sudo chkconfig postgresql-9.5 on

psql setup (updating default psql path to new version)

1
2
sudo mv /usr/bin/psql /usr/bin/psql-bk
sudo ln -sfn /usr/pgsql-9.5/bin/psql /usr/bin/psql

commandline postgres

1
2
3
4
5
6
7
8
sudo -u postgres psql
postgres=#

# quit
postgres=# \q

# show all databases
postgres=# \l

database backup

1
/usr/pgsql-9.5/bin/pg_dump redash | gzip > backup_redash_20181218.gz

creating new database

1
2
sudo -u postgres psql
postgres=# CREATE DATABASE redash2;

importing database backup

1
sudo -u postgres psql redash2 < backup_redash_20181218.sql

PostgreSQL docker instance

Downloading PostgreSQL docker image

1
docker pull postgres:9.6.5

Running postgres container

1
docker run --name postgres-5432 -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres:9.6.5