How to install PostgreSQL on Fedora 34

To Install PostgreSQL-14 on Fedora 34

Introduction:

PostgreSQL 14 Released. PostgreSQL is an open-source object-relational, highly scalable, SQL-compliant database management system which is developed at the University of California at Berkeley Computer Science Department.

Installation Procedure:

Step 1: Check the OS version by using the below command

[root@linuxhelp ~]# cat /etc/os-release
NAME=Fedora
VERSION="34 (Workstation Edition)"
ID=fedora
VERSION_ID=34
VERSION_CODENAME=""
PLATFORM_ID="platform:f34"
PRETTY_NAME="Fedora 34 (Workstation Edition)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:34"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f34/system-administrators-guide/"
SUPPORT_URL="https://fedoraproject.org/wiki/Communicating_and_getting_help"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=34
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=34
PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
VARIANT="Workstation Edition"
VARIANT_ID=workstation

Step 2: Before starting make sure that the server has up-to-date packages by using the below command

[root@linuxhelp ~]# dnf -y update
Fedora 34 - x86_64                                                                                      7.5 kB/s | 6.0 kB     00:00    
Fedora 34 openh264 (From Cisco) - x86_64                                                                1.1 kB/s | 989  B     00:00   
Fedora Modular 34 - x86_64                                                                              7.9 kB/s | 5.9 kB     00:00    
Fedora 34 - x86_64 - Updates                                                                            5.3 kB/s | 3.9 kB     00:00    
Fedora 34 - x86_64 - Updates                                                                            3.0 MB/s |  33 MB     00:11    
Fedora Modular 34 - x86_64 - Updates                                                                    6.5 kB/s | 5.6 kB     00:00    
Fedora Modular 34 - x86_64 - Updates                                                                    415 kB/s | 4.5 MB     00:10    
Dependencies resolved.
========================================================================================================================================
 Package                                               Architecture       Version                             Repository           Size
========================================================================================================================================
Installing:
 kernel                                                x86_64             5.16.11-100.fc34                    updates              84 k
 kernel-modules                                        x86_64             5.16.11-100.fc34                    updates              51 M
 kernel-modules-extra                                  x86_64             5.16.11-100.fc34                    updates             3.2 M
Upgrading:
 autocorr-en                                           noarch             1:7.1.8.1-4.fc34                    updates             108 k
 bolt                                                  x86_64             0.9.2-1.fc34                        updates             191 k
 btrfs-progs                                           x86_64             5.16.2-1.fc34                       updates             962 k
 cpp                                                   x86_64             11.2.1-9.fc34                       updates              10 M
 expat                                                 x86_64             2.4.4-1.fc34                        updates             112 k
 firefox                                               x86_64             97.0.1-2.fc34                       updates             104 M
 freerdp-libs                                          x86_64             2:2.5.0-1.fc34                      updates             998 k
 gcc                                                   x86_64             11.2.1-9.fc34                       updates              32 M
 gcc-gdb-plugin                                        x86_64             11.2.1-9.fc34                       updates             149 k
24 k
 gnome-user-docs                                       noarch             40.6-1.fc34                         updates             8.3 M
 hwdata                                                noarch             0.356-1.fc34                        updates             1.5 M
 iwl100-firmware                                       noarch             39.31.5.1-129.fc34                  updates             123 k
 iwl1000-firmware                                      noarch             1:39.31.5.1-129.fc34                updates             234 k
  libxcrypt-4.4.28-1.fc34.x86_64                                   libxcrypt-compat-4.4.28-1.fc34.x86_64                               
  libxcrypt-devel-4.4.28-1.fc34.x86_64                             linux-firmware-20220209-129.fc34.noarch                             
  linux-firmware-whence-20220209-129.fc34.noarch                   lua-5.4.4-1.fc34.x86_64                                             
  lua-libs-5.4.4-1.fc34.x86_64                                     microcode_ctl-2:2.1-46.1.fc34.x86_64                                
  mutter-40.9-1.fc34.x86_64                                        nspr-4.32.0-4.fc34.x86_64                                           
  nss-3.75.0-1.fc34.x86_64                                         nss-softokn-3.75.0-1.fc34.x86_64                                    
  nss-softokn-freebl-3.75.0-1.fc34.x86_64                          nss-sysinit-3.75.0-1.fc34.x86_64                                    
  nss-util-3.75.0-1.fc34.x86_64                                    polkit-0.117-3.fc34.3.x86_64                                        
  polkit-libs-0.117-3.fc34.3.x86_64                                protobuf-3.14.0-7.fc34.x86_64                                       
