DEV Community

Tushar Sadhwani
Tushar Sadhwani

Posted on • Updated on

How to setup PostgreSQL and PGAdmin on Manjaro Linux / Arch

This guide is here just because I've messed up the installs on arch before, and turns out it's actually pretty easy to do.

Step 1 - Install the dependencies

sudo pacman -S yay
yay postgresql pgadmin4
Enter fullscreen mode Exit fullscreen mode

This should automatically setup your postgres user and group.

Step 2 - Setup postgres service

sudo -u postgres -i # login as postgres
initdb --locale $LANG -E UTF8 -D '/var/lib/postgres/data/'
exit

sudo systemctl enable --now postgresql
sudo systemctl status postgresql # to check for any errors
Enter fullscreen mode Exit fullscreen mode

Step 3 - Setup password

psql -U postgres

postgres=# \password # to set password
Enter fullscreen mode Exit fullscreen mode

Step 4 - Setup connection security

$ su

# cd /var/lib/postgres/data
# cp pg_hba.conf pg_hba.conf.backup # in case you mess up
# nano pg_hba.conf
Enter fullscreen mode Exit fullscreen mode

Your default pg_hba.conf might look like this:

 TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust
Enter fullscreen mode Exit fullscreen mode

"Method" is set to trust, meaning it won't ask for the password to anyone. To fix that, change the method from trust to md5 everywhere.

And that should be it for postgres!

Bonus: shortcuts

> psql dbname postgres # to directly open a database

postgres=# \c                       # see current database
postgres=# \l                       # see list of databases
postgres=# \c dbname                # set database
postgres=# create database dbname;  # create database
postgres=# \dt                      # see list of tables
Enter fullscreen mode Exit fullscreen mode

Step 6 - PgAdmin

Open up pgadmin, click on "Add New Server", and add the following:

Host: localhost
Port: 5432
Maintenance database: postgres
Username: postgres
Password: <your password>
Enter fullscreen mode Exit fullscreen mode

And PgAdmin should work just fine.

Top comments (7)

Collapse
 
luisaureliocasoni profile image
Luís Aurélio Casoni

One more info: Sometimes, do you need to install postgis package:

sudo pacman -S postgis

This is required when you not found the initdb application.

Collapse
 
tusharsadhwani profile image
Tushar Sadhwani

I didn't know that! Thanks for letting me know.

Collapse
 
sha888 profile image
kresna888

I just followed the steps and PgAdmin not working and saw this error on my terminal.

QCoreApplication::applicationFilePath: Please instantiate the QApplication object first
QCoreApplication::applicationFilePath: Please instantiate the QApplication object first
Semaphore name: "pgadmin4---sema"
Shared memory segment name: "pgadmin4-sha888--shmem"
Python path: "/usr/lib/python3.10:/usr/lib/python3.10/lib-dynload:/usr/lib/python3.10/site-packages"
Python Home: "/usr/lib/python3.10"
Webapp path: "/usr/lib/pgadmin4/web/pgAdmin4.py"

How to solve this?
Thanks in advance.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

Manjaro won't let me install pgadmin4-5.1. It is breaking the promise of always up-to-date?

Collapse
 
tusharsadhwani profile image
Tushar Sadhwani • Edited

possibly. I switched from arch/manjaro to pop os LTS, and i'm pretty happy with it.

Collapse
 
kohli6010 profile image
Rahul

Everything looks good but pgadmin4 is not connecting to the host.

Collapse
 
tusharsadhwani profile image
Tushar Sadhwani

I'll try to refresh this article and add more edge cases soon. If you find a solution, do drop a comment!