Skip to content

fix: recognize errors from external tools and mention them in logs (#293)

Artyom Kartasov requested to merge 293-transparent-dump-errors into master

Description

Errors are ignored during the dump and restore stages by default. It might lead to restoring an inconsistent database and make the restore process intransparent.

To recognize errors from external tools and mention them in logs, de-multiplexe attach response and inspect the running exec command.

Additional suggestions (like --set ON_ERROR_STOP=on for psql and plain dump text and --verbose for pg_restore) are too strict and generate a lot of output logs. They can be implemented separately opting-in by configuration parameters strict and verbose

Related issue

#293 (closed)

Examples

Failed pg_dump

2021/12/03 11:56:55 dump.go:444: [INFO]   Running dump command:  [pg_dump --create --host 172.17.0.4 --port 5432 --username postgres --dbname test --jobs 1 --format directory --file /tmp/dumps/test]
2021/12/03 11:56:55 dump.go:456: [DEBUG]  pg_dump: [archiver (db)] connection to database "test" failed: could not connect to server: Connection refused
	Is the server running on host "172.17.0.4" and accepting
	TCP/IP connections on port 5432?

Failed pg_restore

2021/12/03 12:21:12 restore.go:487: [INFO]   Running restore command for test.sql [sh -c cat /tmp/test.sql | psql --set ON_ERROR_STOP=on --username postgres --dbname postgres]
2021/12/03 12:21:12 restore.go:494: [DEBUG]  Output of the restore command:  SET
SET
SET
 set_config 
------------
...
ALTER DATABASE
ERROR:  role "john" does not exist
2021/12/03 12:21:12 tools.go:343: [INFO]   Container logs:
 �postgres: could not access the server configuration file "/var/lib/dblab/oldest5/data/postgresql.conf": No such file or directory

2021/12/03 12:21:12 tools.go:371: [INFO]   Removing container ID: 16032e56880697fde647093505b26b80457b1a408ee520d3b4f68c6d7d5f6369
2021/12/03 12:21:43 tools.go:377: [INFO]   Container "16032e56880697fde647093505b26b80457b1a408ee520d3b4f68c6d7d5f6369" has been stopped
2021/12/03 12:21:43 tools.go:388: [INFO]   Container "16032e56880697fde647093505b26b80457b1a408ee520d3b4f68c6d7d5f6369" has been removed
2021/12/03 12:21:43 main.go:182: [ERROR]  Failed to run the data retrieval service: failed to restore a database: failed to exec restore command: exit code: 3
2021/12/03 12:21:43 main.go:183: [INFO]   If you have problems or questions, please contact our communities for help: https://postgres.ai/docs/questions-and-answers#where-to-get-help

Checklist

  • the MR description has been reviewed
  • this MR contains text changes and they have been reviewed OR there are no texts changes
  • this MR contains GUI/CLI changes and they have been reviewed OR there are no GUI/CLI changes
  • this MR contains API changes, specifications reflect those changes and they have been reviewed OR there are no API changes

Closes #293 (closed)

Edited by Artyom Kartasov

Merge request reports