Install PostgreSQL on Fedora 36

This article will take you through how to install PostgreSQL on Fedora 36. Frequently referred to as Postgres, PostgreSQL is a relational database management system (RDBMS) that emphasizes flexibility and SQL compliance. PostgreSQL supports both relational SQL and non-relational JSON querying. PostgreSQL’s features include triggers, foreign keys, materialized views, transactions with Atomicity, Consistency, Isolation, and Durability (ACID) properties, and stored procedures.

It can handle a variety of workloads, including those on single PCs, data warehouses, and Web services with many concurrent users. It supports operating systems such as Windows, Linux, FreeBSD, and OpenBSD, and serves as the macOS Server’s default database.

How to Install PostgreSQL on Fedora 36

  • Update your system.
sudo dnf update
  • Install PostgreSQL on Fedora 36 using the command below.
sudo dnf install -y postgresql-server postgresql-contrib

Sample output

Last metadata expiration check: 1:17:14 ago on Thu 30 Jun 2022 08:59:09 AM EAT.
Dependencies resolved.
==============================================================================
 Package                     Arch       Version              Repository  Size
==============================================================================
Installing:
 postgresql-contrib          x86_64     14.1-3.fc36          fedora     873 k
 postgresql-server           x86_64     14.1-3.fc36          fedora     6.0 M
Installing dependencies:
 postgresql                  x86_64     14.1-3.fc36          fedora     1.6 M
 postgresql-private-libs     x86_64     14.1-3.fc36          fedora     137 k
 uuid                        x86_64     1.6.2-54.fc36        fedora      58 k

Transaction Summary
==============================================================================
Install  5 Packages

Total download size: 8.6 M
Installed size: 33 M
Downloading Packages:
(1/5): postgresql-private-libs-14.1-3.fc36.x8  93 kB/s | 137 kB     00:01    
(2/5): postgresql-contrib-14.1-3.fc36.x86_64. 111 kB/s | 873 kB     00:07    
(3/5): uuid-1.6.2-54.fc36.x86_64.rpm          137 kB/s |  58 kB     00:00    
(4/5): postgresql-14.1-3.fc36.x86_64.rpm       95 kB/s | 1.6 MB     00:16    
(5/5): postgresql-server-14.1-3.fc36.x86_64.r 204 kB/s | 6.0 MB     00:30    
------------------------------------------------------------------------------
Total                                         262 kB/s | 8.6 MB     00:33     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                      1/1 
  Installing       : postgresql-private-libs-14.1-3.fc36.x86_64           1/5 
  Installing       : postgresql-14.1-3.fc36.x86_64                        2/5 
  Installing       : uuid-1.6.2-54.fc36.x86_64                            3/5 
  Installing       : postgresql-contrib-14.1-3.fc36.x86_64                4/5 
  Running scriptlet: postgresql-server-14.1-3.fc36.x86_64                 5/5 
  Installing       : postgresql-server-14.1-3.fc36.x86_64                 5/5 
  Running scriptlet: postgresql-server-14.1-3.fc36.x86_64                 5/5 
  Verifying        : postgresql-14.1-3.fc36.x86_64                        1/5 
  Verifying        : postgresql-contrib-14.1-3.fc36.x86_64                2/5 
  Verifying        : postgresql-private-libs-14.1-3.fc36.x86_64           3/5 
  Verifying        : postgresql-server-14.1-3.fc36.x86_64                 4/5 
  Verifying        : uuid-1.6.2-54.fc36.x86_64                            5/5 

Installed:
  postgresql-14.1-3.fc36.x86_64                                               
  postgresql-contrib-14.1-3.fc36.x86_64                                       
  postgresql-private-libs-14.1-3.fc36.x86_64                                  
  postgresql-server-14.1-3.fc36.x86_64                                        
  uuid-1.6.2-54.fc36.x86_64                                                   

Complete!
  • Next, initialize the database using the following command.
sudo postgresql-setup --initdb --unit postgresql
  • Enable PostgreSQL to start on boot.
sudo systemctl enable postgresql
  • Then start PostgreSQL by running the command below.
sudo systemctl start postgresql
  • PostgreSQL should be up and running, you can check its status using the following command.
sudo systemctl status postgresql

Sample output

● postgresql.service - PostgreSQL database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
     Active: active (running) since Thu 2022-06-30 10:22:29 EAT; 1min 10s ago
    Process: 4646 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)
   Main PID: 4648 (postmaster)
      Tasks: 8 (limit: 4612)
     Memory: 16.4M
        CPU: 79ms
     CGroup: /system.slice/postgresql.service
             ├─ 4648 /usr/bin/postmaster -D /var/lib/pgsql/data
             ├─ 4649 "postgres: logger "
             ├─ 4651 "postgres: checkpointer "
             ├─ 4652 "postgres: background writer "
             ├─ 4653 "postgres: walwriter "
             ├─ 4654 "postgres: autovacuum launcher "
             ├─ 4655 "postgres: stats collector "
             └─ 4656 "postgres: logical replication launcher "

Jun 30 10:22:29 fedora systemd[1]: Starting postgresql.service - PostgreSQL database server...
Jun 30 10:22:29 fedora postmaster[4648]: 2022-06-30 10:22:29.202 EAT [4648] LOG:  redirecting log output to logging collector process
Jun 30 10:22:29 fedora postmaster[4648]: 2022-06-30 10:22:29.202 EAT [4648] HINT:  Future log output will appear in directory "log".
Jun 30 10:22:29 fedora systemd[1]: Started postgresql.service - PostgreSQL database server.
  • Allow PostgreSQL on the firewall.
sudo firewall-cmd --add-service=postgresql --permanent
  • Reload your firewall for changes to take effect.
sudo firewall-cmd --reload

Connect to PostgreSQL on Fedora 36

  • Login to PostgreSQL using the default user account.
sudo -u postgres psql
  • Then set a password for the user.
\password postgres
  • Create user.
CREATE USER itnixpro WITH PASSWORD 'strongpassword';
  • Create a database with the user-created above as the owner.
CREATE DATABASE Nixproject OWNER itnixpro;
  • Show databases.
\l
  • Quit PostgreSQL.
\q

Sample output

postgres=# \password postgres
Enter new password: 
Enter it again: 
postgres=# CREATE USER itnixpro WITH PASSWORD 'strongpassword';
CREATE ROLE
postgres=# CREATE DATABASE Nixproject OWNER itnixpro;
CREATE DATABASE
postgres-# \l
                                  List of databases
    Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privi
leges   
------------+----------+----------+-------------+-------------+---------------
--------
 nixproject | itnixpro | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres   | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres   
       +
            |          |          |             |             | postgres=CTc/p
ostgres
 template1  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres   
       +
            |          |          |             |             | postgres=CTc/p
ostgres
(4 rows)
postgres-# \q
  • To check the version of PostgreSQL installed simply run the following command.
sudo -u postgres psql -c "SELECT version();"
  • You have made it to the end of our guide, congratulations. We have gone through how to install PostgreSQL on Fedora 36.

Read more on PostgreSQL Documentation

Other Tutorials

Install PostgreSQL on Ubuntu 22.04

Install pgAdmin on Ubuntu 22.04

Install DBeaver on Ubuntu 22.04

System administrator | Software Developer | DevOps

Leave a Comment