Install PostgreSQL 12 on Centos8

1 minute read


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.


  • CentOS8
  • Postgresql12


dnf install -y
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.

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


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

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

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

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               ident
    # IPv6 local connections:
    host    all             all             ::1/128                 ident
  • After change
  • # IPv4 local connections:
    host    all             all               trust
    # IPv6 local connections:
    host    all             all             ::1/128                 trust

Reflection of settings

Apply the settings with the following command.

pg_ctl reload


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';


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.