Install Postgresql On Centos
Download
$ sudo yum install postgresql-server
Enable service
$ sudo systemctl enable postgresql.service
InitDB
$ sudo /usr/bin/postgresql-setup initdb
Start service
$ sudo systemctl start postgresql.service
Configuration
$ sudo vi /var/lib/pgsql/data/postgresql.conf
Connection Settings
find & replace
As-is:
listen_addresses = 'localhost'
To-be:
listen_addresses = '*'
Change password
$ sudo vi /var/lib/pgsql/data/pg_hba.conf
find & replace
As-is:
local all all peer
To-be:
local all all trust
$ sudo systemctl restart postgresql.service
$ psql -U postgres
postgres=# ALTER USER postgres with password 'yourPasswd';
postgres=# \q
$ sudo vi /var/lib/pgsql/data/pg_hba.conf
find & replace
As-is:
local all all trust
To-be:
local all all md5
and, add row
host all all 0.0.0.0/0 md5
$ sudo systemctl restart postgresql.service
$ psql -U postgres
Password for user postgres: # <== new password
psql (9.2.18)
Type "help" for help.
postgres=#
CREATE DATABASE
postgres=# CREATE DATABASE test1 WITH OWNER = postgres ENCODING = 'UTF8';
CREATE DATABASE
postgres=#
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------+----------+----------+-------------+-------------+-----------------------
test1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
Use Database
postgres=# \c test1
You are now connected to database "test1" as user "postgres".
test1=# \q
Client
https://www.pgadmin.org/download/