9.fc34.x86_64                
  qemu-device-usb-redirect-2:5.2.0-9.fc34.x86_64                   qemu-device-usb-smartcard-2:5.2.0-9.fc34.x86_64                     
  qemu-guest-agent-2:5.2.0-9.fc34.x86_64                           qemu-img-2:5.2.0-9.fc34.x86_64                                      
  qemu-kvm-2:5.2.0-9.fc34.x86_64                                   qemu-system-x86-2:5.2.0-9.fc34.x86_64                               
  qemu-system-x86-core-2:5.2.0-9.fc34.x86_64                       qemu-ui-curses-2:5.2.0-9.fc34.x86_64                                
  qemu-ui-egl-headless-2:5.2.0-9.fc34.x86_64                       qemu-ui-gtk-2:5.2.0-9.fc34.x86_64                                   
  qemu-ui-opengl-2:5.2.0-9.fc34.x86_64                             qemu-ui-sdl-2:5.2.0-9.fc34.x86_64                                   
  qemu-ui-spice-app-2:5.2.0-9.fc34.x86_64                          qemu-ui-spice-core-2:5.2.0-9.fc34.x86_64                            
  selinux-policy-34.26-1.fc34.noarch                               selinux-policy-targeted-34.26-1.fc34.noarch                         
  tigervnc-license-1.12.0-5.fc34.noarch                            tigervnc-server-minimal-1.12.0-5.fc34.x86_64                        
  uresourced-0.4.1-1.fc34.x86_64                                   vim-common-2:8.2.4460-1.fc34.x86_64                                 
  vim-data-2:8.2.4460-1.fc34.noarch                                vim-enhanced-2:8.2.4460-1.fc34.x86_64                               
  vim-filesystem-2:8.2.4460-1.fc34.noarch                          vim-minimal-2:8.2.4460-1.fc34.x86_64                                
  webkit2gtk3-2.34.6-1.fc34.x86_64                                 webkit2gtk3-jsc-2.34.6-1.fc34.x86_64                                
  wpa_supplicant-1:2.10-2.fc34.x86_64                              xen-libs-4.14.4-1.fc34.x86_64                                       
  xen-licenses-4.14.4-1.fc34.x86_64                                xorg-x11-server-Xorg-1.20.14-3.fc34.x86_64                          
  xorg-x11-server-common-1.20.14-3.fc34.x86_64                    
Installed:
  kernel-5.16.11-100.fc34.x86_64                   kernel-core-5.16.11-100.fc34.x86_64       kernel-modules-5.16.11-100.fc34.x86_64    
  kernel-modules-extra-5.16.11-100.fc34.x86_64     libglvnd-opengl-1:1.3.3-1.fc34.x86_64    

Complete!

Step 3: The fedora DNF Postgres module includes a Postgres 14 installation, but it is not the default. So, check the Postgres module on Fedora by running the below command

 [root@linuxhelp ~]# dnf module list postgresql
Last metadata expiration check: 0:09:07 ago on Sat 05 Mar 2022 02:21:19 AM IST.
Fedora Modular 34 - x86_64
Name                            Stream                      Profiles                               Summary                              
postgresql                      9.6                         client, server [d]                     PostgreSQL module                    
postgresql                      10                          client, server [d]                     PostgreSQL module                    
postgresql                      11                          client, server [d]                     PostgreSQL module                    
postgresql                      12                          client, server                         PostgreSQL module                    
postgresql                      13                          client, server                         PostgreSQL module                    

Fedora Modular 34 - x86_64 - Updates
Name                            Stream                      Profiles                               Summary                              
postgresql                      9.6                         client, server [d]                     PostgreSQL module                    
postgresql                      10                          client, server [d]                     PostgreSQL module                    
postgresql                      11                          client, server [d]                     PostgreSQL module                    
postgresql                      12                          client, server                         PostgreSQL module                    
postgresql                      13                          client, server                         PostgreSQL module                    
postgresql                      14                          client, server                         PostgreSQL module                    

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

Step 4: Enable postgres 14 by using the below command

 [root@linuxhelp ~]# dnf module enable postgresql:14
Last metadata expiration check: 0:14:45 ago on Sat 05 Mar 2022 02:21:19 AM IST.
Dependencies resolved.
========================================================================================================================================
 Package                         Architecture                   Version                           Repository                       Size
========================================================================================================================================
Enabling module streams:
 postgresql                                                     14                                                                     

Transaction Summary
========================================================================================================================================

Is this ok [y/N]: y
Complete!

Step 5: Now install Postgresql 14 and the Contrib package that provides several additional features for the PostgreSQL database system

 [root@linuxhelp ~]# dnf install -y postgresql-server postgresql-contrib
Last metadata expiration check: 0:15:29 ago on Sat 05 Mar 2022 02:21:19 AM IST.
Dependencies resolved.
========================================================================================================================================
 Package                             Architecture       Version                                       Repository                   Size
========================================================================================================================================
Installing:
 postgresql-contrib                  x86_64             14.1-1.module_f34+13635+e48fc4f4              updates-modular             872 k
 postgresql-server                   x86_64             14.1-1.module_f34+13635+e48fc4f4              updates-modular             5.9 M
Installing dependencies:
 postgresql                          x86_64             14.1-1.module_f34+13635+e48fc4f4              updates-modular             1.6 M
 postgresql-private-libs             x86_64             14.1-1.module_f34+13635+e48fc4f4              updates-modular             136 k
 uuid                                x86_64             1.6.2-50.fc34                                 fedora                       57 k

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

Total download size: 8.5 M
Installed size: 33 M
Downloading Packages:
(1/5): uuid-1.6.2-50.fc34.x86_64.rpm                                                                    178 kB/s |  57 kB     00:00    
(2/5): postgresql-private-libs-14.1-1.module_f34+13635+e48fc4f4.x86_64.rpm                              111 kB/s | 136 kB     00:01    
(3/5): postgresql-contrib-14.1-1.module_f34+13635+e48fc4f4.x86_64.rpm                                   401 kB/s | 872 kB     00:02    
(4/5): postgresql-14.1-1.module_f34+13635+e48fc4f4.x86_64.rpm                                           680 kB/s | 1.6 MB     00:02    
(5/5): postgresql-server-14.1-1.module_f34+13635+e48fc4f4.x86_64.rpm                                    2.7 MB/s | 5.9 MB     00:02    
----------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                   1.6 MB/s | 8.5 MB     00:05     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                1/1 
  Installing       : postgresql-private-libs-14.1-1.module_f34+13635+e48fc4f4.x86_64                                                1/5 
  Installing       : postgresql-14.1-1.module_f34+13635+e48fc4f4.x86_64                                                             2/5 
  Installing       : uuid-1.6.2-50.fc34.x86_64                                                                                      3/5 
  Installing       : postgresql-contrib-14.1-1.module_f34+13635+e48fc4f4.x86_64                                                     4/5 
  Running scriptlet: postgresql-server-14.1-1.module_f34+13635+e48fc4f4.x86_64                                                      5/5 
  Installing       : postgresql-server-14.1-1.module_f34+13635+e48fc4f4.x86_64                                                      5/5 
  Running scriptlet: postgresql-server-14.1-1.module_f34+13635+e48fc4f4.x86_64                                                      5/5 
  Verifying        : uuid-1.6.2-50.fc34.x86_64                                                                                      1/5 
  Verifying        : postgresql-14.1-1.module_f34+13635+e48fc4f4.x86_64                                                             2/5 
  Verifying        : postgresql-contrib-14.1-1.module_f34+13635+e48fc4f4.x86_64                                                     3/5 
  Verifying        : postgresql-private-libs-14.1-1.module_f34+13635+e48fc4f4.x86_64                                                4/5 
  Verifying        : postgresql-server-14.1-1.module_f34+13635+e48fc4f4.x86_64                                                      5/5 

