Accéder à la DB distante depuis la machine locale¶
Contexte : shared-postgres tourne dans Docker sur le VPS Hetzner (178.105.46.57). Son port 5432 est mappé sur
127.0.0.1:5432du VPS — non exposé publiquement.
Option 1 — Requête ponctuelle (psql via SSH)¶
Pas de configuration préalable :
ssh root@178.105.46.57 "docker exec -i shared-postgres psql -U fichepaie_user -d gestionFichePaie -c 'SELECT * FROM utilisateurs LIMIT 5;'"
Option 2 — Tunnel SSH (Prisma Studio, GUI, psql interactif)¶
Ouvre le tunnel dans un terminal et laisse-le ouvert :
ssh -L 5434:127.0.0.1:5432 root@178.105.46.57 -N
Ensuite dans un autre terminal, connecte-toi comme si c'était local :
# psql interactif
PGPASSWORD='FichePaie_DB' psql -h localhost -p 5434 -U fichepaie_user -d gestionFichePaie
# Prisma Studio sur la DB distante
DATABASE_URL="postgresql://fichepaie_user:FichePaie_DB@localhost:5434/gestionFichePaie" npx prisma studio
Tout GUI (TablePlus, DBeaver, pgAdmin) fonctionne aussi sur localhost:5434.
Option 3 — Prisma migrate / db push vers la DB distante¶
(nécessite le tunnel de l'option 2 actif)
cd /home/kanmaber/projets/DDD_Module/BackEnd
DATABASE_URL="postgresql://fichepaie_user:FichePaie_DB@localhost:5434/gestionFichePaie" npx prisma db push
Adapter pour d'autres projets¶
| Projet | Utilisateur DB | Nom DB | Port tunnel suggéré |
|---|---|---|---|
| gestionFichePaie | fichepaie_user |
gestionFichePaie |
5434 |
| PsychoEnLigneV2 | psycho_user |
PsychoEnLigneV2 |
5435 |
Changer le port tunnel (-L 5434:...) pour éviter les conflits si plusieurs tunnels ouverts en même temps.
Prérequis¶
- Clé SSH configurée pour
root@178.105.46.57 - shared-postgres accessible sur le VPS :
docker port shared-postgres→5432/tcp -> 127.0.0.1:5432