Install PostgreSQL 17 on Arch|Manjaro|Garuda

PostgreSQL is an open-source object-relational database system that can reliably store and grow even the most complex data demands. Users may rely on the PostgreSQL database system for its dependability, data integrity, extensive feature set, and flexibility. To assure innovation and a solid reputation, it has a huge community behind it. Thousands of businesses rely on PostgreSQL to support financial transactions, massive website traffic, and e-commerce systems, among other things. Custom functions written in programming languages such as Java, Python, C/C++, and others can also be added.

In this tutorial, we’ll look at how to install PostgreSQL 17 on Arch Linux | Manjaro | Garuda Linux.

Where is PostgreSQL used?

The following list illustrates some of the ways PostgreSQL is or may be utilized in the real world scenarios.

  • GIS data from the government: PostgreSQL offers a sophisticated GIS extension called “PostGIS” that contains hundreds of functions for processing geometric data in various formats. PostGIS is one of the power standards in the Open Source GIS industry, as it is extremely standard compliant.
  • Financial sector: PostgreSQL is well-suited to the financial sector. PostgreSQL is completely ACID compliant, making it excellent for OLTP workloads (Online Transaction Processing).
  • Data generated by scientific initiatives might amount to terabytes, which must be managed in the most useful and effective manner feasible. PostgreSQL has excellent analytical capabilities and a robust SQL engine that makes handling huge volumes of data a breeze.
  • Web technologies and NoSQL workloads: To service your consumers, modern websites may demand thousands or even hundreds of thousands of requests per second. Scalability is a key concern, and the PostgreSQL community has been working hard to solve such concerns in recent years.
  • Manufacturing: Many world-class industrial manufacturers utilize PostgreSQL as a storage backend to speed up innovation and drive growth through customer-centric operations, as well as to enhance supply chain performance. PostgreSQL is a long-term data store that provides you with secure storage at a cheap cost.

Top Features of PostgreSQL database

The following are some of PostgreSQL’s key features:

  • Different data kinds, as well as user-defined types, are supported.
  • Inheritance in tables.
  • Ensures data integrity by ensuring the integrity of foreign key referential.
  • High levels of protection.
  • Extensibility.
  • Transactions nested.
  • Supports asynchronous replication and point-in-time recovery for reliability and disaster recovery.
  • Locking mechanism with a high level of sophistication.

Install PostgreSQL on Arch | Manjaro | Garuda

With the following steps, we will install PostgreSQL 17 on Arch | Manjaro | Garuda Linus OS.

Step 1: Update System Packages

Linux users should always upgrade their operating system packages to the most recent versions available from upstream sources.

Run the following command to update and upgrade system packages before installation:

sudo pacman -Syu

Reboot the system:

sudo reboot

Step 2: Install PostgreSQL 17

Following the reboot, install PostgreSQL from the AUR on Arch | Manjaro | Garuda Linux:

sudo pacman -S postgresql vim

Accept the installation prompt to proceed:

resolving dependencies...
looking for conflicting packages...

Package (3)            Old Version  New Version  Net Change  Download Size

extra/postgresql-libs               17.2-3         8.62 MiB       1.68 MiB
extra/postgresql                    17.2-3        65.00 MiB      18.97 MiB
extra/vim              9.1.1120-1   9.1.1120-1     0.00 MiB               

Total Download Size:   20.65 MiB
Total Installed Size:  78.55 MiB
Net Upgrade Size:      73.63 MiB

:: Proceed with installation? [Y/n] Y

We can confirm PostgreSQL installed version:

$ postgres --version
postgres (PostgreSQL) 17.2

Set applicable entries in /etc/locale.gen:

echo "en_US.UTF-8 UTF-8" | sudo tee /etc/locale.gen

Then run locale-gen to generate locale settings:

$ sudo locale-gen
Generating locales...
  en_US.UTF-8... done
Generation complete.

Step 3: PostgreSQL Service Management

Now check PostgreSQL status with the following command:

$ systemctl status postgresql       
○ postgresql.service - PostgreSQL database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
     Active: inactive (dead)
       Docs: man:postgres(1)     

In the above output we have seen that PostgreSQL is inactive and dead. Before we can start and enable PostgreSQL, we need to initialize PostgreSQL data directory.

You must first login as the postgres user using the following command before you can initialize PostgreSQL’s data directory:

sudo su - postgres

With the following command, you can now initialize PostgreSQL’s data directory:

$ initdb --locale en_US.UTF-8 -D /var/lib/postgres/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgres/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default "max_connections" ... 100
selecting default "shared_buffers" ... 128MB
selecting default time zone ... Africa/Nairobi
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /var/lib/postgres/data -l logfile start

Now logout postgres use and start PostgreSQL:

$ exit
logout

Start PostgreSQL:

sudo systemctl start postgresql

Then enable PostgreSQL:

sudo systemctl enable postgresql

Check if PostgreSQL is active and running:

$ systemctl status postgresql
 postgresql.service - PostgreSQL database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; preset: disabled)
     Active: active (running) since Tue 2025-02-25 09:31:47 EAT; 13s ago
 Invocation: ec36d14d282b4957a800a38b36f3e598
       Docs: man:postgres(1)
   Main PID: 3806 (postgres)
      Tasks: 6 (limit: 7074)
     Memory: 17.8M (peak: 18.4M)
        CPU: 101ms
     CGroup: /system.slice/postgresql.service
             ├─3806 /usr/bin/postgres -D /var/lib/postgres/data
             ├─3809 "postgres: checkpointer "
             ├─3810 "postgres: background writer "
             ├─3812 "postgres: walwriter "
             ├─3813 "postgres: autovacuum launcher "
             └─3814 "postgres: logical replication launcher "

Feb 25 09:31:46 garuda.cloudspinx.com systemd[1]: Starting PostgreSQL database server...
Feb 25 09:31:47 garuda.cloudspinx.com postgres[3806]: 2025-02-25 09:31:47.076 EAT [3806] LOG:  starting PostgreSQL 17.2 on x86_64-pc-linux-gnu, c>
Feb 25 09:31:47 garuda.cloudspinx.com postgres[3806]: 2025-02-25 09:31:47.077 EAT [3806] LOG:  listening on IPv6 address "::1", port 5432
Feb 25 09:31:47 garuda.cloudspinx.com postgres[3806]: 2025-02-25 09:31:47.077 EAT [3806] LOG:  listening on IPv4 address "127.0.0.1", port 5432
Feb 25 09:31:47 garuda.cloudspinx.com postgres[3806]: 2025-02-25 09:31:47.080 EAT [3806] LOG:  listening on Unix socket "/run/postgresql/.s.PGSQL>
Feb 25 09:31:47 garuda.cloudspinx.com postgres[3811]: 2025-02-25 09:31:47.085 EAT [3811] LOG:  database system was shut down at 2025-02-25 09:30:>
Feb 25 09:31:47 garuda.cloudspinx.com postgres[3806]: 2025-02-25 09:31:47.091 EAT [3806] LOG:  database system is ready to accept connections
Feb 25 09:31:47 garuda.cloudspinx.com systemd[1]: Started PostgreSQL database server.

Now that PostgreSQL is active and running we can create databases and users as shown below.

Create Database in PostgreSQL

To create a database, connect to PostgreSQL. A default user named ‘postgres‘ is established when PostgreSQL is installed. Connect to this user first. We will create a database called mydb.

$ sudo su - postgres
[postgres@garuda ~]$

Now you are logged in as postgres user, secure this default postgres user with a strong password using the following command:

$ psql -c "alter user postgres with password 'StrongPassword'"
ALTER ROLE

To execute Postgresql commands, type the following command into the PostgreSQL command prompt:

$ psql
psql (17.2)
Type "help" for help.

Run the following command to create a database:

# CREATE DATABASE mydb;
CREATE DATABASE

Confirm created database above as well listing available databases:

# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 mydb      | postgres | 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/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)
Create User in PostgreSQL

Run the following commands to create a user postgreuser and allow them access to the database we created above:

# CREATE USER postgreuser WITH ENCRYPTED PASSWORD 'MyPassword';
CREATE ROLE

# GRANT ALL PRIVILEGES ON DATABASE mydb to postgreuser;
GRANT

Run the following to connect to the database we created above:

# \c mydb
You are now connected to database "mydb" as user "postgres".
mydb=#

Step 4: Changing PostgreSQL Service Port

Check the default port the PostgreSQL is listening on:

$ sudo netstat -nltp      
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      13141/sshd: /usr/bi 
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      14450/postgres      
tcp6       0      0 :::22                   :::*                    LISTEN      13141/sshd: /usr/bi 
tcp6       0      0 ::1:5432                :::*                    LISTEN      14450/postgres

From the above output is running on port 5432.

We can change PostgreSQL default service port which is 5432 by editing the postgresql.conf file located in /var/lib/postgres/data/ directory.

sudo vim /var/lib/postgres/data/postgresql.conf

In the above file search for #port = 5432 and change to 5433:

# line 63 uncomment and change it to 5433
port = 5433                             # (change requires restart)

Now, restart PostgreSQL for the changes to take effect:

sudo systemctl restart postgresql

We can now confirm if PostgreSQL is listening on port 5433:

$ sudo netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      13141/sshd: /usr/bi 
tcp        0      0 127.0.0.1:5433          0.0.0.0:*               LISTEN      20246/postgres      
tcp6       0      0 :::22                   :::*                    LISTEN      13141/sshd: /usr/bi 
tcp6       0      0 ::1:5433                :::*                    LISTEN      20246/postgres 

PostgreSQL is now listening on port 5433.

Step 5: Enabling Remote Database connections

Set Listen address to your server IP address or “*” for all interfaces in the file /var/lib/postgres/data/postgresql.conf to allow remote database connection.

$ sudo vim /var/lib/postgres/data/postgresql.conf
# line 59
listen_addresses = '192.168.1.179'

Also set PostgreSQL to accept remote connections as shown below:

$ sudo vim /var/lib/postgres/data/pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             192.168.1.0/24            trust

