In this blog, we will guide you how to install PostgreSQL on Rocky Linux. PostgreSQL is a powerful and popular open-source relational database management system. It is known for its robustness, scalability, and flexibility. Installing PostgreSQL on Rocky Linux is a straightforward process that can be done in a few easy steps.
Steps to Install PostgreSQL on Rocky Linux
Step 1: Update the System
Before installing PostgreSQL, it is recommended to update your system with the latest packages.
sudo dnf update
Step 2: Add PostgreSQL Repository
Rocky Linux does not come with the PostgreSQL package in its official repository. Therefore, we need to add the PostgreSQL repository to our system. You can do this by running the following command:
$ sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Sample output:
[sysadminxpert@RockyLinux ~]$ sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm Last metadata expiration check: 2:01:41 ago on Sat 25 Mar 2023 02:53:49 AM EDT. pgdg-redhat-repo-latest.noarch.rpm 9.6 kB/s | 13 kB 00:01 Dependencies resolved. ============================================================================================================================================================== Package Architecture Version Repository Size ============================================================================================================================================================== Installing: pgdg-redhat-repo noarch 42.0-32 @commandline 13 k Transaction Summary ============================================================================================================================================================== Install 1 Package Total size: 13 k Installed size: 14 k Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : pgdg-redhat-repo-42.0-32.noarch 1/1 Verifying : pgdg-redhat-repo-42.0-32.noarch 1/1 Installed: pgdg-redhat-repo-42.0-32.noarch Complete! [sysadminxpert@RockyLinux ~]$
Step 3: Install PostgreSQL
Disable the default postgresql module
$ sudo dnf -qy module disable postgresql
Once the PostgreSQL repository is added to your system, you can proceed with the installation of PostgreSQL by running the following command:
$ sudo dnf install -y postgresql15-server postgresql15-contrib
Sample Output:
[sysadminxpert@RockyLinux ~]$ sudo dnf install -y postgresql15-server postgresql15-contrib Last metadata expiration check: 0:06:15 ago on Sat 25 Mar 2023 05:01:41 AM EDT. Dependencies resolved. ============================================================================================================================================================== Package Architecture Version Repository Size ============================================================================================================================================================== Installing: postgresql15-contrib x86_64 15.2-1PGDG.rhel8 pgdg15 750 k postgresql15-server x86_64 15.2-1PGDG.rhel8 pgdg15 5.9 M Installing dependencies: lz4 x86_64 1.8.3-3.el8_4 baseos 102 k perl-Carp noarch 1.42-396.el8 baseos 29 k perl-Data-Dumper x86_64 2.167-399.el8 baseos 57 k perl-Digest noarch 1.17-395.el8 appstream 26 k perl-Digest-MD5 x86_64 2.55-396.el8 appstream 36 k perl-Encode x86_64 4:2.97-3.el8 baseos 1.5 M perl-Errno x86_64 1.28-421.el8 baseos 75 k perl-Exporter noarch 5.72-396.el8 baseos 33 k perl-File-Path noarch 2.15-2.el8 baseos 37 k perl-File-Temp noarch 0.230.600-1.el8 baseos 62 k perl-Getopt-Long noarch 1:2.50-4.el8 baseos 62 k perl-HTTP-Tiny noarch 0.074-1.el8 baseos 57 k perl-IO x86_64 1.38-421.el8 baseos 141 k perl-MIME-Base64 x86_64 3.15-396.el8 baseos 30 k perl-Net-SSLeay x86_64 1.88-2.module+el8.6.0+957+15d660ad appstream 378 k perl-PathTools x86_64 3.74-1.el8 baseos 89 k perl-Pod-Escapes noarch 1:1.07-395.el8 baseos 19 k perl-Pod-Perldoc noarch 3.28-396.el8 baseos 85 k perl-Pod-Simple noarch 1:3.35-395.el8 baseos 212 k perl-Pod-Usage noarch 4:1.69-395.el8 baseos 33 k perl-Scalar-List-Utils x86_64 3:1.49-2.el8 baseos 67 k perl-Socket x86_64 4:2.027-3.el8 baseos 58 k perl-Storable x86_64 1:3.11-3.el8 baseos 97 k perl-Term-ANSIColor noarch 4.06-396.el8 baseos 45 k perl-Term-Cap noarch 1.17-395.el8 baseos 22 k perl-Text-ParseWords noarch 3.30-395.el8 baseos 17 k perl-Text-Tabs+Wrap noarch 2013.0523-395.el8 baseos 23 k perl-Time-Local noarch 1:1.280-1.el8 baseos 32 k perl-URI noarch 1.73-3.el8 appstream 115 k perl-Unicode-Normalize x86_64 1.25-396.el8 baseos 81 k perl-constant noarch 1.33-396.el8 baseos 24 k perl-interpreter x86_64 4:5.26.3-421.el8 baseos 6.3 M perl-libnet noarch 3.11-3.el8 appstream 120 k perl-libs x86_64 4:5.26.3-421.el8 baseos 1.6 M perl-macros x86_64 4:5.26.3-421.el8 baseos 71 k perl-parent noarch 1:0.237-1.el8 baseos 19 k perl-podlators noarch 4.11-1.el8 baseos 117 k perl-threads x86_64 1:2.21-2.el8 baseos 60 k perl-threads-shared x86_64 1.58-2.el8 baseos 47 k postgresql15 x86_64 15.2-1PGDG.rhel8 pgdg15 1.6 M postgresql15-libs x86_64 15.2-1PGDG.rhel8 pgdg15 293 k Installing weak dependencies: perl-IO-Socket-IP noarch 0.39-5.el8 appstream 46 k perl-IO-Socket-SSL noarch 2.066-4.module+el8.6.0+957+15d660ad appstream 297 k perl-Mozilla-CA noarch 20160104-7.module+el8.6.0+965+850557f9 appstream 14 k Enabling module streams: perl 5.26 perl-IO-Socket-SSL 2.066 perl-libwww-perl 6.34 Transaction Summary ============================================================================================================================================================== Install 46 Packages Total download size: 21 M Installed size: 71 M Downloading Packages: (1/46): perl-Digest-MD5-2.55-396.el8.x86_64.rpm 6.3 kB/s | 36 kB 00:05 (2/46): perl-Digest-1.17-395.el8.noarch.rpm 4.5 kB/s | 26 kB 00:05 (3/46): perl-IO-Socket-IP-0.39-5.el8.noarch.rpm 7.9 kB/s | 46 kB 00:05 (4/46): perl-Mozilla-CA-20160104-7.module+el8.6.0+965+850557f9.noarch.rpm 121 kB/s | 14 kB 00:00 (5/46): perl-IO-Socket-SSL-2.066-4.module+el8.6.0+957+15d660ad.noarch.rpm 864 kB/s | 297 kB 00:00 (6/46): perl-Net-SSLeay-1.88-2.module+el8.6.0+957+15d660ad.x86_64.rpm 837 kB/s | 378 kB 00:00 (7/46): perl-libnet-3.11-3.el8.noarch.rpm 391 kB/s | 120 kB 00:00 (8/46): lz4-1.8.3-3.el8_4.x86_64.rpm 602 kB/s | 102 kB 00:00 (9/46): perl-URI-1.73-3.el8.noarch.rpm 179 kB/s | 115 kB 00:00 (10/46): perl-Carp-1.42-396.el8.noarch.rpm 148 kB/s | 29 kB 00:00 (11/46): perl-Data-Dumper-2.167-399.el8.x86_64.rpm 278 kB/s | 57 kB 00:00 (12/46): perl-Errno-1.28-421.el8.x86_64.rpm 333 kB/s | 75 kB 00:00 (13/46): perl-Encode-2.97-3.el8.x86_64.rpm 2.3 MB/s | 1.5 MB 00:00 (14/46): perl-Exporter-5.72-396.el8.noarch.rpm 45 kB/s | 33 kB 00:00 (15/46): perl-File-Path-2.15-2.el8.noarch.rpm 55 kB/s | 37 kB 00:00 (16/46): perl-File-Temp-0.230.600-1.el8.noarch.rpm 143 kB/s | 62 kB 00:00 (17/46): perl-Getopt-Long-2.50-4.el8.noarch.rpm 183 kB/s | 62 kB 00:00 (18/46): perl-HTTP-Tiny-0.074-1.el8.noarch.rpm 171 kB/s | 57 kB 00:00 (19/46): perl-IO-1.38-421.el8.x86_64.rpm 487 kB/s | 141 kB 00:00 (20/46): perl-MIME-Base64-3.15-396.el8.x86_64.rpm 141 kB/s | 30 kB 00:00 (21/46): perl-PathTools-3.74-1.el8.x86_64.rpm 349 kB/s | 89 kB 00:00 (22/46): perl-Pod-Escapes-1.07-395.el8.noarch.rpm 64 kB/s | 19 kB 00:00 (23/46): perl-Pod-Perldoc-3.28-396.el8.noarch.rpm 235 kB/s | 85 kB 00:00 (24/46): perl-Pod-Simple-3.35-395.el8.noarch.rpm 894 kB/s | 212 kB 00:00 (25/46): perl-Pod-Usage-1.69-395.el8.noarch.rpm 122 kB/s | 33 kB 00:00 (26/46): perl-Scalar-List-Utils-1.49-2.el8.x86_64.rpm 297 kB/s | 67 kB 00:00 (27/46): perl-Socket-2.027-3.el8.x86_64.rpm 311 kB/s | 58 kB 00:00 (28/46): perl-Storable-3.11-3.el8.x86_64.rpm 598 kB/s | 97 kB 00:00 (29/46): perl-Term-ANSIColor-4.06-396.el8.noarch.rpm 280 kB/s | 45 kB 00:00 (30/46): perl-Term-Cap-1.17-395.el8.noarch.rpm 144 kB/s | 22 kB 00:00 (31/46): perl-Text-ParseWords-3.30-395.el8.noarch.rpm 140 kB/s | 17 kB 00:00 (32/46): perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch.rpm 141 kB/s | 23 kB 00:00 (33/46): perl-Time-Local-1.280-1.el8.noarch.rpm 185 kB/s | 32 kB 00:00 (34/46): perl-Unicode-Normalize-1.25-396.el8.x86_64.rpm 602 kB/s | 81 kB 00:00 (35/46): perl-constant-1.33-396.el8.noarch.rpm 258 kB/s | 24 kB 00:00 (36/46): perl-macros-5.26.3-421.el8.x86_64.rpm 169 kB/s | 71 kB 00:00 (37/46): perl-libs-5.26.3-421.el8.x86_64.rpm 1.6 MB/s | 1.6 MB 00:00 (38/46): perl-parent-0.237-1.el8.noarch.rpm 19 kB/s | 19 kB 00:01 (39/46): perl-podlators-4.11-1.el8.noarch.rpm 157 kB/s | 117 kB 00:00 (40/46): perl-threads-2.21-2.el8.x86_64.rpm 120 kB/s | 60 kB 00:00 (41/46): perl-threads-shared-1.58-2.el8.x86_64.rpm 123 kB/s | 47 kB 00:00 (42/46): perl-interpreter-5.26.3-421.el8.x86_64.rpm 2.1 MB/s | 6.3 MB 00:02 (43/46): postgresql15-contrib-15.2-1PGDG.rhel8.x86_64.rpm 192 kB/s | 750 kB 00:03 (44/46): postgresql15-15.2-1PGDG.rhel8.x86_64.rpm 381 kB/s | 1.6 MB 00:04 (45/46): postgresql15-libs-15.2-1PGDG.rhel8.x86_64.rpm 83 kB/s | 293 kB 00:03 (46/46): postgresql15-server-15.2-1PGDG.rhel8.x86_64.rpm 931 kB/s | 5.9 MB 00:06 -------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 627 kB/s | 21 MB 00:33 warning: /var/cache/dnf/pgdg15-6354961cb227a0b2/packages/postgresql15-15.2-1PGDG.rhel8.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY PostgreSQL 15 for RHEL / Rocky 8 - x86_64 778 kB/s | 1.7 kB 00:00 Importing GPG key 0x442DF0F8: Userid : "PostgreSQL RPM Building Project <pgsql-pkg-yum@postgresql.org>" Fingerprint: 68C9 E2B9 1A37 D136 FE74 D176 1F16 D2E1 442D F0F8 From : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : postgresql15-libs-15.2-1PGDG.rhel8.x86_64 1/46 Running scriptlet: postgresql15-libs-15.2-1PGDG.rhel8.x86_64 1/46 Installing : perl-Digest-1.17-395.el8.noarch 2/46 Installing : perl-Digest-MD5-2.55-396.el8.x86_64 3/46 Installing : perl-Data-Dumper-2.167-399.el8.x86_64 4/46 Installing : perl-libnet-3.11-3.el8.noarch 5/46 Installing : perl-Net-SSLeay-1.88-2.module+el8.6.0+957+15d660ad.x86_64 6/46 Installing : perl-URI-1.73-3.el8.noarch 7/46 Installing : perl-Pod-Escapes-1:1.07-395.el8.noarch 8/46 Installing : perl-Mozilla-CA-20160104-7.module+el8.6.0+965+850557f9.noarch 9/46 Installing : perl-IO-Socket-IP-0.39-5.el8.noarch 10/46 Installing : perl-Time-Local-1:1.280-1.el8.noarch 11/46 Installing : perl-IO-Socket-SSL-2.066-4.module+el8.6.0+957+15d660ad.noarch 12/46 Installing : perl-Term-ANSIColor-4.06-396.el8.noarch 13/46 Installing : perl-Term-Cap-1.17-395.el8.noarch 14/46 Installing : perl-File-Temp-0.230.600-1.el8.noarch 15/46 Installing : perl-Pod-Simple-1:3.35-395.el8.noarch 16/46 Installing : perl-HTTP-Tiny-0.074-1.el8.noarch 17/46 Installing : perl-podlators-4.11-1.el8.noarch 18/46 Installing : perl-Pod-Perldoc-3.28-396.el8.noarch 19/46 Installing : perl-Text-ParseWords-3.30-395.el8.noarch 20/46 Installing : perl-Pod-Usage-4:1.69-395.el8.noarch 21/46 Installing : perl-MIME-Base64-3.15-396.el8.x86_64 22/46 Installing : perl-Storable-1:3.11-3.el8.x86_64 23/46 Installing : perl-Getopt-Long-1:2.50-4.el8.noarch 24/46 Installing : perl-Errno-1.28-421.el8.x86_64 25/46 Installing : perl-Socket-4:2.027-3.el8.x86_64 26/46 Installing : perl-Encode-4:2.97-3.el8.x86_64 27/46 Installing : perl-Carp-1.42-396.el8.noarch 28/46 Installing : perl-Exporter-5.72-396.el8.noarch 29/46 Installing : perl-libs-4:5.26.3-421.el8.x86_64 30/46 Installing : perl-Scalar-List-Utils-3:1.49-2.el8.x86_64 31/46 Installing : perl-parent-1:0.237-1.el8.noarch 32/46 Installing : perl-macros-4:5.26.3-421.el8.x86_64 33/46 Installing : perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch 34/46 Installing : perl-Unicode-Normalize-1.25-396.el8.x86_64 35/46 Installing : perl-File-Path-2.15-2.el8.noarch 36/46 Installing : perl-IO-1.38-421.el8.x86_64 37/46 Installing : perl-PathTools-3.74-1.el8.x86_64 38/46 Installing : perl-constant-1.33-396.el8.noarch 39/46 Installing : perl-threads-1:2.21-2.el8.x86_64 40/46 Installing : perl-threads-shared-1.58-2.el8.x86_64 41/46 Installing : perl-interpreter-4:5.26.3-421.el8.x86_64 42/46 Installing : lz4-1.8.3-3.el8_4.x86_64 43/46 Installing : postgresql15-15.2-1PGDG.rhel8.x86_64 44/46 Running scriptlet: postgresql15-15.2-1PGDG.rhel8.x86_64 44/46 Running scriptlet: postgresql15-server-15.2-1PGDG.rhel8.x86_64 45/46 Installing : postgresql15-server-15.2-1PGDG.rhel8.x86_64 45/46 Running scriptlet: postgresql15-server-15.2-1PGDG.rhel8.x86_64 45/46 Installing : postgresql15-contrib-15.2-1PGDG.rhel8.x86_64 46/46 Running scriptlet: postgresql15-contrib-15.2-1PGDG.rhel8.x86_64 46/46 Verifying : perl-Digest-1.17-395.el8.noarch 1/46 Verifying : perl-Digest-MD5-2.55-396.el8.x86_64 2/46 Verifying : perl-IO-Socket-IP-0.39-5.el8.noarch 3/46 Verifying : perl-IO-Socket-SSL-2.066-4.module+el8.6.0+957+15d660ad.noarch 4/46 Verifying : perl-Mozilla-CA-20160104-7.module+el8.6.0+965+850557f9.noarch 5/46 Verifying : perl-Net-SSLeay-1.88-2.module+el8.6.0+957+15d660ad.x86_64 6/46 Verifying : perl-URI-1.73-3.el8.noarch 7/46 Verifying : perl-libnet-3.11-3.el8.noarch 8/46 Verifying : lz4-1.8.3-3.el8_4.x86_64 9/46 Verifying : perl-Carp-1.42-396.el8.noarch 10/46 Verifying : perl-Data-Dumper-2.167-399.el8.x86_64 11/46 Verifying : perl-Encode-4:2.97-3.el8.x86_64 12/46 Verifying : perl-Errno-1.28-421.el8.x86_64 13/46 Verifying : perl-Exporter-5.72-396.el8.noarch 14/46 Verifying : perl-File-Path-2.15-2.el8.noarch 15/46 Verifying : perl-File-Temp-0.230.600-1.el8.noarch 16/46 Verifying : perl-Getopt-Long-1:2.50-4.el8.noarch 17/46 Verifying : perl-HTTP-Tiny-0.074-1.el8.noarch 18/46 Verifying : perl-IO-1.38-421.el8.x86_64 19/46 Verifying : perl-MIME-Base64-3.15-396.el8.x86_64 20/46 Verifying : perl-PathTools-3.74-1.el8.x86_64 21/46 Verifying : perl-Pod-Escapes-1:1.07-395.el8.noarch 22/46 Verifying : perl-Pod-Perldoc-3.28-396.el8.noarch 23/46 Verifying : perl-Pod-Simple-1:3.35-395.el8.noarch 24/46 Verifying : perl-Pod-Usage-4:1.69-395.el8.noarch 25/46 Verifying : perl-Scalar-List-Utils-3:1.49-2.el8.x86_64 26/46 Verifying : perl-Socket-4:2.027-3.el8.x86_64 27/46 Verifying : perl-Storable-1:3.11-3.el8.x86_64 28/46 Verifying : perl-Term-ANSIColor-4.06-396.el8.noarch 29/46 Verifying : perl-Term-Cap-1.17-395.el8.noarch 30/46 Verifying : perl-Text-ParseWords-3.30-395.el8.noarch 31/46 Verifying : perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch 32/46 Verifying : perl-Time-Local-1:1.280-1.el8.noarch 33/46 Verifying : perl-Unicode-Normalize-1.25-396.el8.x86_64 34/46 Verifying : perl-constant-1.33-396.el8.noarch 35/46 Verifying : perl-interpreter-4:5.26.3-421.el8.x86_64 36/46 Verifying : perl-libs-4:5.26.3-421.el8.x86_64 37/46 Verifying : perl-macros-4:5.26.3-421.el8.x86_64 38/46 Verifying : perl-parent-1:0.237-1.el8.noarch 39/46 Verifying : perl-podlators-4.11-1.el8.noarch 40/46 Verifying : perl-threads-1:2.21-2.el8.x86_64 41/46 Verifying : perl-threads-shared-1.58-2.el8.x86_64 42/46 Verifying : postgresql15-15.2-1PGDG.rhel8.x86_64 43/46 Verifying : postgresql15-contrib-15.2-1PGDG.rhel8.x86_64 44/46 Verifying : postgresql15-libs-15.2-1PGDG.rhel8.x86_64 45/46 Verifying : postgresql15-server-15.2-1PGDG.rhel8.x86_64 46/46 Installed: lz4-1.8.3-3.el8_4.x86_64 perl-Carp-1.42-396.el8.noarch perl-Data-Dumper-2.167-399.el8.x86_64 perl-Digest-1.17-395.el8.noarch perl-Digest-MD5-2.55-396.el8.x86_64 perl-Encode-4:2.97-3.el8.x86_64 perl-Errno-1.28-421.el8.x86_64 perl-Exporter-5.72-396.el8.noarch perl-File-Path-2.15-2.el8.noarch perl-File-Temp-0.230.600-1.el8.noarch perl-Getopt-Long-1:2.50-4.el8.noarch perl-HTTP-Tiny-0.074-1.el8.noarch perl-IO-1.38-421.el8.x86_64 perl-IO-Socket-IP-0.39-5.el8.noarch perl-IO-Socket-SSL-2.066-4.module+el8.6.0+957+15d660ad.noarch perl-MIME-Base64-3.15-396.el8.x86_64 perl-Mozilla-CA-20160104-7.module+el8.6.0+965+850557f9.noarch perl-Net-SSLeay-1.88-2.module+el8.6.0+957+15d660ad.x86_64 perl-PathTools-3.74-1.el8.x86_64 perl-Pod-Escapes-1:1.07-395.el8.noarch perl-Pod-Perldoc-3.28-396.el8.noarch perl-Pod-Simple-1:3.35-395.el8.noarch perl-Pod-Usage-4:1.69-395.el8.noarch perl-Scalar-List-Utils-3:1.49-2.el8.x86_64 perl-Socket-4:2.027-3.el8.x86_64 perl-Storable-1:3.11-3.el8.x86_64 perl-Term-ANSIColor-4.06-396.el8.noarch perl-Term-Cap-1.17-395.el8.noarch perl-Text-ParseWords-3.30-395.el8.noarch perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch perl-Time-Local-1:1.280-1.el8.noarch perl-URI-1.73-3.el8.noarch perl-Unicode-Normalize-1.25-396.el8.x86_64 perl-constant-1.33-396.el8.noarch perl-interpreter-4:5.26.3-421.el8.x86_64 perl-libnet-3.11-3.el8.noarch perl-libs-4:5.26.3-421.el8.x86_64 perl-macros-4:5.26.3-421.el8.x86_64 perl-parent-1:0.237-1.el8.noarch perl-podlators-4.11-1.el8.noarch perl-threads-1:2.21-2.el8.x86_64 perl-threads-shared-1.58-2.el8.x86_64 postgresql15-15.2-1PGDG.rhel8.x86_64 postgresql15-contrib-15.2-1PGDG.rhel8.x86_64 postgresql15-libs-15.2-1PGDG.rhel8.x86_64 postgresql15-server-15.2-1PGDG.rhel8.x86_64 Complete! [sysadminxpert@RockyLinux ~]$
This command installs PostgreSQL version 15 along with the contrib package that provides additional functionalities such as extensions and plugins.
Confirm the version:
[sysadminxpert@RockyLinux ~]$ psql -V psql (PostgreSQL) 15.2
Step 4: Initialize PostgreSQL Database
After the installation of PostgreSQL, you need to initialize the database cluster by running the following command:
$ sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
Sample output:
[sysadminxpert@RockyLinux ~]$ sudo /usr/pgsql-15/bin/postgresql-15-setup initdb [sudo] password for sysadminxpert: Initializing database ... OK [sysadminxpert@RockyLinux ~]$
Step 5: Start PostgreSQL Service
Once the database cluster is initialized, you can start the PostgreSQL service by running the following command.
$ sudo systemctl start postgresql-15
To check the status of the PostgreSQL service, you can run the following command:
$ sudo systemctl status postgresql-15
Step 6: Enable PostgreSQL Service
To ensure that PostgreSQL starts automatically at boot time, you need to enable the PostgreSQL service by running the following command:
$ sudo systemctl enable postgresql-15
Sample output:
[sysadminxpert@RockyLinux ~]$ sudo systemctl enable postgresql-15 Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-15.service → /usr/lib/systemd/system/postgresql-15.service. [sysadminxpert@RockyLinux ~]$
Step 7: Connect to PostgreSQL
You can use the psql command-line tool to connect to the PostgreSQL server. By default, PostgreSQL creates a user called Postgres with the superuser role. You can connect to the PostgreSQL server using the following command:
sudo -u postgres psql
This command will connect you to the PostgreSQL server with the Postgres user.
Step 8: Create a New User and Database
To create a new user and database, you need to connect to the PostgreSQL server and run the following commands:
CREATE USER myuser WITH PASSWORD 'mypassword'; CREATE DATABASE mydb; GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
These commands will create a new user called myuser with the password mypassword and a new database named mydb. The third command grants all privileges on the mydb database to the myuser user.
Conclusion
In this blog, we have shown you how to install PostgreSQL on Rocky Linux. We have covered the installation process, initializing the database cluster, starting the PostgreSQL service, enabling the service at boot time, connecting to PostgreSQL, and creating a new user and database. With this knowledge, you can start building robust and scalable applications using PostgreSQL.
Frequently Asked Questions (FAQs)
Q1: Why choose PostgreSQL for Linux environments?
A1: PostgreSQL is known for its robust features, extensibility, and strong community support. It’s an excellent choice for Linux users seeking a powerful and open-source relational database management system.
Q2: Can I install PostgreSQL on both Rocky Linux and AlmaLinux using the same procedure?
A2: Yes, the installation procedure for PostgreSQL is generally consistent across Rocky Linux and AlmaLinux. Follow this guide for a successful installation on either distribution.
Q3: Are there specific security considerations during PostgreSQL installation?
A3: Yes, ensuring secure configurations is crucial. This guide includes steps to configure authentication methods and access controls to enhance the security of your PostgreSQL installation.
Q4: How do I check if PostgreSQL is running on my system?
A4: Utilize system commands or connect to PostgreSQL using the psql
command-line tool to verify if the service is running and accessible.
Q5: Can I install multiple versions of PostgreSQL on the same system?
A5: Yes, you can install multiple versions of PostgreSQL on a single system. However, careful consideration of port configurations and service management is necessary to avoid conflicts.