Setup Steps
1. Install PostgreSQL:
sudo apt update
sudo apt install postgresql postgresql-contrib -y2. Start the service:
sudo systemctl start postgresql
sudo systemctl enable postgresql3. Switch to PostgreSQL user:
sudo -u postgres psql4. Create a new user and database:
CREATE USER appuser WITH PASSWORD 'StrongPass123!';
CREATE DATABASE myapp OWNER appuser;
GRANT ALL PRIVILEGES ON DATABASE myapp TO appuser;
\q5. Connect to the database:
psql -U appuser -d myapp -h localhost6. Enable remote connections:
sudo nano /etc/postgresql/16/main/postgresql.conf
# listen_addresses = '*'7. Edit pg_hba.conf:
sudo nano /etc/postgresql/16/main/pg_hba.conf
# host all all 0.0.0.0/0 md58. Restart the service:
sudo systemctl restart postgresql9. Backup:
pg_dump -U appuser myapp > backup.sql