7

Install PostgreSQL 14 on Fedora 35/34/33/32/31

 2 years ago
source link: https://computingforgeeks.com/install-postgresql-database-fedora-linux/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Install PostgreSQL 14 on Fedora 35/34/33/32/31
Search

In this blog post we will look at the installation of PostgreSQL 14 on Fedora 35/34/33/32/31. PostgreSQL is a free to use and powerful relational database management system. PostgreSQL has been in active development for over 30 years and has earned a strong reputation in its reliability, robustness, and performance. As of this article update, the latest stable release of PostgreSQL is version 14.

This new release of PostgreSQL 14 comes with several new features designed to ease administration and development of intense data-driven applications. Some of the improvements are in complex data types support, logical replication, connection concurrency, query parallelism, and high-write workloads among many other features and improvements.

Some highlights in PostgreSQL 14 release

Below are some enhancements in PostgreSQL 14 database management system:

  • Significant performance increases through parallel queries, heavily concurrent workloads, partitioned databases, logical replication, and vacuuming.
  • JSON Conveniences and multiranges- enabling the representation of non-contiguous data ranges.
  • OUT parameters can now be used to return data from stored procedures.
  • Subscripting operators have been added to the jsonb and hstore types.
  • Supports pipelined queries through libpq, which can significantly increase throughput over high-latency connections.
  • Updates to B-tree indexes are more efficiently managed, resulting in less index bloat.
  • Security enhancements

The PostgreSQL team provides and maintains a YUM repository with pre-built binary packages of PostgreSQL. We’ll be adding the repository to our Fedora system and install PostgreSQL 14 on Fedora 35/34/33/32/31 Linux system. We’ll also cover installation of PostgreSQL 14 on Fedora Linux from the OS AppStream repositories.

Step 1: Install PostgreSQL 14 on Fedora 35/34/33/32/31

You can choose option 1 or 2 to Install PostgreSQL 14 on Fedora 35/34/33/32/31;

Option 1: Install PostgreSQL 14 on Fedora from OS AppStream repo

In newer releases of Fedora, PostgreSQL 14 is available in system provided AppStream module. Start by resetting PostgreSQL module:

sudo dnf module reset postgresql -y

Then enable the PostgreSQL 14 module with the commands below:

$ sudo dnf module enable postgresql:14
Dependencies resolved.
======================================================================================================================================================================================================
 Package                                         Architecture                                   Version                                         Repository                                       Size
======================================================================================================================================================================================================
Enabling module streams:
 postgresql                                                                                     14

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

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

When done install PostgreSQL 14 on Fedora Linux system:

sudo dnf install vim postgresql-server postgresql

Accept all installation prompts:

Dependencies resolved.
======================================================================================================================================================================================================
 Package                                            Architecture                      Version                                                        Repository                                  Size
======================================================================================================================================================================================================
Installing:
 postgresql                                         x86_64                            14.0-1.module_f35+13197+dca6e3a6                               updates-modular                            1.6 M
 postgresql-server                                  x86_64                            14.0-1.module_f35+13197+dca6e3a6                               updates-modular                            6.3 M
Installing dependencies:
 postgresql-private-libs                            x86_64                            14.0-1.module_f35+13197+dca6e3a6                               updates-modular                            135 k

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

Total download size: 8.0 M
Installed size: 31 M
Is this ok [y/N]: y

Option 2 – Install PostgreSQL 14 on Fedora from PostgreSQL repo

If PostgreSQL 14 packages are not in the AppStream repositories on your Fedora Linux system, you’ve to add PostgreSQL repositories manually to the system.

Add the PostgreSQL Yum Repository

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

Fedora 35:

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

Fedora 34:

sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-34-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

Fedora 31:

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

Fedora 30:

sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-30-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-20                                       @commandline                                      10 k

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

Total size: 10 k
Installed size: 11 k
Is this ok [y/N]: y

Install PostgreSQL 14 on Fedora35/34/33/32/31

Once the PostgreSQL repository is added to your Fedora system, install PostgreSQL 14 Server and Client packages:

sudo dnf module reset postgresql -y
sudo dnf install vim postgresql14-server postgresql14

Agree to the installation prompts that you receive.

Dependencies resolved.
======================================================================================================================================================================================================
 Package                                                Architecture                              Version                                             Repository                                 Size
======================================================================================================================================================================================================
Installing:
 postgresql14-server                                    x86_64                                    14.1-1PGDG.f35                                      pgdg14                                    5.9 M
