postgres

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package postgres 는 PostgreSQL 논리 백업/복원 어댑터다.

설계: docs/11_기능설계/Nullus_백업복구_설계.md §3.1 (nullus-plan#75)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCompatible

func IsCompatible(clientVersion, serverVersion string) (bool, error)

IsCompatible 은 클라이언트가 서버를 덤프할 수 있는지 판정한다.

기준은 **major 버전**이다. PostgreSQL 은 같은 major 안의 minor 차이를 호환으로 다루고, pg_dump 는 자기보다 낮거나 같은 major 의 서버를 덤프한다.

이 규칙을 minor 까지 좁혀 잡았다가 리허설에서 걸렸다 — 클라이언트 18.3 / 서버 18.4 조합이 막혔다. 서버가 마이너 패치를 받는 것만으로 백업이 멈추면, 막으려던 것과 정반대 방향의 사고가 된다.

Types

type DumpImage

type DumpImage struct {
	Ref     string // 예: docker.io/bitnamilegacy/postgresql:17.5.0-debian-12-r20
	Version string // 예: 17.5.0
}

DumpImage 는 pg_dump/pg_restore 를 담은 컨테이너 이미지다.

func SelectDumpImage

func SelectDumpImage(serverVersion string, candidates []DumpImage) (DumpImage, error)

SelectDumpImage 는 서버를 덤프할 수 있는 이미지 중 하나를 고른다.

규칙: 서버 major 이상인 것 중 **가장 낮은 major**, 그 안에서 **가장 높은 minor**. 낮은 major 를 고르는 것은 산출물이 그 환경 밖에서도 열리게 하기 위해서이고, 높은 minor 를 고르는 것은 같은 major 안에서는 어차피 호환이라 버그 수정이 더 들어간 쪽이 낫기 때문이다.

type PgDumper

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

PgDumper 는 pg_dump/pg_restore 를 exec 한다.

바이너리는 API 이미지에 함께 담긴다(Dockerfile 의 postgresql17-client) — helm·kubectl·migrate 와 같은 방식이다.

func NewPgDumper

func NewPgDumper(pool *pgxpool.Pool) *PgDumper

func (*PgDumper) Dump

func (d *PgDumper) Dump(ctx context.Context, target port.DBTarget, out io.Writer) (port.DumpResult, error)

Dump 는 custom format(-Fc) 으로 뜬다. 압축이 내장돼 있고 pg_restore 로 선택적 복원이 가능하다 (§3.1).

func (*PgDumper) Restore

func (d *PgDumper) Restore(ctx context.Context, target port.DBTarget, in io.Reader) error

Restore 는 database 단위로 복원한다.

인스턴스를 통째로 되돌리지 않는다 — 통합(§1.2) 이후에는 한 인스턴스에 두 database 가 있어서, 한쪽을 복원하다 다른 쪽을 날릴 수 있다 (§6.6).

func (*PgDumper) SchemaState

func (d *PgDumper) SchemaState(ctx context.Context, target port.DBTarget) (domain.SchemaState, error)

SchemaState 는 **대상 DB** 의 golang-migrate schema_migrations 를 읽는다 (§6.2).

이 표는 플랫폼 DB 에만 있다 — Keycloak 은 Liquibase 를 써서 자기 스키마를 관리한다. 그래서 Keycloak 대상으로 부르면 "relation does not exist" 가 나는데, 그것이 옳다. 공용 풀로 대신 읽어 플랫폼의 버전을 돌려주면 **엉뚱한 DB 의 답을 대상의 답인 것처럼** 쓰게 된다.

func (*PgDumper) ServerVersion

func (d *PgDumper) ServerVersion(ctx context.Context, target port.DBTarget) (string, error)

ServerVersion 은 **대상 DB** 의 서버 버전을 돌려준다.

Jump to

Keyboard shortcuts

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