Skip to content

Instantly share code, notes, and snippets.

@a2gs
Last active July 14, 2019 05:13
Show Gist options
  • Save a2gs/679a3781f207fcbfc59347adcb49e8e6 to your computer and use it in GitHub Desktop.
Save a2gs/679a3781f207fcbfc59347adcb49e8e6 to your computer and use it in GitHub Desktop.
0) Debian instalation
(ref: https://wiki.postgresql.org/wiki/Apt#Quickstart)
sudo apt-get install curl ca-certificates
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
sudo apt-get update
sudo apt-get install postgresql
/* sudo apt-get install pgadmin4 */
1) Getting Started
(ref: https://pgdash.io/blog/postgres-11-getting-started.html)
1.1)
/etc/postgresql/11/main/pg_hba.conf
This file is used to control how PostgreSQL users are authenticated
(https://www.postgresql.org/docs/11/auth-pg-hba-conf.html)
For item 1.3 add this line:
host userdb userapp 0.0.0.0/0 md5
1.2)
/etc/postgresql/11/main/postgresql.conf
Remove comment '#' from line and change 'localhost' to '*':
#listen_addresses = 'localhost'
listen_addresses = '*'
sudo systemctl restart postgresql
$ sudo netstat -tnlp | grep 5432
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 8408/postgres
1.3) Creating frist user (userapp) and self database (userdb):
$ sudo -u postgres psql
psql (11.0 (Ubuntu 11.0-1.pgdg18.04+2))
Type "help" for help.
postgres=# create user userapp password 'userpassword';
CREATE ROLE
postgres=# create database userdb owner userapp;
CREATE DATABASE
postgres=#
(or, after 'sudo su postgres', run commands 'createuser --interactive' and 'createdb userdb')
Testing:
$ psql -h 127.0.0.1 -d userdb -U userapp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment