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

Step 1: Update Your System

sudo pacman -Syu

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

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'
  • --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

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

Create a new PostgreSQL user with:

createuser --interactive

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

Step 7: Access the PostgreSQL Shell

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

psql

Or, connect directly to a specific database:

psql mydatabase

Step 8: Exit the PostgreSQL Shell

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

\q

0
Subscribe to my newsletter

Read articles from Ashish prajapati directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ashish prajapati
Ashish prajapati

I am a front-end web developer and currently exploring new things about backend development