Skip to content

Instantly share code, notes, and snippets.

@sko00o
Last active November 18, 2019 07:57
Show Gist options
  • Save sko00o/2ad5c10a4f43d0a465457e347c7c9b5d to your computer and use it in GitHub Desktop.
Save sko00o/2ad5c10a4f43d0a465457e347c7c9b5d to your computer and use it in GitHub Desktop.
[Install PostgreSQL on CentOS7] #postgresql #CentOS7

Install PostgreSQL on CentOS7

Installation

if you want install latest version check official site

# will install postgres9
sudo yum install postgresql-server postgresql-contrib
sudo postgresql-setup initdb

Config for remote access

Set listen port to wildcard

# sudo vim /var/lib/pgsql/data/postgresql.conf
listen_addresses = '*'

Change HBA (host-based authentication) configuration

# sudo vim /var/lib/pgsql/data/pg_hba.conf
host    all             all             0.0.0.0/0            md5

Start server

sudo systemctl start postgresql
sudo systemctl enable postgresql

# check listen port
ss -ant | grep 5432

Login default role

sudo -i -u postgres
# to access PostgreSQL prompt
psql
# for quit PostgreSQL prompt
\q  

Create a new role

createuser --interactive

My new role is rwuser

Create a new database

createdb test1

Login new role

# access PostgreSQL prompt with new role
sudo su -c "psql -d test1" - rwuser
# type following command in  PostgreSQL prompt
\password
# then set your new password

You can use navicat to connect pgsql later.

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment