Explain the installation and configuration tutorial of PostgreSQL 11 under centos7

Time:2021-8-18

1. Official website address

Installation reference steps are provided on the official website: click here to view the official website

2. Install rpm


yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

3. Install the client

yum install postgresql11

4. Install the server side

yum install postgresql11-server

5. Install dependent packages


yum install postgresql11-libs
yum install postgresql11-contrib
yum install postgresql11-devel

6. Database initialization and setting self startup


/usr/pgsql-11/bin/postgresql-11-setup initdb
systemctl enable postgresql-11
systemctl start postgresql-11

In this step, the initialize database command will create a folder named 11 in the / var / lib / PgSQL directory. 11 is the database version. If other versions are installed, the corresponding version numbers are 9.4 and 9.5; If there is already a folder of the corresponding version here, an error will be reported in the initialization step. You need to delete the corresponding folder and then initialize it.

7. Modify database login password

After the database is initialized, a Linux login user named Postgres will be created by default, and the password will be modified here

[[email protected] ~]# passwd postgres

8. Log in to PostgreSQL


[[email protected] ~]# su - postgres
-bash-4.2$ psql
psql (11.5)
Type "help" for help.
postgres=#

9. Create a user to access PostgreSQL


postgres=# CREATE USER dbuser WITH PASSWORD '*****';

10. Create a database and grant user permissions


postgres=# CREATE DATABASE exampledb OWNER dbuser;
postgres=# GRANT ALL PRIVILEGES ON DATABASE exampledb TO dbuser;

11. Exit PSQL

postgres=# \q

12. Modify the configuration file for remote computer access


[[email protected] ~]# vim /var/lib/pgsql/11/data/postgresql.conf


[[email protected] ~]# vim /var/lib/pgsql/11/data/pg_hba.conf

13. Restart the service


[[email protected] ~]# systemctl restart postgresql-11

Finally, remember to open the firewall port


[[email protected] ~]# firewall-cmd --query-port=5432/tcp
no
[[email protected] ~]# firewall-cmd --add-port=5432/tcp
success
[[email protected] ~]# firewall-cmd --add-port=5432/tcp --zone=public --permanent
success

summary

The above is the installation and configuration tutorial of PostgreSQL 11 under centos7 introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support to the developeppaer website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!