본문으로 건너뛰기
2.2 소스 빌드와 다양한 배포본

2.2 소스 빌드와 다양한 배포본

운영 환경 대부분은 패키지로 충분하지만, 다음 경우에는 소스 빌드가 답입니다.

  • 확장(extension) 개발 — 서버와 정확히 같은 메이저·마이너 헤더 필요
  • 베타·RC 버전 검증
  • 특정 컴파일 옵션 (--enable-debug, --with-llvm, 커스텀 BLCKSZ)
  • 패키지가 없는 OS/아키텍처

또 한편으로는 PGDG 외에 상용·자동화 배포본이 따로 존재합니다. EDB Postgres Advanced Server, Postgres Pro, Pigsty 같은 것들입니다.

소스 빌드 — autoconf와 meson

PostgreSQL은 두 빌드 시스템을 모두 지원합니다. PG 16부터 meson이 정식 지원되고, PG 17부터 meson이 권장 빌드 시스템으로 자리 잡았습니다.

시스템도입명령 흐름
autoconf(전통)초기부터./configure → make → make install
meson(현재 권장)PG 16~17meson setup → ninja → ninja install

사전 의존성 설치

# RHEL / Rocky
sudo dnf install -y \
  gcc gcc-c++ make readline-devel zlib-devel \
  openssl-devel libxml2-devel libicu-devel \
  flex bison perl-IPC-Run \
  meson ninja-build         # meson 빌드용

# Debian / Ubuntu
sudo apt-get install -y \
  build-essential libreadline-dev zlib1g-dev \
  libssl-dev libxml2-dev libicu-dev \
  flex bison perl libperl-dev \
  meson ninja-build

autoconf 흐름

# 1. 소스 받기
curl -O https://ftp.postgresql.org/pub/source/v17.10/postgresql-17.10.tar.bz2
tar xjf postgresql-17.10.tar.bz2
cd postgresql-17.10

# 2. configure
./configure \
  --prefix=/opt/pgsql-17 \
  --with-openssl \
  --with-icu \
  --with-systemd \
  --with-llvm \
  --enable-thread-safety

# 3. 빌드
make -j$(nproc) world           # contrib·docs 포함
sudo make install-world

자주 쓰는 configure 옵션:

옵션의미
--prefix=<dir>설치 위치. 기본 /usr/local/pgsql
--with-opensslTLS·SCRAM-SHA-256 등 보안 기능
--with-icuICU 로케일 (PG 16+ 기본 권장)
--with-systemdsystemd notify 통합 (Type=notify)
--with-llvmJIT 코드 생성 (PG 11+)
--with-lz4LZ4 TOAST 압축
--with-zstdZstandard 압축 (백업·복제용)
--enable-debug디버그 심볼 — 개발용
--enable-cassertassertion 활성 — 개발용 (성능 손해, 운영 금지)
--with-blocksize=N페이지 크기(KB). 기본 8
--with-segsize=N세그먼트 크기(GB). 기본 1

meson 흐름

# meson 빌드는 별도 디렉토리에서 진행
meson setup build \
  --prefix=/opt/pgsql-17 \
  -Dssl=openssl -Dicu=enabled -Dsystemd=enabled \
  -Dllvm=enabled -Dlz4=enabled -Dzstd=enabled

ninja -C build
sudo ninja -C build install

meson은 의존성·옵션 탐지가 더 정밀하고 빌드가 빠릅니다. 신규 빌드는 meson을 우선 선택하는 게 좋습니다.

postgres 사용자·systemd 유닛 만들기 (수동)

소스 빌드는 패키지가 안 만들어 주므로 직접 잡아야 합니다.

# 시스템 사용자
sudo useradd -m -r -s /bin/bash postgres

# PGDATA
sudo mkdir -p /opt/pgsql-17/data
sudo chown postgres:postgres /opt/pgsql-17/data
sudo chmod 0700 /opt/pgsql-17/data

# initdb
sudo -u postgres /opt/pgsql-17/bin/initdb -D /opt/pgsql-17/data --data-checksums

systemd 유닛 /etc/systemd/system/postgresql.service:

[Unit]
Description=PostgreSQL 17 (source build)
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
User=postgres
Group=postgres
Environment=PGDATA=/opt/pgsql-17/data
ExecStart=/opt/pgsql-17/bin/postgres -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
TimeoutSec=120

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now postgresql
--with-systemd로 빌드해야 Type=notify가 동작합니다. 없이 빌드하면 Type=simple로 두고 PID 파일 기반으로 관리해야 합니다.

다양한 배포본

PostgreSQL은 BSD 라이선스라 누구나 자체 배포본을 만들 수 있습니다. 운영 환경에서 마주치는 주요 배포본:

