postgres

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const PostgresDefaultPort = "5432"

Variables

This section is empty.

Functions

func ForceWALArchive added in v0.0.14

func ForceWALArchive(ctx *contexts.Context, run PSQLRunner, opts ForceWALArchiveOptions) (err error)

ForceWALArchive guarantees two things a clone's forward PITR recovery depends on: that a clone recovering to any wall-clock time at or before now can confirm it reached its target, and that the WAL segment holding the base backup's consistency point is archived. It does this by:

  1. Writing a recovery fence — a no-op transaction forced to commit. SELECT txid_current() assigns the transaction a real XID, so committing it writes an XLOG_XACT_COMMIT record (a transaction that never touches data and is never assigned an XID writes no such record). recovery_target_time only ever stops at a transaction commit, so this commit — timestamped after the recovery target — is the marker that lets recovery confirm it replayed past the target and stop cleanly. Without it, a source that committed nothing after the target (an idle database) makes a forward recovery run out of WAL and fail with "recovery ended before configured recovery target was reached".
  2. Forcing a WAL switch so the segment holding the fence — and, on an idle source, the consistency point that shares that segment — is completed and archived.
  3. Waiting for that segment to reach the object store before any recovery can need it.

The fence MUST be a committing transaction. Do not "simplify" it to pg_create_restore_point or a bare pg_switch_wal: recovery_target_time is blind to restore points, and a non-committing switch leaves a source that is idle past the target with no record to recover to.

func GetServerAddress

func GetServerAddress(creds Credentials) string

func NewCmdWrapper

func NewCmdWrapper(cmd *exec.Cmd) *cmdWrapper

func ParseDuration added in v0.0.13

func ParseDuration(value string) (time.Duration, error)

ParseDuration parses a PostgreSQL time-valued configuration parameter (such as archive_timeout) into a time.Duration. PostgreSQL accepts an integer optionally followed by a unit suffix (us, ms, s, min, h, d). A bare integer with no unit is interpreted in seconds, which is the default unit for archive_timeout and the other WAL-timing parameters this is used for.

Types

type CredentialVariable

type CredentialVariable string
const (
	HostVarName        CredentialVariable = "PGHOST"
	PortVarName        CredentialVariable = "PGPORT"
	DatabaseVarName    CredentialVariable = "PGDATABASE"
	UserVarName        CredentialVariable = "PGUSER"
	RequireAuthVarName CredentialVariable = "PGREQUIREAUTH"
	SSLModeVarName     CredentialVariable = "PGSSLMODE"
	SSLCertVarName     CredentialVariable = "PGSSLCERT"
	SSLKeyVarName      CredentialVariable = "PGSSLKEY"
	SSLRootCertVarName CredentialVariable = "PGSSLROOTCERT"
)

type CredentialVariables

type CredentialVariables map[CredentialVariable]string

func (CredentialVariables) SetDatabaseName

func (cv CredentialVariables) SetDatabaseName(name string) CredentialVariables

func (CredentialVariables) ToEnvSlice

func (cv CredentialVariables) ToEnvSlice() []string

type Credentials

type Credentials interface {
	GetVariables() CredentialVariables
	GetUsername() string
	GetHost() string
	GetPort() string
}

type DumpAllOptions

type DumpAllOptions struct {
	CleanupTimeout helpers.MaxWaitTime
}

type EnvironmentCredentials

type EnvironmentCredentials CredentialVariables

func (EnvironmentCredentials) GetHost

func (ec EnvironmentCredentials) GetHost() string

func (EnvironmentCredentials) GetPort

func (ec EnvironmentCredentials) GetPort() string

func (EnvironmentCredentials) GetUsername

func (ec EnvironmentCredentials) GetUsername() string

func (EnvironmentCredentials) GetVariables

func (ec EnvironmentCredentials) GetVariables() CredentialVariables

type ForceWALArchiveOptions added in v0.0.14

type ForceWALArchiveOptions struct {
	WaitForArchiveTimeout helpers.MaxWaitTime
}

type LocalRuntime

type LocalRuntime struct {
	// contains filtered or unexported fields
}

func NewLocalRuntime

func NewLocalRuntime() *LocalRuntime

func (*LocalRuntime) DumpAll

func (lr *LocalRuntime) DumpAll(ctx *contexts.Context, credentials Credentials, outputFilePath string, opts DumpAllOptions) (err error)

func (*LocalRuntime) Restore added in v0.0.2

func (lr *LocalRuntime) Restore(ctx *contexts.Context, credentials Credentials, inputFilePath string, opts RestoreOptions) (err error)

type MockRuntime

type MockRuntime struct {
	mock.Mock
}

MockRuntime is an autogenerated mock type for the Runtime type

func NewMockRuntime

func NewMockRuntime(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockRuntime

NewMockRuntime creates a new instance of MockRuntime. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockRuntime) DumpAll

func (_m *MockRuntime) DumpAll(_a0 *contexts.Context, _a1 Credentials, _a2 string, _a3 DumpAllOptions) error

DumpAll provides a mock function with given fields: _a0, _a1, _a2, _a3

func (*MockRuntime) EXPECT

func (_m *MockRuntime) EXPECT() *MockRuntime_Expecter

func (*MockRuntime) Restore added in v0.0.2

func (_m *MockRuntime) Restore(_a0 *contexts.Context, _a1 Credentials, _a2 string, _a3 RestoreOptions) error

Restore provides a mock function with given fields: _a0, _a1, _a2, _a3

type MockRuntime_DumpAll_Call

type MockRuntime_DumpAll_Call struct {
	*mock.Call
}

MockRuntime_DumpAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DumpAll'

func (*MockRuntime_DumpAll_Call) Return

func (*MockRuntime_DumpAll_Call) Run

func (*MockRuntime_DumpAll_Call) RunAndReturn

type MockRuntime_Expecter

type MockRuntime_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockRuntime_Expecter) DumpAll

func (_e *MockRuntime_Expecter) DumpAll(_a0 interface{}, _a1 interface{}, _a2 interface{}, _a3 interface{}) *MockRuntime_DumpAll_Call

DumpAll is a helper method to define mock.On call

  • _a0 *contexts.Context
  • _a1 Credentials
  • _a2 string
  • _a3 DumpAllOptions

func (*MockRuntime_Expecter) Restore added in v0.0.2

func (_e *MockRuntime_Expecter) Restore(_a0 interface{}, _a1 interface{}, _a2 interface{}, _a3 interface{}) *MockRuntime_Restore_Call

Restore is a helper method to define mock.On call

  • _a0 *contexts.Context
  • _a1 Credentials
  • _a2 string
  • _a3 RestoreOptions

type MockRuntime_Restore_Call added in v0.0.2

type MockRuntime_Restore_Call struct {
	*mock.Call
}

MockRuntime_Restore_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Restore'

func (*MockRuntime_Restore_Call) Return added in v0.0.2

func (*MockRuntime_Restore_Call) Run added in v0.0.2

func (*MockRuntime_Restore_Call) RunAndReturn added in v0.0.2

type PSQLRunner added in v0.0.14

type PSQLRunner func(ctx *contexts.Context, sql string) (string, error)

PSQLRunner runs a single SQL statement against a Postgres server and returns psql's stdout. The caller decides where and how psql runs (e.g. exec'd inside the cluster's primary pod, connecting as the local superuser). Implementations must run psql so the result is the bare value(s) — tuples only, unaligned (psql -tA) — and must fail the call if the statement errors.

type RestoreOptions added in v0.0.2

type RestoreOptions struct{}

type Runtime

Represents a place (i.e. local or remote) where commands can run.

Jump to

Keyboard shortcuts

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