How to Install PostgreSQL on Arch-based Linux Distributions (Manjaro)
PostgreSQL (often called Postgres) is a free, open-source, and advanced relational database management system and is developed by The PostgreSQL Global Development Group. It is primarily written in the C Programming Language. In addition to SQL (relational) querying, Postgres also supports JSON (non-relational) querying.
This article is a step-by-step instruction for installing PostgreSQL on an Arch-based Linux system.
Installation of PostgreSQL
Step 1: Update and upgrade your system by executing the following command
$ sudo pacman -Syu
Step 2: Install PostgreSQL from the official repository using pacman package manager
$ sudo pacman -S postgresql
Step 3: Verify the installation by running
$ postgres --version
Step 4: Using the initdb command, initialize PostgreSQL’s data directory
initdb –locale $LANG -E UTF8 -D ‘/var/lib/postgres/data/’
Step 5: Start the PostgreSQL server by using systemctl command.
$ sudo systemctl start postgresql $ sudo systemctl status postgresql
Step 6: Once again use systemctl command to enable PostgreSQL. Now, PostgreSQL will restart whenever your machine boots up.
$ sudo systemctl enable postgresql
Step 7: Now, log into the psql command-line interface with the default user ‘postgres’
$ sudo -u postgres psql
Step 8: Create a new user with the following command
postgres=# CREATE USER <username> WITH ENCRYPTED PASSWORD ‘<password>’;
Step 9: Create a new database with the following command
postgres=# CREATE DATABASE <dbname>;
Step 10: Finally, grant all permissions to the desired user on the newly created database.
postgres=# GRANT ALL PRIVILEGES ON DATABASE <dbname> TO username;
At this point, you have successfully installed and configured PostgreSQL on your Linux machine.
Uninstallation of PostgreSQL
To uninstall PostgreSQL and all of its config files run
$ sudo pacman -Rcns postgresql