This post is about How to install PostgreSQL on Fedora 35.
Introduction to PostgreSQL on Fedora
PostgreSQL is an open-source object-relational, highly scalable, SQL-compliant database management system. It is developed at the University of California at Berkeley Computer Science Department.
At the time of the last update of this article, PostgreSQL 14.1 is the latest stable version available for production servers.
So, this guide is for the installation of PostgreSQL 14.1 on Fedora 35. PostgreSQL is a powerful open-source relational database system with a strong reputation for reliability, feature robustness, and performance.
Use the steps below to install PostgreSQL 14.1 on your Fedora 35. For those new to Fedora, we have an installation guide:
Step 1: Update System
Ensure system packages are up to date:
sudo dnf install -y bash-completion vim
sudo dnf update -y
Since you may have Kernel updates, it is recommended to reboot your system after an upgrade. This step is not necessary if you are using Fedora 35 or the latest version.
sudo reboot
Step 2: Add the PostgreSQL Yum Repository
Before installing PostgreSQL on Fedora 35 you need to add PostgreSQL Yum Repository to your Fedora system by running the below command
sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-35-x86_64/pgdg-fedora-repo-latest.noarch.rpm
When prompted to confirm installation, press the y key.
...................................
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
pgdg-fedora-repo noarch 42.0-4 @commandline 9.6 k
Transaction Summary
================================================================================
Install 1 Package
Total size: 9.6 k
Installed size: 9.1 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-4.noarch 1/1
Verifying : pgdg-fedora-repo-42.0-4.noarch 1/1
Installed:
pgdg-fedora-repo-42.0-4.noarch
Complete!
Step 3: Install PostgreSQL on Fedora 35
After adding PostgreSQL Yum Repository, install PostgreSQL on Fedora by running:
$ sudo dnf install postgresql11-server postgresql11
PostgreSQL 11 30 - x86_64 22 kB/s | 138 kB 00:06
PostgreSQL 10 30 - x86_64 18 kB/s | 130 kB 00:07
PostgreSQL 9.6 30 - x86_64 16 kB/s | 128 kB 00:07
PostgreSQL 9.5 30 - x86_64 20 kB/s | 120 kB 00:06
PostgreSQL 9.4 30 - x86_64 16 kB/s | 111 kB 00:06
Last metadata expiration check: 0:00:01 ago on Mon 06 May 2019 10:47:09 AM EAT.
Dependencies resolved.
=====================================================================================================================================================================================================
Package Architecture Version Repository Size
=====================================================================================================================================================================================================
Installing:
postgresql11 x86_64 11.2-2PGDG.f30 pgdg11 1.7 M
postgresql11-server x86_64 11.2-2PGDG.f30 pgdg11 4.9 M
Installing dependencies:
postgresql11-libs x86_64 11.2-2PGDG.f30 pgdg11 375 k
Transaction Summary
=====================================================================================================================================================================================================
Install 3 Packages
Total download size: 6.9 M
Installed size: 32 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): postgresql11-libs-11.2-2PGDG.f30.x86_64.rpm 75 kB/s | 375 kB 00:05
(2/3): postgresql11-11.2-2PGDG.f30.x86_64.rpm 274 kB/s | 1.7 MB 00:06
(3/3): postgresql11-server-11.2-2PGDG.f30.x86_64.rpm 208 kB/s | 4.9 MB 00:23
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 296 kB/s | 6.9 MB 00:23
warning: /var/cache/dnf/pgdg11-cde8ad453ae6cd5b/packages/postgresql11-11.2-2PGDG.f30.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
PostgreSQL 11 30 - x86_64 1.6 MB/s | 1.7 kB 00:00
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
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : postgresql11-libs-11.2-2PGDG.f30.x86_64 1/3
Running scriptlet: postgresql11-libs-11.2-2PGDG.f30.x86_64 1/3
Installing : postgresql11-11.2-2PGDG.f30.x86_64 2/3
Running scriptlet: postgresql11-11.2-2PGDG.f30.x86_64 2/3
Running scriptlet: postgresql11-server-11.2-2PGDG.f30.x86_64 3/3
Installing : postgresql11-server-11.2-2PGDG.f30.x86_64 3/3
Running scriptlet: postgresql11-server-11.2-2PGDG.f30.x86_64 3/3
Verifying : postgresql11-11.2-2PGDG.f30.x86_64 1/3
Verifying : postgresql11-libs-11.2-2PGDG.f30.x86_64 2/3
Verifying : postgresql11-server-11.2-2PGDG.f30.x86_64 3/3
Installed:
postgresql11-11.2-2PGDG.f30.x86_64 postgresql11-server-11.2-2PGDG.f30.x86_64 postgresql11-libs-11.2-2PGDG.f30.x86_64
Complete!
Confirm the installed package:
$ rpm -qi postgresql11-server
Name : postgresql11-server
Version : 11.2
Release : 2PGDG.f30
Architecture: x86_64
Install Date: Mon 06 May 2019 10:49:47 AM EAT
Group : Applications/Databases
Size : 21514298
License : PostgreSQL
Signature : DSA/SHA1, Mon 01 Apr 2019 08:32:00 PM EAT, Key ID 1f16d2e1442df0f8
Source RPM : postgresql11-11.2-2PGDG.f30.src.rpm
Build Date : Mon 01 Apr 2019 08:31:35 PM EAT
Build Host : koji-fedora30-x86-64-pgbuild
Relocations : (not relocatable)
Vendor : PostgreSQL Global Development Group
URL : https://www.postgresql.org/
Summary : The programs needed to create and run a PostgreSQL server
Description :
PostgreSQL is an advanced Object-Relational database management system (DBMS).
The postgresql11-server package contains the programs needed to create
and run a PostgreSQL server, which will in turn allow you to create
and maintain PostgreSQL databases.
Step 4: Initialize the database and enable automatic start
Now that the database packages have been installed, Initialize the database by running the following command
$ sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
Initializing database ... OK
Then start and enable the service to start on boot
sudo systemctl start postgresql-11
sudo systemctl enable postgresql-11
Confirm service status.
$ systemctl status postgresql-11
● postgresql-11.service - PostgreSQL 11 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-11.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2019-05-06 10:52:19 EAT; 30s ago
Docs: https://www.postgresql.org/docs/11/static/
Process: 12779 ExecStartPre=/usr/pgsql-11/bin/postgresql-11-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 12784 (postmaster)
Tasks: 8 (limit: 2323)
Memory: 15.7M
CGroup: /system.slice/postgresql-11.service
├─12784 /usr/pgsql-11/bin/postmaster -D /var/lib/pgsql/11/data/
├─12785 postgres: logger
├─12787 postgres: checkpointer
├─12788 postgres: background writer
├─12789 postgres: walwriter
├─12790 postgres: autovacuum launcher
├─12791 postgres: stats collector
└─12792 postgres: logical replication launcher
May 06 10:52:19 myregistry.local systemd[1]: Starting PostgreSQL 11 database server...
May 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.739 EAT [12784] LOG: listening on IPv6 address "::1", port 5432
May 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.740 EAT [12784] LOG: listening on IPv4 address "127.0.0.1", port 5432
May 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.742 EAT [12784] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
May 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.743 EAT [12784] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
May 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.752 EAT [12784] LOG: redirecting log output to logging collector process
May 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.752 EAT [12784] HINT: Future log output will appear in directory "log".
May 06 10:52:19 myregistry.local systemd[1]: Started PostgreSQL 11 database server.
PostgreSQL 11 config file is/var/lib/pgsql/11/data/postgresql.conf
So, 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 on Fedora
After that, edit the file /var/lib/pgsql/11/data/postgresql.conf
and set Listen address to your server IP address or “*” for all interfaces.
$ sudo vi /var/lib/pgsql/11/data/postgresql.conf
listen_addresses = '*'
Also set PostgreSQL to accept remote connections
$ 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 192.168.18.0/24 md5
Then, restart the service
sudo systemctl restart postgresql-11
Step 6: Set PostgreSQL admin user’s password
Set PostgreSQL admin user
$ sudo su - postgres
[postgres@fed29 ~]$ psql -c "alter user postgres with password 'StrongPassword'"
ALTER ROLE
Create a test user and database
[postgres@fed ~]$ createuser test_user
[postgres@fed ~]$ createdb test_db -O test_user
[postgres@fed ~]$ grant all privileges on database test_db to test_user;
Finally, log in as a test_user user try to create a table on the Database.
Good luck and make sure to leave a comment if you encounter a problem and I’ll surely get back to you as soon as possible.
grant is not a linux shell command. Should be: psql -c “grant ….” prehaps?