Pg_dump pg_restore Oneliner - Datenbankumzug

Hallo!
Ich möchte alle Datenbanken eins Servers auf einen neuen Server übertragen. Um die Downtime der Datenbanken gering zu halten (das Dump hat unkomprimiert ca. 2TB) würde ich gerne mit einem Oneliner das pg_restore über eine Pipe direkt von dem pg_dump holen. Ist das möglich?
Beste Grüße

Wenn Du auf beiden Servern das gleiche Betriebssystem (und Version) verwendest und auch die gleiche Postgres Version, dann ist pg_basebackup vermutlich die schnellste Variante. Damit hast Du auf dem neuen Server sofort ein “Cluster” (Instanz) die Du starten kannst.

Danke für die schnelle Antwort, die Datenbank soll umziehen von
Debian 10 auf Debian 11
postgres 11.19 auf postgres 13.9
Das scheint wohl die Sache etwas komplizierte zu machen?
vorher habe ich mit
pg_dump > rsync → pg_restore die Datenbanken im Testbetrieb verschieben können, es dauert aber mehr als 8h.

nun ja. Wie viele Datenbanken sind es? pg_dump kann im directory-Format parallel dumpen und du kannst das auch wieder parallel einlesen. Was auch eine Option ist: via logical replication das im laufenden Betrieb machen - dann könntest Du auf max. ein paar Sekunden Downtime kommen. Aber das erfordert erheblich mehr Planung.

Ich suche eine Lösung für 4 Server mit jeweils 2-10 Datenbanken. Die Datenmenge unkomprimiert variiert von 500GB bis 2TB.
Ich hatte eigentlich an eine universelle Lösung gedacht in Richtung:
pg_dump -h ssh quellserver | psql -h localhost
Mit einer Downtime von ungefähr 4-5 Stunden würde ich leben können.

Das sollte so funktionieren.

Du musst nur vorher alle Benutzer anlegen, z.B. über pg_dumpall --globals.

Alternativ kannst Du natürlich auch direkt pg_dumpall` verwenden um alle Datenbank (und User) in einem Aufruf zu kopieren. Oder eben ein pg_dump pro Datenbank, die könntest Du dann auch parallel starten.

da habe ich bis jetzt noch keinen Erfolg erziehlt, sicher ist meine Syntax verdreht oder falsch.
auf jeden Fall kann ich mit ssh quellserver ohne Passwort auf die Konsole des anderen Servers. Die jeweilig angemeldeten Benutzer haben das Recht, auf postgresql zuzugreifen.
Wer kann mir die Befehlszeile richten?

Danke schonmal !

pg_dumpall | ssh quellserver | /bin/bash psql -h zielserver
/usr/bin/psql: line 19: use: command not found
/usr/bin/psql: line 20: use: command not found
Pseudo-terminal will not be allocated because stdin is not a terminal.
/usr/bin/psql: line 21: use: command not found
/usr/bin/psql: line 22: use: command not found
/usr/bin/psql: psql: line 24: syntax error near unexpected token $version,' /usr/bin/psql: psql: line 24: my ($version, $cluster);’
-bash: line 1: --: command not found
-bash: line 2: --: command not found
-bash: line 3: --: command not found
-bash: line 5: SET: command not found
-bash: line 7: SET: command not found
-bash: line 8: SET: command not found
-bash: line 10: --: command not found
-bash: line 11: --: command not found
-bash: line 12: --: command not found
-bash: line 14: CREATE: command not found
-bash: line 15: ALTER: command not found
-bash: line 16: CREATE: command not found
-bash: line 17: ALTER: command not found
-bash: line 18: CREATE: command not found
-bash: line 19: ALTER: command not found
-bash: line 20: CREATE: command not found
-bash: line 21: ALTER: command not found
-bash: line 22: CREATE: command not found
-bash: line 23: ALTER: command not found
-bash: line 24: CREATE: command not found
-bash: line 25: ALTER: command not found
-bash: line 26: CREATE: command not found
-bash: line 27: ALTER: command not found
-bash: line 28: CREATE: command not found
-bash: line 29: ALTER: command not found
-bash: line 32: --: command not found
-bash: line 33: --: command not found
-bash: line 34: --: command not found
-bash: line 36: GRANT: command not found
-bash: line 37: GRANT: command not found
-bash: line 42: --: command not found
-bash: line 43: --: command not found
-bash: line 44: --: command not found
-bash: line 46: --: command not found
-bash: line 47: --: command not found
-bash: line 48: --: command not found
-bash: line 50: connect: command not found
-bash: line 52: --: command not found
-bash: line 53: --: command not found
-bash: line 54: --: command not found
-bash: line 56: syntax error near unexpected token (' -bash: line 56: – Dumped from database version 13.9 (Debian 13.9-0+deb11u1)’
pg_dumpall: error: pg_dump failed on database “database”, exiting

Dieses Thema wurde automatisch 60 Tage nach der letzten Antwort geschlossen. Es sind keine neuen Antworten mehr erlaubt.