Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returns error code 74 on WAL fetch when WAL file does not exist #1195

Merged
merged 2 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/PostgreSQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ WAL-G will also prefetch WAL files ahead of asked WAL file. These files will be
wal-g wal-fetch example-archive new-file-name
```

Note: ``wal-fetch`` will exit with errorcode 74 (EX_IOERR: input/output error, see sysexits.h for more info) if the WAL-file is not available in the repository.
All other errors end in exit code 1, and should stop PostgreSQL rather than ending PostgreSQL recovery.
For PostgreSQL that should be any error code between 126 and 255, which can be achieved with a simple wrapper script.
Please see https://github.com/wal-g/wal-g/pull/1195 for more information.

### ``wal-push``

When uploading WAL archives to S3, the user should pass in the absolute path to where the archive is located.
Expand Down
10 changes: 9 additions & 1 deletion internal/databases/postgres/wal_fetch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
"github.com/wal-g/wal-g/utility"
)

// Looking at sysexits.h, EX_IOERR (74) is defined as a generic exit code for input/output errors
const exIoError = 74

type InvalidWalFileMagicError struct {
error
}
Expand Down Expand Up @@ -96,7 +99,12 @@ func HandleWALFetch(folder storage.Folder, walFileName string, location string,
}

err := internal.DownloadFileTo(folder, walFileName, location)
tracelog.ErrorLogger.FatalOnError(err)
if _, isArchNonExistErr := err.(internal.ArchiveNonExistenceError); isArchNonExistErr {
tracelog.ErrorLogger.Print(err.Error())
os.Exit(exIoError)
} else {
tracelog.ErrorLogger.FatalOnError(err)
}
}

// TODO : unit tests
Expand Down