gpbackup

module
v0.0.0-...-cb08592 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: Apache-2.0

README

Greengage Backup

gpbackup and gprestore are Go utilities for performing Greengage Database backups. They are still currently in active development.

Pre-Requisites

The project requires the Go Programming language version 1.26.11 or higher (the version the go directive of go.mod asks for). Follow the directions here for installation, usage and configuration instructions. The project also has a dependency on sqlite3. This is installed by default on many platforms, but you must install it on your system if it is not present.

Downloading

go get github.com/GreengageDB/gpbackup/...

This will place the code in $GOPATH/github.com/GreengageDB/gpbackup/.

Building and installing binaries

Make the gpbackup directory your current working directory and run:

make depend
make build

The build target will put the gpbackup, gprestore, and ggcheckmigrate binaries in $HOME/go/bin.

This will also attempt to copy gpbackup_helper to the greengage segments (retrieving hostnames from gp_segment_configuration). Pay attention to the output as it will indicate whether this operation was successful.

make build_linux is for cross compiling on macOS, and the target is Linux.

make install will scp the gpbackup_helper binary (used with -single-data-file flag) to all hosts

Validation and code quality

Test setup

Required for Greengage Database 6 or higher, several tests require the dummy_seclabel Greengage contrib module. This module exists only to support regression testing of the SECURITY LABEL statement. It is not intended to be used in production. Use the following commands to install the module.

pushd $(find ~/workspace/gpdb -name dummy_seclabel)
    make install
    gpconfig -c shared_preload_libraries -v "$(psql -At -c "SELECT array_to_string(array_append(string_to_array(current_setting('shared_preload_libraries'), ','), 'dummy_seclabel'), ',')" postgres)"
    gpstop -ra
    gpconfig -s shared_preload_libraries | grep dummy_seclabel
popd

Test execution

For how to run tests in a docker container, see: ci/README.md

NOTE: The integration and end_to_end tests require a running Greengage Database instance.

To run all tests except end-to-end (linters, unit, and integration), use

make test

To run only unit tests, use

make unit

To run only integration tests

make integration

Integration test requirements

  • Running GGDB instance
  • GGDB's gpcloud extension
make -C gpcontrib/gpcloud/ install
  • GGDB configured with --with-perl

To run end to end tests (requires a running GGDB instance), use

make end_to_end

We provide the following targets to help developers ensure their code fits Go standard formatting guidelines.

To run a linting tool that checks for basic coding errors, use

make lint

This target runs gometalinter.

Note: The lint target will fail if code is not formatted properly.

To automatically format your code and add/remove imports, use

make format

This target runs goimports and gofmt. We will only accept code that has been formatted using this target or an equivalent gofmt call.

Running the utilities

The basic command for gpbackup is

gpbackup --dbname <your_db_name>

The basic command for gprestore is

gprestore --timestamp <YYYYMMDDHHMMSS>

The basic command for ggcheckmigrate is

ggcheckmigrate --source-host <source_host> --source-port <source_port>

To check whether the required libraries can be loaded on the target cluster, provide both connections.

ggcheckmigrate \
  --source-host source.example.com --source-port 5432 --source-user source_admin \
  --target-host target.example.com --target-port 5432 --target-user target_admin

ggcheckmigrate finds known compatibility problems before a logical migration from Greengage 6 to Greengage 7. It checks every connectable source database by default. Use --source-database to check one database.

Objects in a schema given to --exclude-schema or -N are not checked in any database. A partition and its columns are checked or skipped by the schema of the root partitioned table. The flag can be repeated, and a missing schema is not an error.

Objects that belong to an extension are not reported, and neither are the indexes and partitions of an extension table, but the libraries of extension functions are still required on the target cluster, even when the functions are in an excluded schema.

ggcheckmigrate --source-host <source_host> --source-port <source_port> \
  --exclude-schema madlib --exclude-schema arenadata_toolkit

The source and target connections can be local or remote. The target connection is optional and uses the postgres database. Both connections use standard PostgreSQL authentication, including .pgpass, PGPASSWORD, ident, peer, and trust. If a target is specified, install and configure every extension and shared library used by the source cluster on the target cluster.

For separate passwords, add entries for both connections to ~/.pgpass and set the file permissions to 0600.

source.example.com:5432:*:source_admin:source_password
target.example.com:5432:postgres:target_admin:target_password

The * matches every connectable source database. If both connections use the same password, PGPASSWORD can be set for one command.

PGPASSWORD=shared_password ggcheckmigrate \
  --source-host source.example.com --source-port 5432 --source-user source_admin \
  --target-host target.example.com --target-port 5432 --target-user target_admin

The following problems are checked.

  • A LIST partition key contains multiple columns.
  • A function depends on Python 2.
  • A view or materialized view uses a removed operator, function, or data type.
  • A table column uses the removed abstime, reltime, tinterval, or unknown data type.
  • A required library cannot be loaded on the target cluster. This check requires a target connection.
  • An append-optimized partition omits an inherited storage option.
  • A function has a restricted EXECUTE ON location and does not return a set.
  • A unique index on a partitioned table omits a partition key.
  • A range partition uses START EXCLUSIVE or END INCLUSIVE with a text, float, or numeric key.
  • A statement trigger exists.

Each finding includes the database, schema, object name, object type, problem, and a possible correction. A run succeeds when no problem is found. The utility does not perform a test restore. Other migration problems may still occur.

The utility returns these exit codes.

Code Meaning
0 No checked migration problems were found.
1 At least one checked migration problem was found.
2 The source cluster is not Greengage 6.
3 The target cluster is not Greengage 7.
4 A command parameter is invalid.
5 The utility could not complete its checks.

Do not pass --with-stats to gpbackup when creating a backup for migration.

Run --help with any of these commands for a complete list of options.

Cleaning up

To remove the compiled binaries and other generated files, run

make clean

How to Contribute

See CONTRIBUTING.md file.

Code Formatting

We use goimports to format go code. See https://godoc.org/golang.org/x/tools/cmd/goimports The following command formats the gpbackup codebase excluding the vendor directory and also lists the files updated.

goimports -w -l $(find . -type f -name '*.go' -not -path "./vendor/*")

Troubleshooting

Dummy Security Label module is not installed or configured

If you see errors in many integration tests (below), review the Validation and code quality [Test setup](#Test setup) section above:

SECURITY LABEL FOR dummy ON TYPE public.testtype IS 'unclassified';
      Expected
          <pgx.PgError>: {
              Severity: "ERROR",
              Code: "22023",
              Message: "security label provider \"dummy\" is not loaded",

Tablespace already exists

If you see errors indicating the test_tablespace tablespace already exists (below), execute psql postgres -c 'DROP TABLESPACE test_tablespace' to cleanup the environment and rerun the tests.

    CREATE TABLESPACE test_tablespace LOCATION '/tmp/test_dir'
    Expected
        <pgx.PgError>: {
            Severity: "ERROR",
            Code: "42710",
            Message: "tablespace \"test_tablespace\" already exists",

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL