pgdump

package
v0.0.0-...-e9a6805 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCommands

func BuildCommands(outDir string, commandBuilder CommandBuilder, targets Targets, dump bool) ([]string, error)

BuildCommands generates commands that output Postgres dumps and sends them to predefined files for each target database.

func DumpCommand

func DumpCommand(t Target) string

DumpCommand generates a pg_dump command that can be used for on-prem-to-Cloud migrations.

func PartialCopyWithoutExtensions

func PartialCopyWithoutExtensions(dst io.Writer, src io.ReadSeeker, progressFn func(int64)) (int64, error)

PartialCopyWithoutExtensions will perform a partial copy of a SQL database dump from src to dst while commenting out EXTENSIONs-related statements. When it determines there are no more EXTENSIONs-related statements, it will return, resetting src to the position of the last contents written to dst.

This is needed for import to Google Cloud Storage, which does not like many EXTENSION statements. For more details, see https://cloud.google.com/sql/docs/postgres/import-export/import-export-dmp

Filtering requires reading entire lines into memory - this can be a very expensive operation, so when filtering is complete the more efficient io.Copy should be used to perform the remainder of the copy from src to dst.

func RestoreCommand

func RestoreCommand(t Target) string

RestoreCommand generates a psql command that can be used for migrations.

Types

type CommandBuilder

type CommandBuilder func(Target) (string, error)

func Builder

func Builder(builder string, command PGCommand) (commandBuilder CommandBuilder, targetKey string)

Builder generates the CommandBuilder and targetKey for a given builder and PGCommand

type Output

type Output struct {
	Output string
	Target Target
}

func Outputs

func Outputs(dir string, targets Targets) []Output

Outputs generates a set of mappings between a pgdump.Target and the desired output path. It can be provided a zero-value Targets to just generate the output paths.

type PGCommand

type PGCommand func(Target) string

type Target

type Target struct {
	// Target is the DSN of the database deployment:
	//
	// - in docker, the name of the database container, e.g. pgsql, codeintel-db, codeinsights-db
	// - in k8s, the name of the deployment or statefulset, e.g. deploy/pgsql, sts/pgsql
	// - in plain pg_dump, the server host or socket directory
	Target string `yaml:"target"`

	DBName   string `yaml:"dbname"`
	Username string `yaml:"username"`

	// Only include password if non-sensitive
	Password string `yaml:"password"`
}

Target represents a database for pg_dump to export.

type Targets

type Targets struct {
	Primary      Target `yaml:"primary"`
	CodeIntel    Target `yaml:"codeintel"`
	CodeInsights Target `yaml:"codeinsights"`
}

Targets represents configuration for each of Sourcegraph's databases.

Jump to

Keyboard shortcuts

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