All Guides

PostgreSQL Einrichtung

Installieren und konfigurieren Sie den PostgreSQL-Datenbankserver.

Intermediate20 Min.

Setup Steps

1. Install PostgreSQL:

sudo apt update
sudo apt install postgresql postgresql-contrib -y

2. Start the service:

sudo systemctl start postgresql
sudo systemctl enable postgresql

3. Switch to PostgreSQL user:

sudo -u postgres psql

4. 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;
\q

5. Connect to the database:

psql -U appuser -d myapp -h localhost

6. 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 md5

8. Restart the service:

sudo systemctl restart postgresql

9. Backup:

pg_dump -U appuser myapp > backup.sql