Installing dependencies:
 lz4                                                    x86_64                                    1.9.3-3.fc35                                        fedora                                     57 k
 postgresql14                                           x86_64                                    14.1-1PGDG.f35                                      pgdg14                                    1.4 M
 postgresql14-libs                                      x86_64                                    14.1-1PGDG.f35                                      pgdg14                                    277 k

Transaction Summary
======================================================================================================================================================================================================
Install  4 Packages

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

Agree to import all repository GPG keys as prompted:

Total                                                                                                                              13 MB/s |  18 MB     00:01
warning: /var/cache/dnf/pgdg13-5b69a3a370fb59a8/packages/postgresql14-14.1-3PGDG.f33.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
PostgreSQL 14 for Fedora 33 - 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

Step 2 – Initialize PostgreSQL 14 database on Fedora

Run the commands below to initialize the database:

# AppStream PostgreSQL install
$ sudo postgresql-setup --initdb
* Initializing database in '/var/lib/pgsql/data'
 * Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log

# PostgreSQL Repo install
$ sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
Initializing database ... OK

Start and enable postgresql database service:

# AppStream PostgreSQL install
$ sudo systemctl enable --now postgresql

# PostgreSQL Repo install
$ sudo systemctl enable --now postgresql-14
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-14.service → /usr/lib/systemd/system/postgresql-14.service.

Confirm service status.

$ systemctl status postgresql
## OR ##
$ systemctl status postgresql-14
● postgresql-14.service - PostgreSQL 14 database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql-14.service; enabled; vendor preset: disabled)
     Active: active (running) since Wed 2021-11-17 10:19:09 UTC; 46s ago
       Docs: https://www.postgresql.org/docs/14/static/
    Process: 8167 ExecStartPre=/usr/pgsql-14/bin/postgresql-14-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
   Main PID: 8172 (postmaster)
      Tasks: 8 (limit: 2320)
     Memory: 16.0M
        CPU: 72ms
     CGroup: /system.slice/postgresql-14.service
             ├─8172 /usr/pgsql-14/bin/postmaster -D /var/lib/pgsql/14/data/
             ├─8173 "postgres: logger " "" "" "" "" "" "" "" "" "" "" "" "" 
             ├─8175 "postgres: checkpointer " "" "" "" "" "" "" "" "" "" "" 
             ├─8176 "postgres: background writer " "" "" "" "" "" "" "" "" " 
             ├─8177 "postgres: walwriter " "" "" "" "" "" "" "" "" "" "" "" "
             ├─8178 "postgres: autovacuum launcher " "" "" "" "" "" "" "" "" "
             ├─8179 "postgres: stats collector " "" "" "" "" "" "" "" "" "" ""
             └─8180 "postgres: logical replication launcher " "" "" "" "" "" ""
Nov 17 13:17:28 fedora-35.lab systemd[1]: Starting PostgreSQL database server...
Nov 17 13:17:28 fedora-35.lab postmaster[38315]: 2021-11-17 13:17:28.564 EAT [38315] LOG:  redirecting log output to logging collector process
Nov 17 13:17:28 fedora-35.lab postmaster[38315]: 2021-11-17 13:17:28.564 EAT [38315] HINT:  Future log output will appear in directory "log".
Nov 17 13:17:28 fedora-35.lab systemd[1]: Started PostgreSQL database server.

Step 3 – Enable remote Access to PostgreSQL (Optional)

If you have remote applications connecting to this PostgreSQL server, you should allow postgresql service on firewalld if running.

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

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

# AppStream PostgreSQL install
$ sudo vim /var/lib/pgsql/data/postgresql.conf
listen_addresses = '*'

# PostgreSQL Repo install
$ sudo vi /var/lib/pgsql/14/data/postgresql.conf 
listen_addresses = '*'

Also set PostgreSQL to accept remote connections from allowed hosts.

# AppStream PostgreSQL install
$ sudo vim /var/lib/pgsql/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

# PostgreSQL Repo install
$ sudo vim /var/lib/pgsql/14/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 14 service after making the change.

sudo systemctl restart postgresql
## OR ##
sudo systemctl restart postgresql-14

Step 4 – Set PostgreSQL admin user’s (postgres) password

In this step you can set PostgreSQL admin user password.

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

Replace StrongDBPassword with the new password for postgres user.

Step 5 – Install pgAdmin 4 Web Management

pgAdmin is a popular and feature rich Open Source administration and development platform for PostgreSQL database systems. Refer to our guide in the link below for a step-by-step installation:

Best Video courses to Learn PostgreSQL Database:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK