Tools: Installing PostgreSQL on Arch Linux | Practical Setup Guide (2026)

Tools: Installing PostgreSQL on Arch Linux | Practical Setup Guide (2026)

First things first : Installation

Lets initialize a Database Cluster

Start & Enable Service

Enter psql Shell

Create Role for a Project

Create a Database

Some frequently used and useful psql Commands

Connection URL Format

Enable Password Authentication (Critical for Prisma)

Restart PostgreSQL

Testing our Connection

Some Common Errors & Causes you might face Installing postgres on windows/mac is pretty simple, you just follow the steps on the installation wizard and you get it working. You will also find lots of video tutorials and blogs regarding installation in windows/mac. But when it comes to linux (specifically arch), things get interesting. Since linux gives you more control, setting up anything on it can seem tricky at first glance but as you go through, you understand each and every step and its purpose. Before getting into it, understand this : Postgres is not like MongoDB which you initialize once through the CLI by providing the --dbpath flag, it is a system service. Meaning it will run on the system 24x7 (if we configure it that way) and different system users will be able to use it according to the access they have been granted. Always update the packages first : PostgreSQL requires a data directory initialization. This is the directory which holds the actual data (one-time step unlike MongoDB) : -u postgres → run command as postgres system user initdb → creates system tables & internal structure -D → data directory location Enable on every boot : What is psql ? It is a command line interface to interact with out postgres service, databases, relations etc. Lets enter the psql shell with the user “postgres”. On installing postgres, a new user named “postgres” is generated with default privileges. It is always a good practice to create a separate role for every major project. This way you follow modular principles. Ownership = full control over that DB. List tables/relations Show current connection details To connect to the database, you will need a url (Yes this is the one you add in your environment variables) General structure : postgresql://USER:PASSWORD@HOST:PORT/DATABASE Example : postgresql://myapp:devpass123@localhost:5432/myapp_db This url can be used by: Change these lines according to your needs : Replace md5 with one of the following : To apply the config changes : -U → database role -d → database name -h → host (forces TCP) -W → force password prompt No manual server start like MongoDB. Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse

Command

Copy

$ -weight: 600;">sudo -weight: 500;">pacman -Syu -weight: 600;">sudo -weight: 500;">pacman -Syu -weight: 600;">sudo -weight: 500;">pacman -Syu -weight: 600;">sudo -weight: 500;">pacman -S postgresql -weight: 600;">sudo -weight: 500;">pacman -S postgresql -weight: 600;">sudo -weight: 500;">pacman -S postgresql -weight: 600;">sudo -u postgres initdb -D /var/lib/postgres/data -weight: 600;">sudo -u postgres initdb -D /var/lib/postgres/data -weight: 600;">sudo -u postgres initdb -D /var/lib/postgres/data -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start postgresql -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start postgresql -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start postgresql -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable postgresql -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable postgresql -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable postgresql -weight: 500;">systemctl -weight: 500;">status postgresql -weight: 500;">systemctl -weight: 500;">status postgresql -weight: 500;">systemctl -weight: 500;">status postgresql -weight: 600;">sudo -u postgres psql -weight: 600;">sudo -u postgres psql -weight: 600;">sudo -u postgres psql CREATE ROLE myapp WITH LOGIN PASSWORD 'devpass123' CREATEDB; CREATE ROLE myapp WITH LOGIN PASSWORD 'devpass123' CREATEDB; CREATE ROLE myapp WITH LOGIN PASSWORD 'devpass123' CREATEDB; CREATE DATABASE myapp_db OWNER myapp; CREATE DATABASE myapp_db OWNER myapp; CREATE DATABASE myapp_db OWNER myapp; SELECT current_user; SELECT current_user; SELECT current_user; -weight: 600;">sudo nano /var/lib/postgres/data/pg_hba.conf -weight: 600;">sudo nano /var/lib/postgres/data/pg_hba.conf -weight: 600;">sudo nano /var/lib/postgres/data/pg_hba.conf local all all md5 host all all 127.0.0.1/32 md5 host all all ::1/128 md5 local all all md5 host all all 127.0.0.1/32 md5 host all all ::1/128 md5 local all all md5 host all all 127.0.0.1/32 md5 host all all ::1/128 md5 -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart postgresql -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart postgresql -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart postgresql psql "postgresql://myapp:devpass123@localhost:5432/myapp_db" psql "postgresql://myapp:devpass123@localhost:5432/myapp_db" psql "postgresql://myapp:devpass123@localhost:5432/myapp_db" psql -U myapp -d myapp_db -h localhost -W psql -U myapp -d myapp_db -h localhost -W psql -U myapp -d myapp_db -h localhost -W - Default auth configuration is the “peer” auth. Peer auth uses our OS user to login - OS user identity is trusted - LOGIN → allows authentication - PASSWORD → required for apps/ORMs - CREATEDB → grant access to create databases - trust → no password - peer → OS identity - md5 / scram-sha-256 → password-based login - password authentication failed → wrong password - database does not exist → DB missing - role does not exist → user missing - could not connect to server → -weight: 500;">service stopped / wrong port - Always-running -weight: 500;">service - Config-driven behavior - URL = connection info only