Install PostgreSQL 9.6 on CentOS 7

CentOS Yum tool installation, simple and convenient, official source list, RPM LIST .

add RPM

yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm

Install PostgreSQL 9.6

postgresql96-server database core server

postgresql96-contrib additional third-party extensions

postgresql96-devel C language development Header header files and libraries

yum install postgresql96-server postgresql96-contrib postgresql96-devel

Verify that the installation was successful

rpm -aq| grep postgres

The default Postgresql database path is /var/lib/pgsql/9.6/data, you can create a new directory, if it is /mnt/vdb1

cd /mnt

sudo mkdir vdb1

sudo chown -R postgres:postgres vdb1

sudo chmod 700 vdb1

vi /usr/lib/systemd/system/postgresql-9.6.service

Environment=PGDATA=/mnt/vdb1/ Change to your own new data path

Initialize the database

/usr/pgsql-9.6/bin/postgresql96-setup initdb

Start the service

service postgresql-9.6start  或者 systemctl start postgresql-9.6.service

boot

sudo chkconfig postgresql-9.6 on  或者 systemctl enable postgresql-9.6.service

change Password

with postgres

psql

ALTER USER postgres WITH PASSWORD 'password'; -- must end with a semicolon, ALTER ROLE will appear after successful execution

\q

su root

Enable remote access

vi /var/lib/pgsql/9.6/data/postgresql.conf someone vi /mnt/vdb1/postgresql.conf

修改#listen_addresses = 'localhost'  为  listen_addresses='*'

Of course, the '*' here can also be changed to any server IP you want to open

Trust remote connections

vi /var/lib/pgsql/9.6/data/pg_hba.conf someone vi /mnt/vdb1/pg_hba.conf

Modify the following content to trust the specified server connection

# IPv4 local connections:

host    all            all      127.0.0.1/32      md5

host all all 10.211.55.6/32 (server IP that needs to be connected) md5

restart the service

service postgresql-9.6 restart 或者 systemctl restart postgresql-9.6.service

Open the firewall

The PostgreSQL service is built into the CentOS firewall. The location of the configuration file is /usr/lib/firewalld/services/postgresql.xml. We only need to open the PostgreSQL service as a service.

systemctl enable firewalld enable firewall at boot

systemctl start firewalld to open the firewall

firewall-cmd --add-service=postgresql --permanent open postgresql service

firewall-cmd --zone=public --add-port=5432/tcp --permanent or you can add the port directly

firewall-cmd --reload reload firewall

firewall-cmd --list-ports View occupied ports

Simple to use:

psql -U postgres postgres connect to the database

Description: -h means host (Host), -p means port (Port), -U means user (User)

Show all databases: \l

 

Uninstall PostgreSQL

yum erase postgresql96

end

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326070086&siteId=291194637