Friday, December 27, 2024
Google search engine
HomeData Modelling & AIInstall PostgreSQL 12 on Fedora 38/37/36/35/34/33

Install PostgreSQL 12 on Fedora 38/37/36/35/34/33

This guide will discuss the installation of PostgreSQL 12 on Fedora 38/37/36/35/34/33. PostgreSQL is an open source database server created to be reliable, robust, and for performance focused deployments. The PostgreSQL 12 was released for general use on 3rd October 2019 with many new features.

install postgresql 12 fedora

Check available guides if you’re using a different flavor of Linux:

Let’s get started with the install of PostgreSQL 12 on Fedora.

Step 1: Update Fedora System

Ensure system packages are up to date:

sudo dnf install -y vim bash-completion wget
sudo dnf update -y

Since you may have Kernel updates, it is recommended to reboot your system after an upgrade:

sudo reboot

Step 2: Add PostgreSQL Yum Repository

Add PostgreSQL Yum Repository to your Fedora system by running the below command:

Fedora 38:

sudo dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/F-38-x86_64/pgdg-fedora-repo-latest.noarch.rpm

Fedora 37:

sudo dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/F-37-x86_64/pgdg-fedora-repo-latest.noarch.rpm

Fedora 36:

sudo dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/F-36-x86_64/pgdg-fedora-repo-latest.noarch.rpm

Fedora 35:

sudo dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/F-35-x86_64/pgdg-fedora-repo-latest.noarch.rpm

Fedora 34:

sudo dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/F-34-x86_64/pgdg-fedora-repo-latest.noarch.rpm

Fedora 33:

sudo dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/F-33-x86_64/pgdg-fedora-repo-latest.noarch.rpm

Fedora 32:

sudo dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/F-32-x86_64/pgdg-fedora-repo-latest.noarch.rpm

Step 3: Install PostgreSQL 12 on Fedora

After the PostgreSQL Repository is added to Fedora system, install PostgreSQL 12 Server / Client packages:

sudo dnf -qy module disable postgresql
sudo dnf install postgresql12-server postgresql12

Agree to the installation.

....
Transaction Summary
===================================================================================================================================================
Install  3 Packages

Total download size: 18 M
Installed size: 68 M
Is this ok [y/N]: y

Step 4: Initialize the database

Now that the database packages have been installed, Initialize the database by running the following command

$ sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
Initializing database ... OK

Then start and enable the service to start on boot

sudo systemctl enable --now postgresql-12

Confirm service status.

$ systemctl status postgresql-12
 postgresql-12.service - PostgreSQL 12 database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql-12.service; enabled; preset: disabled)
    Drop-In: /usr/lib/systemd/system/service.d
             └─10-timeout-abort.conf
     Active: active (running) since Fri 2023-05-26 16:02:33 UTC; 4s ago
       Docs: https://www.postgresql.org/docs/12/static/
    Process: 1909 ExecStartPre=/usr/pgsql-12/bin/postgresql-12-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
   Main PID: 1914 (postmaster)
      Tasks: 8 (limit: 4526)
     Memory: 16.4M
        CPU: 89ms
     CGroup: /system.slice/postgresql-12.service
             ├─1914 /usr/pgsql-12/bin/postmaster -D /var/lib/pgsql/12/data/
             ├─1915 "postgres: logger   "
             ├─1917 "postgres: checkpointer   "
             ├─1918 "postgres: background writer   "
             ├─1919 "postgres: walwriter   "
             ├─1920 "postgres: autovacuum launcher   "
             ├─1921 "postgres: stats collector   "
             └─1922 "postgres: logical replication launcher   "

May 26 16:02:33 fed38.mylab.io systemd[1]: Starting postgresql-12.service - PostgreSQL 12 database server...
May 26 16:02:33 fed38.mylab.io postmaster[1914]: 2023-05-26 16:02:33.374 UTC [1914] LOG:  starting PostgreSQL 12.15 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 13.1.1 20230426 (Red Hat 13.1.1-1),>
May 26 16:02:33 fed38.mylab.io postmaster[1914]: 2023-05-26 16:02:33.375 UTC [1914] LOG:  listening on IPv6 address "::1", port 5432
May 26 16:02:33 fed38.mylab.io postmaster[1914]: 2023-05-26 16:02:33.376 UTC [1914] LOG:  listening on IPv4 address "127.0.0.1", port 5432
May 26 16:02:33 fed38.mylab.io postmaster[1914]: 2023-05-26 16:02:33.377 UTC [1914] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
May 26 16:02:33 fed38.mylab.io postmaster[1914]: 2023-05-26 16:02:33.379 UTC [1914] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
May 26 16:02:33 fed38.mylab.io postmaster[1914]: 2023-05-26 16:02:33.398 UTC [1914] LOG:  redirecting log output to logging collector process
May 26 16:02:33 fed38.mylab.io postmaster[1914]: 2023-05-26 16:02:33.398 UTC [1914] HINT:  Future log output will appear in directory "log".
May 26 16:02:33 fed38.mylab.io systemd[1]: Started postgresql-12.service - PostgreSQL 12 database server.

If you have a running Firewall service and remote clients should connect to your database server, allow PostgreSQL service.

sudo firewall-cmd --add-service=postgresql --permanent
sudo firewall-cmd --reload

Step 5: Enable remote access to PostgreSQL (Optional)

If you have Applications connecting to the database server over the network, edit the file /var/lib/pgsql/12/data/postgresql.conf and set Listen address to your server IP address or “*” for all interfaces.

$ sudo vim /var/lib/pgsql/12/data/postgresql.conf 
listen_addresses = '*'

Also set PostgreSQL to accept remote connections from allowed hosts.

$ sudo vim /var/lib/pgsql/12/data/pg_hba.conf
# Accept from anywhere
host all all 0.0.0.0/0 md5

# Accept from trusted subnet
host all all 10.10.10.0/24 md5

Restart PostgreSQL 12 service after making the change.

sudo systemctl restart postgresql-12

Step 6: Set PostgreSQL admin user’s password

Set PostgreSQL admin user password.

sudo su - postgres
psql -c "alter user postgres with password 'StrongPassword'"

Where StrongPassword is the new password for postgres user.

Step 7: Install pgAdmin 4 Web Management

If you need an easy way for managing PostgreSQL database server (Similar to phpMyAdmin for MySQL), consider installing pgAdmin4.

Recommended books:

Enjoy running PostgreSQL 12 on Fedora Linux.

More guides to check out:

RELATED ARTICLES

Most Popular

Recent Comments