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
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
Step 3 - Setup password
psql -U postgres
postgres=# \password # to set password
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
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
"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
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>
And PgAdmin should work just fine.
Top comments (7)
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.I didn't know that! Thanks for letting me know.
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.
Manjaro won't let me install
pgadmin4-5.1
. It is breaking the promise of always up-to-date?possibly. I switched from arch/manjaro to pop os LTS, and i'm pretty happy with it.
Everything looks good but pgadmin4 is not connecting to the host.
I'll try to refresh this article and add more edge cases soon. If you find a solution, do drop a comment!