Installed:
  postgresql-14.1-1.module_f34+13635+e48fc4f4.x86_64                    postgresql-contrib-14.1-1.module_f34+13635+e48fc4f4.x86_64      
  postgresql-private-libs-14.1-1.module_f34+13635+e48fc4f4.x86_64       postgresql-server-14.1-1.module_f34+13635+e48fc4f4.x86_64       
  uuid-1.6.2-50.fc34.x86_64                                            

Complete!

Step 6: Once the installation is complete, initialize the PostgreSQL database with the below command

[root@linuxhelp ~]# postgresql-setup initdb
WARNING: using obsoleted argument syntax, try --help
WARNING: arguments transformed to: postgresql-setup --initdb --unit postgresql
 * Initializing database in '/var/lib/pgsql/data'
 * Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log

Step 7: Now start the service by using the below command

 [root@linuxhelp ~]# systemctl start postgresql

Step 8: Then Enable the service using the below command therefore the service will automatically restart when the computer is restarted

 [root@linuxhelp ~]# systemctl enable postgresql
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service.

Step 9: Check whether the Postgres 14 is running by using the below command

 [root@linuxhelp ~]# systemctl status postgresql
● postgresql.service - PostgreSQL database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
     Active: active (running) since Sat 2022-03-05 02:38:43 IST; 54s ago
   Main PID: 79439 (postmaster)
      Tasks: 8 (limit: 4965)
     Memory: 15.7M
        CPU: 76ms
     CGroup: /system.slice/postgresql.service
             ├─79439 /usr/bin/postmaster -D /var/lib/pgsql/data
             ├─79440 postgres: logger
             ├─79442 postgres: checkpointer
             ├─79443 postgres: background writer
             ├─79444 postgres: walwriter
             ├─79445 postgres: autovacuum launcher
             ├─79446 postgres: stats collector
             └─79447 postgres: logical replication launcher

Mar 05 02:38:42 linuxhelp systemd[1]: Starting PostgreSQL database server...
Mar 05 02:38:43 linuxhelp postmaster[79439]: 2022-03-05 02:38:43.036 IST [79439] LOG:  redirecting log output to logging collector proc>
Mar 05 02:38:43 linuxhelp postmaster[79439]: 2022-03-05 02:38:43.036 IST [79439] HINT:  Future log output will appear in directory "log>
Mar 05 02:38:43 linuxhelp systemd[1]: Started PostgreSQL database server.

Step 10: Now verify that the installation was successfully completed by connecting to the PostgreSQL database server and printing its version using the below command

 [root@linuxhelp ~]# sudo -u postgres psql -c "SELECT version();"
could not change directory to "/root": Permission denied
                                                   version                                                    
--------------------------------------------------------------------------------------------------------------
 PostgreSQL 14.1 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1), 64-bit 
(1 row)

Step 11: Switch over to the postgres account on your server by running the below command in the terminal then set the password

[root@linuxhelp ~]# sudo -u postgres psql
could not change directory to "/root": Permission denied
psql (14.1)
Type "help" for help.

postgres=# \password postgres
Enter new password: 
Enter it again: 
postgres=#

By this the process of installing PostgreSQL on Fedora 34 has been completed.

FAQ
Q
What happened to the database dump feature in phpPgAdmin?
A
You need to configure phpPgAdmin (in the config.inc.php file) to point to the location of the pg_dump and pg_dumpall utilities on your server.
Once you have done that, the database export feature will appear.
Q
Why phpPgAdmin ask me to re-enter login information for every page I access?
A
You most certainly have a problem with your PHP sessions. Make sure:
your browser accepts cookies if your session ID relies on them
PHP has to write access to the path set in the parameter “session.save_path” of your php.ini
Q
How to control connections from other hosts?
A
PostgreSQL allows connections from the local machine using Unix domain sockets or TCP/IP connections.
Other machines will not be able to connect unless you modify listen_addresses in the postgresql.conf file,
enable host-based authentication by modifying the $PGDATA/pg_hba.conf file, and restart.
Q
How does PostgreSQL use CPU resources?
A
The PostgreSQL server is process-based (not threaded). Each database session connects to a single PostgreSQL operating system (OS) process.
Multiple sessions are automatically spread across all available CPUs by the OS.
Q
How to change the sort ordering of textual data in PostgreSQL?
A
PostgreSQL sorts textual data in accordance with the current locale, which is selected during initdb.