Install PostgreSQL 12 on Centos8

1 minute read

Introduction

Since I had only touched Mysql, I installed Postgresql using the installation method on the official website for verification.
This time, we assume a local postgres user connection without authentication.

environment

  • CentOS8
  • Postgresql12

Installation

dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
dnf -qy module disable postgresql
dnf install -y postgresql12-server
/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl enable postgresql-12
systemctl start postgresql-12

Select the one you want to install from the official website below and install it.
https://www.postgresql.org/download/linux/redhat/

setting change

Advance preparation

User change

After installation, the postgres user has been added, so change the user.
Basically, the operation is performed by the postgres user.

su - postgres

Directory transition

Change to the directory where the configuration file is.

cd /var/lib/pgsql/12/data

Add PATH

Make pg_ctl available in relative PATH.
You may add it to .bash_profile.

export PATH=$PATH:/usr/pgsql-12/bin/

postgresql.conf
A file for basic settings. Change the settings as appropriate.
This time it is a verification, so leave it as the default.

pg_hba.conf
A file that sets the network to connect to.
By changing from ident to trust, you can connect to the local host without authentication.
If postgresql.conf is the default, you may go to connect with ipv6, so change ipv6 as well.

  • Change before
  • # IPv4 local connections:
    host    all             all             127.0.0.1/32            ident
    # IPv6 local connections:
    host    all             all             ::1/128                 ident
    
  • After change
  • # IPv4 local connections:
    host    all             all             127.0.0.1/32            trust
    # IPv6 local connections:
    host    all             all             ::1/128                 trust
    

Reflection of settings

Apply the settings with the following command.

pg_ctl reload

Verification

Login confirmation

Confirm that you can log in with the following command.

psql -h localhost

Password change (optional)

After connecting, change the password of the postgres user.

alter role postgres with password 'password';

Summary

I installed it on the official website.
I forgot to change the ipv6 settings, I didn’t know the initial password of the postgres user, or I was caught unexpectedly.
And the initial password for the postgres user is still unknown.

References