배포본라이선스/형태특징
PGDG 공식무료, 오픈소스표준. 모든 메이저·OS 지원
EDB Postgres Advanced Server (EPAS)상용Oracle 호환 PL/SQL, DBA·복제 도구 추가
EDB Postgres Distributed (PGD)상용active-active 다중 마스터 복제
Postgres Pro Standard / Enterprise상용 (러시아 기반)autotuning, 추가 인덱스 타입, 확장
Pigsty무료, 오픈소스PostgreSQL + Patroni + HAProxy + 모니터링을 Ansible로 한 번에
Cybertec ApsCloudOne / Datalink상용EU 컴플라이언스, 추가 도구
Crunchy Data Postgres for Kubernetes상용 + 오픈소스 (operator)k8s 운영자용 operator
Citus무료 확장(MIT)분산 PostgreSQL 확장. Microsoft가 인수해 Azure에서 제공

대부분 배포본은 wire 프로토콜과 핵심 SQL이 호환되므로 클라이언트·드라이버는 그대로 씁니다. 호환되지 않는 영역은:

  • 추가 확장(특정 배포본 전용)
  • 일부 SQL 방언(EDB의 Oracle 호환 PL/SQL 등)
  • 운영 도구(자체 클러스터링 CLI)

Pigsty — 자동화 배포본

운영자가 자주 마주치는 오픈소스 자동화 배포본. PostgreSQL 위에 Patroni + HAProxy + Prometheus + Grafana + 확장 묶음을 Ansible 한 번으로 깝니다.

# Pigsty 단일 노드 데모
curl -fsSL https://repo.pigsty.io/get | bash
cd ~/pigsty
./bootstrap
./configure
./install.yml

호스트 1대~수십 대 클러스터를 분 단위로 띄울 수 있어 PoC·중소규모 운영에 유리. 대규모로 가면 자체 운영 자동화로 옮기는 패턴이 많습니다.

EDB / Postgres Pro

상용 배포본은 Oracle 마이그레이션·EU 정부 조달처럼 공식 지원이 계약 조건일 때 선택합니다. 일반 운영에서는 PGDG로 충분한 경우가 대부분입니다.

    flowchart LR
  subgraph Core["PostgreSQL 핵심 엔진 (BSD)"]
    PG["postgres binary,<br/>SQL, MVCC, WAL"]
  end
  Core --> PGDG["PGDG 패키지<br/>(공식, 무료)"]
  Core --> EDB["EDB EPAS<br/>(Oracle 호환 + 상용 지원)"]
  Core --> PP["Postgres Pro<br/>(상용 강화판)"]
  Core --> Pigsty["Pigsty<br/>(자동화 묶음)"]
  Core --> Cloud["AWS RDS / Azure / NCP<br/>(매니지드)"]

  classDef core fill:#ede9fe,stroke:#6d28d9,color:#3b0764,stroke-width:2px
  classDef d1 fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
  classDef d2 fill:#fed7aa,stroke:#c2410c,color:#7c2d12
  classDef d3 fill:#d1fae5,stroke:#047857,color:#064e3b
  class PG core
  class PGDG d1
  class EDB,PP d2
  class Pigsty d3
  class Cloud d2
  

소스 vs 패키지 — 의사결정 체크리스트

시나리오권장
일반 운영 클러스터PGDG 패키지
확장 개발소스 빌드(헤더 일치) 또는 -devel/-server-dev 패키지
베타 검증소스 빌드
다양한 컴파일 옵션 검증소스 빌드
컴플라이언스 요구되는 상용 지원 필요EDB/Postgres Pro
HA 자동화 빠르게 검증Pigsty
클라우드/매니지드RDS, Aurora, NCP Cloud DB, Flexible Server 등 (Part XVII)
소스 빌드 = 보안 패치 책임이 본인. 패키지는 dnf update 한 번이면 끝나지만, 소스 빌드는 새 마이너 나올 때마다 다시 빌드·교체 절차를 직접 만들어야 합니다. 운영 클러스터를 소스 빌드로 둘 거면 빌드 파이프라인부터 갖춰야 합니다.

정리

소스 빌드는 autoconf와 meson을 모두 지원하고 PG 17부터는 meson이 권장이며, --with-openssl·--with-icu·--with-systemd·--with-llvm·--with-lz4·--with-zstd 정도가 자주 쓰는 옵션입니다. 패키지와 달리 systemd 유닛과 postgres 사용자까지 직접 만들어야 하므로, 운영 클러스터는 패키지가 답인 경우가 압도적이고 소스 빌드는 확장 개발·베타 검증에 씁니다. 상용 배포본(EDB·Postgres Pro)은 Oracle 호환이나 상용 지원이 필요할 때, Pigsty는 PostgreSQL에 Patroni·모니터링까지 묶어 PoC·중소 규모를 빠르게 띄울 때 고릅니다.