Install PostgreSQL12 on CentOS offline

Download resource packs

  1. Download address

    www.postgresql.org/download/

  2. Drag to the bottom and hit Direct Download

  3. Choose your own version (depending on your system)

  4. Click to enter

  5. Download the following four files

Two, install and start

  1. Place the four files you just downloaded on your own server and execute the following command

    RPM -ivh postgresQL12-LIBs-12.10-1pgdg.rhel7.x86_64. RPM RPM -ivh postgresQL12-contrib-12.10-1pgdg.rhel7.x86_64. RPM -ivh postgresql12-12.10-1pgdg.rhel7.x86_64. RPM RPM -ivh postgresQL12-server-12.10-1pgdg.rhel7.x86_64. RPMCopy the code
  2. Initializing the database

    /usr/pgsql-12/bin/postgresql-12-setup initdb
    Copy the code
  3. Start the service

    systemctl start postgresql-12
    Copy the code

3. Configure services

  1. Allow other IP access and port number Settings

    vi /var/lib/pgsql/12/data/postgresql.conf
    Copy the code

    Listen_addresses = ‘*’ : listens on all IP addresses

    Port = 5432 Indicates the service port. You can specify another port

  2. Change the allowed IP address (the following configuration allows all IP addresses to access)

TYPE DATABASE USER ADDRESS METHOD
host all all 0.0.0.0/0 md5

The modification takes effect only after the service is restarted

Restart the service

systemctl restart postgresql-12
Copy the code

Create users and databases

  1. Switch to the Postgres user

    su - postgres
    psql -p 5432
    Copy the code
  2. Create a database user name

    create user test with password '123456';
    Copy the code

  3. Creating a database

    create database testdb;
    Copy the code

  4. Grant testdb to the test user

grant all privileges on database testdb to test;
Copy the code

The basic installation and configuration has been completed