DEV Community

Cover image for Step-by-Step Guide to Installing PostgreSQL on Arch Linux
Ashish Prajapati
Ashish Prajapati

Posted on

Step-by-Step Guide to Installing PostgreSQL on Arch Linux

Step 1: Update Your System

sudo pacman -Syu
Enter fullscreen mode Exit fullscreen mode

This command updates your package database and your system.

Step 2: Install PostgreSQL

To install PostgreSQL, use the Pacman package manager:

sudo pacman -S postgresql
Enter fullscreen mode Exit fullscreen mode

This command will install the PostgreSQL server and client on your system.

Step 3: Initialize the Database Cluster

Before using PostgreSQL, you need to set up the database cluster, which is a group of databases managed by a PostgreSQL server.

sudo -iu postgres
initdb --locale $LANG -E UTF8 -D '/var/lib/postgres/data'
Enter fullscreen mode Exit fullscreen mode
  • --locale $LANG: Sets the language settings for the database.
  • -E UTF8: Makes sure the database uses UTF-8 encoding.
  • -D '/var/lib/postgres/data': Chooses where the data will be stored.

Step 4: Start and Enable the PostgreSQL Service

Now, start the PostgreSQL service and enable it to start on boot automatically:

sudo systemctl start postgresql
sudo systemctl enable postgresql
Enter fullscreen mode Exit fullscreen mode

These commands start the PostgreSQL service, so make sure it starts automatically whenever your system boots.

Step 5: Set Up a PostgreSQL User

To manage databases and users, switch to the PostgreSQL user:

sudo -iu postgres
Enter fullscreen mode Exit fullscreen mode

Create a new PostgreSQL user with:

createuser --interactive
Enter fullscreen mode Exit fullscreen mode

You'll be prompted to enter the username and decide whether the new user should be a superuser.

Step 6: Create a Database

With your PostgreSQL user set up, you can now create a database:

createdb your-database-name
Enter fullscreen mode Exit fullscreen mode

Step 7: Access the PostgreSQL Shell

To start working with your databases, access the PostgreSQL command-line interface (CLI) with:

psql
Enter fullscreen mode Exit fullscreen mode

Or, connect directly to a specific database:

psql mydatabase
Enter fullscreen mode Exit fullscreen mode

Step 8: Exit the PostgreSQL Shell

When you're done, you can exit the PostgreSQL shell by typing:

\q
Enter fullscreen mode Exit fullscreen mode

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more