CentOS 7 installation, configuration, use of PostgreSQL 9.5 (1) installation and basic configuration

     I don't know how to read the name of this database, I found the documentation on the official website.

PostgreSQL is pronounced Post-Gres-QL. 

What is PostgreSQL? How is it pronounced? What is Postgres?

Recently, due to the needs of the project, I was going to use the PostgreSQL database. After consulting some databases, I decided to use PostgreSQL 9.5. I found some information on the Internet. After practice, I wrote down the process for future reference.

Since the project operating system has been using CentOS 7, CentOS7+PostgreSQL9.5 is used together.

OS version: Linux localhost.localdomain 3.10.0-327.18.2.el7.x86_64 #1 SMP Thu May 12 11:03:55 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Database version: psql (PostgreSQL) 9.5.3

Refer to the official documentation for the installation process, the address is listed here, Linux downloads (Red Hat family)  .

CentOS Yum tool installation is simple and convenient, check the official source version, it shows that the latest version is 9.2.15, and the source needs to be updated. There is a special rpm package list in the document, RPM LIST .

1. Add RPM
    yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm

2.安装PostgreSQL 9.5
    yum install postgresql95-server postgresql95-contrib

3. Initialize the database
    /usr/pgsql-9.5/bin/postgresql95-setup initdb

4. Set the boot self-start
    systemctl enable postgresql-9.5.service

5. Start the service
    systemctl start postgresql-9.5.service

Since then, the installation of PostgreSQL 9.5 has been completed. During this process, pay attention to the installation permissions. I have been using the root user to install during the installation process.

Next, perform a simple configuration.

After PostgreSQL is installed, a 'postgres' user will be created to execute PostgreSQL, and a 'postgres' user will also be created in the database. The default password is automatically generated and needs to be changed in the system.

6. Modify the user password
    su - postgres to switch users, the prompt will become '-bash-4.2$'
    after execution psql -U postgres log in to the database, after execution the prompt will become 'postgres=#'
    ALTER USER postgres WITH PASSWORD 'abc123 ' Set the postgres user password
    \q to exit the database

The account and password for system management have been changed. Now configure the remote connection.

7. Enable remote access
    vi /var/lib/pgsql/9.5/data/postgresql.conf
    Modify #listen_addresses = 'localhost' to listen_addresses='*'
    Of course, '*' here can also be changed to any server you want to open IP

8. Trust the remote connection
    vi /var/lib/pgsql/9.5/data/pg_hba.conf
    Modify the following to trust the specified server connection
    # IPv4 local connections:
    host all all 127.0.0.1/32 trust
    host all all 10.211.55.6/32 (requires the server IP to connect to) trust

The remote connection configuration is completed. Due to system reasons, the corresponding port needs to be opened in the firewall.

9. Open the firewall
    The CentOS firewall has a built-in PostgreSQL service. The location of the configuration file is /usr/lib/firewalld/services/postgresql.xml. We only need to open the PostgreSQL service as a service.
    firewall-cmd --add-service=postgresql --permanent open postgresql service
    firewall-cmd --reload reload firewall

The last step, not to be forgotten, is to restart the database service for the configuration to take effect.

10. Restart PostgreSQL data service
    systemctl restart postgresql-9.5.service

 

So far, PostgreSQL 9.5 has completed the basic installation and configuration on CentOS 7.

Guess you like

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