How to Set Up PostgreSQL
How to Set Up PostgreSQL
Installation
# Ubuntu/Debian
apt update
apt install postgresql postgresql-contrib -y
systemctl start postgresql
systemctl enable postgresql
# CentOS/AlmaLinux
dnf install postgresql-server postgresql-contrib -y
postgresql-setup --initdb
systemctl start postgresql
systemctl enable postgresql
Creating a Database and User
sudo -u postgres psql
CREATE USER myapp_user WITH PASSWORD 'StrongPassword123!';
CREATE DATABASE myapp_db OWNER myapp_user;
GRANT ALL PRIVILEGES ON DATABASE myapp_db TO myapp_user;
q
Allowing Remote Access (if needed)
- Edit
postgresql.confand setlisten_addresses = '*'. - Edit
pg_hba.confto allow remote connections. - Restart PostgreSQL and open firewall port 5432.