Hero Image

Install PostgreSQL on Gentoo Linux

Install PostgreSQL on Gentoo Linux

Step 1 – Install PostgreSQL

emerge --ask dev-db/postgresql
# Initialize cluster
emerge --config dev-db/postgresql
rc-update add postgresql-14 default
rc-service postgresql-14 start

Step 2 – Connect as the postgres superuser

sudo -u postgres psql

Step 3 – Create a database and user

CREATE USER appuser WITH PASSWORD 'StrongPass123!';
CREATE DATABASE appdb OWNER appuser;
GRANT ALL PRIVILEGES ON DATABASE appdb TO appuser;
\q

Step 4 – Key configuration files

File Purpose
/etc/postgresql-14/postgresql.conf Main server settings
/etc/postgresql-14/pg_hba.conf Client authentication rules
/var/lib/postgresql/14/data Data directory

Step 5 – Allow remote connections (optional)

Edit /etc/postgresql-14/postgresql.conf:

listen_addresses = '*'

Edit /etc/postgresql-14/pg_hba.conf and add:

host  appdb  appuser  0.0.0.0/0  scram-sha-256

Reload:

systemctl reload postgresql 2>/dev/null || \
rc-service postgresql-14 reload 2>/dev/null || \
rcctl reload postgresql