Postgresql Installation and management basics

Installing & Managing postgresql Database in Debian:

sudo apt-get install postgresql-9.5 libpq-dev
# connecting to databasesudo su
su postgres -c "psql"
# change postgres user passwordALTER USER postgres PASSWORD 'our-new-password';
\q
# modify pg_hba.conf to connect to database with password only.local all postgres peer
local all all peer
change peer to md5 and restart postgresql for changes to take affect.# connecting to database psql -U postgres
# create new database
CREATE DATABASE gondor;
# create new user
CREATE USER elessar WITH PASSWORD '<some-password>'
# grant the user permission to Database
GRANT ALL PRIVILEGES ON DATABASE gondor TO elessar;
# switch to database
connect <database-name>

Using Docker Image:

Installing Docker:

wget -qO- https://get.docker.com/ | s
docker run --name some-postgres -e POSTGRES_PASSWORD=<password-postgres-user> -d postgres
apt-get install postgresql-client-common postgresql-client-9.5
psql -U postgres -h <docker-ip>

The article was originally published at MicroPyramid blog.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
MicroPyramid

MicroPyramid

1K Followers

Python, Django, Android and IOS, reactjs, react-native, AWS, Salesforce consulting & development company