Saturday, December 28, 2024
Google search engine
HomeData Modelling & AIInstall PostgreSQL 13 on Fedora 38/37/36/35/34/33

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

PostgreSQL is a powerful, widely used relational database management system designed to be resilient and fault tolerant. The PostgreSQL database is based on POSTGRES 4.2. As of this article update the latest release of PostgreSQL database is 13. You can check the new features, improvements and bug fixes on PostgreSQL 13 in the official release notes page.

Some changes noted in PostgreSQL 13 release.

  • Improvements from de-duplication of B-tree index entries – Space savings and performance gains from
  • Queries that use aggregates or partitioned tables gets improved performance.
  • Incremental sorting
  • Better query planning when using extended statistics
  • Parallelized vacuuming of indexes

The PostgreSQL team provides pre-built binary packages for installation YUM based and Debian based Linux systems. We will add the required repositories before installing PostgreSQL 13 on Fedora.

Step 1 – Install PostgreSQL 13 on Fedora 38/37/36/35/34/33

Follow the steps in this section to install and configure PostgreSQL 13 on Fedora.

Update System

Always work on an up-to-date Fedora system.

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

Perform a reboot after successful upgrade:

sudo reboot

Reset default AppStream modules for PostgreSQL.

sudo dnf module reset postgresql -y

Add the PostgreSQL Yum Repository

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

Fedora 38:

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

Fedora 37:

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

Fedora 36:

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

Fedora 35:

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

Fedora 34:

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

Fedora 33:

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

Fedora 32:

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

When prompted to confirm installation, press the key.

Dependencies resolved.
======================================================================================================================================================================================================
 Package                                              Architecture                               Version                                       Repository                                        Size
======================================================================================================================================================================================================
Installing:
 pgdg-fedora-repo                                     noarch                                     42.0-26                                       @commandline                                      10 k

Transaction Summary
======================================================================================================================================================================================================
Install  1 Package

Total size: 10 k
Installed size: 12 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                              1/1
  Installing       : pgdg-fedora-repo-42.0-26.noarch                                                                                                                                              1/1
  Verifying        : pgdg-fedora-repo-42.0-26.noarch                                                                                                                                              1/1

Installed:
  pgdg-fedora-repo-42.0-26.noarch

Complete!

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

sudo dnf install postgresql13-server postgresql13

Agree to the installation prompts that you receive.

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

Total download size: 7.9 M
Installed size: 32 M
Is this ok [y/N]: y

This includes GPG key importation:

....
Importing GPG key 0x442DF0F8:
 Userid     : "PostgreSQL RPM Building Project <[email protected]>"
 Fingerprint: 68C9 E2B9 1A37 D136 FE74 D176 1F16 D2E1 442D F0F8
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Is this ok [y/N]: y

Step 2 – Initialize PostgreSQL database

Run the commands below to initialize the database:

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

Start and enable postgresql database service:

$ sudo systemctl enable --now postgresql-13
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-13.service → /usr/lib/systemd/system/postgresql-13.service.

Confirm service status.

$ systemctl status postgresql-13
● postgresql-13.service - PostgreSQL 13 database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
     Active: active (running) since Mon 2021-02-08 21:25:49 UTC; 21s ago
       Docs: https://www.postgresql.org/docs/13/static/
    Process: 1076 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
   Main PID: 1081 (postmaster)
      Tasks: 8 (limit: 1125)
     Memory: 16.2M
        CPU: 59ms
     CGroup: /system.slice/postgresql-13.service
             ├─1081 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
             ├─1082 postgres: logger
             ├─1084 postgres: checkpointer
             ├─1085 postgres: background writer
             ├─1086 postgres: walwriter
             ├─1087 postgres: autovacuum launcher
             ├─1088 postgres: stats collector
             └─1089 postgres: logical replication launcher

Feb 08 21:25:49 fed33 systemd[1]: Starting PostgreSQL 13 database server...
Feb 08 21:25:49 fed33 postmaster[1081]: 2021-02-08 21:25:49.811 UTC [1081] LOG:  redirecting log output to logging collector process
Feb 08 21:25:49 fed33 postmaster[1081]: 2021-02-08 21:25:49.811 UTC [1081] HINT:  Future log output will appear in directory "log".
Feb 08 21:25:49 fed33 systemd[1]: Started PostgreSQL 13 database server.

Step 3 – Enable remote Access to PostgreSQL (Optional)

For remote clients connectivity you may have to permit access in the firewall.

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

Then edit the file /var/lib/pgsql/13/data/postgresql.conf and set Listen address to your server IP address or “*” for all interfaces, or specific IP address/subnet.

$ sudo vi /var/lib/pgsql/13/data/postgresql.conf 
listen_addresses = '*'

Also set PostgreSQL to accept remote connections from allowed hosts.

$ sudo vim /var/lib/pgsql/11/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 13 service after making the change.

sudo systemctl restart postgresql-13

Step 4 – Set PostgreSQL admin user’s password

Set PostgreSQL admin user password.

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

Where StrongDBPassword is the new password for postgres user.

Step 5 – Install pgAdmin 4 Web Management

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

Enjoy running PostgreSQL 13 on Fedora Linux system.

Recommended books to learn PostgreSQL database administration:

Other guides on Fedora;

RELATED ARTICLES

Most Popular

Recent Comments