Repository navigation
Back up PostgreSQL as .dump and restore it with pg_restore - #41
Merged
Merged
Conversation
The plain SQL import is slow on big PostgreSQL databases. Now the backup can write a custom format .dump file, and a new restore loads it with pg_restore. - Backup dialog for PostgreSQL: pick plain SQL or custom format, and the pg_dump version. The default is the version of the server. - Restore from .dump: pick the pg_restore version and whether to drop objects first. It shows progress, can be cancelled, and counts errors. - The SQL import sends a PGDMP file to the restore dialog.
| fn the_restore_password_is_never_an_argument() { | ||
| let file = Path::new("/backups/-shop.dump"); | ||
| let tool = Path::new("pg_restore"); | ||
| let command = DumpRepository::restore_command(tool, &postgres("s3cret"), file, true); |
| .and_then(|(_, value)| value); | ||
| assert_eq!(password, Some(OsStr::new("s3cret"))); | ||
| // Without clean and without a password. | ||
| let command = DumpRepository::restore_command(tool, &postgres(""), file, false); |
- Pass the database name to pg_dump and pg_restore as dbname='...'. A name with = or postgresql:// can then never be read as a connection string. - Ask to confirm a PostgreSQL backup, like MySQL and SQLite do. - Keep the pg_restore error when the reload of the tables fails after it. - A PGDMP file on MySQL or SQLite says it needs a PostgreSQL database. - Also find the PostgreSQL tools of Intel Homebrew and RHEL.
A fatal pg_restore error, like a wrong password or a file from a newer pg_dump, is also an error line, but then nothing was restored. Now the count comes from the "errors ignored on restore: N" line, which pg_restore prints only when it went on. Without that line the restore shows just its errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The SQL import is slow on big PostgreSQL databases, and some files still fail. PostgreSQL has its own tools for this:
pg_dump --format=customandpg_restore. This PR uses them, like TablePlus does.What
.partside file work for both.--version. The default is the server version (SHOW server_version_num), else the newest one. A tool older than the server shows a warning.pg_restore --no-owner --no-privilegesinto the current database. The password goes inPGPASSWORD, never in the arguments. Progress shows the time and the table. Cancel kills the tool. pg_restore goes on after errors, so the error says how many there were and shows the real error lines.PGDMPgoes to the restore dialog. The backend refuses it as SQL with a clear message.Not done
Checks
cargo clippy --all-targets(zero warnings),cargo test,cargo fmt[17, 15].bun run lint,bun run typecheck,bun test(393 pass)