Also for replication
local   replication     all                                     trust
host    replication     all             192.168.1.0/24            trust

Restart the database service after saving the changes:

sudo systemctl restart postgresql

Test connection with the psql command while providing username and optionally databasename.

$ psql -U <dbuser> -h <serverip> -p 5432 <dbname>

Step 6: Changing PostgreSQL Data Directory

By default, PostgreSQL stores its data in the /var/lib/postgres directory. As seen below, PostgreSQL may be configured to store data in a specified path.

Before doing so, we need to stop postgresql.service first:

sudo systemctl stop postgresql.service

Create a directory to store PostgreSQL data:

sudo mkdir -p /data/postgres

Set the ownership of the directory to postgres as below:

sudo chown postgres /data/postgres
sudo chmod 700 /data/postgres

Now, move PostgreSQL data from the old folder to new one:

sudo mv /var/lib/postgres/data /data/postgres

Make a symlink from PostgreSQL old folder to new one:

sudo ln -s /data/postgres /var/lib/postgres/data

Now start the postgresql.service:

sudo systemctl start postgresql.service

Confirm if it’s active and running:

$ systemctl status postgresql
 postgresql.service - PostgreSQL database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; preset: disabled)
     Active: active (running) since Tue 2025-02-25 09:31:47 EAT; 7min ago
 Invocation: ec36d14d282b4957a800a38b36f3e598
       Docs: man:postgres(1)
   Main PID: 3806 (postgres)
      Tasks: 6 (limit: 7074)
     Memory: 22.1M (peak: 24.3M)
        CPU: 272ms
     CGroup: /system.slice/postgresql.service
             ├─3806 /usr/bin/postgres -D /var/lib/postgres/data
             ├─3809 "postgres: checkpointer "
             ├─3810 "postgres: background writer "
             ├─3812 "postgres: walwriter "
             ├─3813 "postgres: autovacuum launcher "
             └─3814 "postgres: logical replication launcher "

Feb 25 09:31:46 garuda.cloudspinx.com systemd[1]: Starting PostgreSQL database server...
Feb 25 09:31:47 garuda.cloudspinx.com postgres[3806]: 2025-02-25 09:31:47.076 EAT [3806] LOG:  starting PostgreSQL 17.2 on x86_64-pc-linux-gnu, c>
Feb 25 09:31:47 garuda.cloudspinx.com postgres[3806]: 2025-02-25 09:31:47.077 EAT [3806] LOG:  listening on IPv6 address "::1", port 5432
Feb 25 09:31:47 garuda.cloudspinx.com postgres[3806]: 2025-02-25 09:31:47.077 EAT [3806] LOG:  listening on IPv4 address "127.0.0.1", port 5432
Feb 25 09:31:47 garuda.cloudspinx.com postgres[3806]: 2025-02-25 09:31:47.080 EAT [3806] LOG:  listening on Unix socket "/run/postgresql/.s.PGSQL>
Feb 25 09:31:47 garuda.cloudspinx.com postgres[3811]: 2025-02-25 09:31:47.085 EAT [3811] LOG:  database system was shut down at 2025-02-25 09:30:>
Feb 25 09:31:47 garuda.cloudspinx.com postgres[3806]: 2025-02-25 09:31:47.091 EAT [3806] LOG:  database system is ready to accept connections
Feb 25 09:31:47 garuda.cloudspinx.com systemd[1]: Started PostgreSQL database server.
Feb 25 09:36:47 garuda.cloudspinx.com postgres[3809]: 2025-02-25 09:36:47.093 EAT [3809] LOG:  checkpoint starting: time
Feb 25 09:36:51 garuda.cloudspinx.com postgres[3809]: 2025-02-25 09:36:51.494 EAT [3809] LOG:  checkpoint complete: wrote 46 buffers (0.3%);

Conclusion

We have come to an end of our tutorial on how to install PostgreSQL 17 on Arch | Manjaro | Garuda Linux. We hope you found this information educative, we are bringing you more new and useful tutorial. Stay tuned.

Latest guides on our site:

Your IT Journey Starts Here!

Ready to level up your IT skills? Our new eLearning platform is coming soon to help you master the latest technologies.

Be the first to know when we launch! Join our waitlist now.

Join our Linux and open source community. Subscribe to our newsletter for tips, tricks, and collaboration opportunities!

Recent Post

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Post

On our today’s guide, we will focus on how to schedule jobs on Linux with cron and systemd timers. One […]

Every experienced System Administrator should have a knowledge of user and group management in a Linux system. Executing this tasks […]

Hi there! Welcome to our today’s guide on getting familiar with Major Linux Desktop Environments. Linux and Unix-like OS are […]

Let's Connect

Unleash the full potential of your business with CloudSpinx. Our expert solutions specialists are standing by to answer your questions and tailor a plan that perfectly aligns with your unique needs.
You will get a response from our solutions specialist within 12 hours
We understand emergencies can be stressful. For immediate assistance, chat with us now

Contact CloudSpinx today!

Download CloudSpinx Profile

Discover the full spectrum of our expertise and services by downloading our detailed Company Profile. Simply enter your first name, last name, and email address.