Commit 87d3a5bb authored by Stan Hu's avatar Stan Hu

Add --if-exists to pg_dump command-line in backup creation

Because we use the --clean argument to `pg_dump`, the database backup
SQL file has many DROP commands that precede the section to restore the
tables and data. However, on instances with an empty database, these
DROP statements generate a lot of noise and make it difficult to filter
true error messages from noise.

In preparation of capturing error messages from stderr, we add this to
the backup commands to make it easier to flag real errors.

Reference: https://www.postgresql.org/docs/11/app-pgdump.html

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/36405
parent 4e12f87c
---
title: Add --if-exists to pg_dump command-line in backup creation
merge_request: 40792
author:
type: other
......@@ -27,6 +27,7 @@ module Backup
progress.print "Dumping PostgreSQL database #{config['database']} ... "
pg_env
pgsql_args = ["--clean"] # Pass '--clean' to include 'DROP TABLE' statements in the DB dump.
pgsql_args << '--if-exists'
if Gitlab.config.backup.pg_schema
pgsql_args << '-n'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment