diff --git a/CN/modules/ROOT/nav.adoc b/CN/modules/ROOT/nav.adoc index d569e47..991c4af 100644 --- a/CN/modules/ROOT/nav.adoc +++ b/CN/modules/ROOT/nav.adoc @@ -72,6 +72,7 @@ *** xref:master/ecosystem_components/pgdog.adoc[PgDog] *** xref:master/ecosystem_components/pg_readonly.adoc[pg_readonly] *** xref:master/ecosystem_components/zhparser.adoc[zhparser] +*** xref:master/ecosystem_components/pgbackrest.adoc[pgBackRest] * 监控运维 ** xref:master/getting-started/daily_monitoring.adoc[日常监控] ** xref:master/getting-started/daily_maintenance.adoc[日常维护] diff --git a/CN/modules/ROOT/pages/master/ecosystem_components/ecosystem_overview.adoc b/CN/modules/ROOT/pages/master/ecosystem_components/ecosystem_overview.adoc index 7b2a3ad..c766670 100644 --- a/CN/modules/ROOT/pages/master/ecosystem_components/ecosystem_overview.adoc +++ b/CN/modules/ROOT/pages/master/ecosystem_components/ecosystem_overview.adoc @@ -38,7 +38,8 @@ IvorySQL 作为一款兼容 Oracle 且基于 PostgreSQL 的高级开源数据库 | 25 | xref:master/ecosystem_components/pg_repack.adoc[pg_repack] | 1.5.3 | 在几乎不阻塞业务读写的情况下在线重整表和索引、消除存储膨胀,效果类似 VACUUM FULL | 表与索引在线重建、存储空间回收 | 26 | xref:master/ecosystem_components/pgdog.adoc[PgDog] | 0.1.45 | 专为 PostgreSQL 设计的高性能、开源集群中间件(代理工具),采用 Rust 语言编写 | 自动分片、连接池和负载均衡功能 | 27 | xref:master/ecosystem_components/pg_readonly.adoc[pg_readonly] | 1.0.5 | 可将 PostgreSQL 数据库集群设置为只读 | 系统调试、灾难恢复 -| 28 | xref:master/ecosystem_components/zhparser.adoc[zhparser] | master branch | 用于中文全文搜索的PostgreSQL插件,基于SCWS(即:简易中文分词系统)实现了一个中文解析器 | 搜索引擎、关键字提取 | +| 28 | xref:master/ecosystem_components/zhparser.adoc[zhparser] | master branch | 用于中文全文搜索的PostgreSQL插件,基于SCWS(即:简易中文分词系统)实现了一个中文解析器 | 搜索引擎、关键字提取 +| 29 | xref:master/ecosystem_components/pgbackrest.adoc[pgBackRest] | 2.58.0 | 可靠的 PostgreSQL 备份和恢复解决方案 | 容灾备份、大库备份、异地/多层容灾 |==== 这些插件均经过 IvorySQL 团队的测试和适配,确保在 IvorySQL 环境下稳定运行。用户可以根据业务需求选择合适的插件,进一步提升数据库系统的能力和灵活性。 diff --git a/CN/modules/ROOT/pages/master/ecosystem_components/pgbackrest.adoc b/CN/modules/ROOT/pages/master/ecosystem_components/pgbackrest.adoc new file mode 100644 index 0000000..435aa16 --- /dev/null +++ b/CN/modules/ROOT/pages/master/ecosystem_components/pgbackrest.adoc @@ -0,0 +1,500 @@ + +:sectnums: +:sectnumlevels: 5 + += pgBackRest + +== 概述 + +pgBackRest 是一款可靠的 PostgreSQL 备份和恢复解决方案。其核心基于 PostgreSQL 的物理级备份(数据目录的文件)和WAL归档管理机制。特点是项目质量很高:100%测试覆盖、高质量编码、精简依赖。 + +NOTE: pgBackRest在 v2.48.0 版本引入了对 pg_control 文件的 CRC 校验,由于 IvorySQL 修改了 pg_control 文件布局,所以需要在 stanza 配置中使用 pg-version-force 选项指定 IvorySQL 对应的 PostgreSQL 版本。 + +NOTE: pgBackRest 无需修改即可在 IvorySQL 5.x 下使用,但这仅是一个巧合,实际使用中仍建议增加 pg-version-force 选项。 + +项目地址: + +版本:v2.58.0 + +开源协议:MIT License + +== 安装 + +[TIP] +官网推荐从包管理器安装。 + +[TIP] +源码测试安装环境为 Ubuntu 26.04。 + +=== 依赖 + +[source,bash] +---- +sudo apt update && \ +sudo apt-get install python3-setuptools meson gcc \ + libpq-dev libssl-dev libxml2-dev \ + pkg-config liblz4-dev libzstd-dev \ + libbz2-dev libz-dev libyaml-dev \ + libssh2-1-dev +---- + +=== 源码安装 + +[source,bash] +---- +cd ~ +mkdir -p build +wget -q -O - \ + https://github.com/pgbackrest/pgbackrest/archive/release/2.58.0.tar.gz | \ + tar zx -C build +meson setup build/pgbackrest build/pgbackrest-release-2.58.0 +ninja -C build/pgbackrest + +# 编译完成后,将在 build/src 路径下生成 pgbackrest 可执行文件 +./build/src/pgbackrest --version +---- + +=== 验证安装 + +NOTE: pgBackRest本体只有一个可执行文件,使用时通过传入配置文件即可。本文仅作使用说明,无需额外安装步骤。 + +== 配置 + +NOTE: pgBackRest 支持多备份仓库,详情参考: + +NOTE: 本文演示中,PG数据库和备份仓库均在同一台主机上,备份仓库为本地文件。 + +需要在两两处对进行配置: + +[cols="1,2"] +|=== +| 文件名 | 说明 + +| postgresql.conf +| 配置 `PostgreSQL` ,增加 `archive_command` ,使能 `WAL` 备份 + +| pgbackrest.conf +| 对 `pgBackRest` 本身的配置,包括源数据库、备份仓库等的配置 +|=== + +在 `postgresql.conf` 末尾附加: + +NOTE: 仅为示例,具体操作参考文档后续部分。 + +[source,conf] +---- +port = 6551 +ivorysql.port = 6553 +listen_addresses = '127.0.0.1' +unix_socket_directories = '/tmp/.pgbr_sock_1000_6551' +archive_mode = on +archive_command = '/path/to/pgbackrest --config=/path/to/pgbackrest.conf --stanza=ivory archive-push %p' +log_min_messages = info +---- + +创建 `pgbackrest.conf` : + +NOTE: 仅为示例,具体操作参考文档后续部分。 + +[source,conf] +---- +[global] +# 配置了多个repos的话,WAL是全冗余、备份需要手动执行 +repo1-path=/tmp/pgbackrest_ivorysql/repo +# 完整备份保留时间 +repo1-retention-full=9999 +# log文件 +log-path=/tmp/pgbackrest_ivorysql/log +# console的loglevel +log-level-console=info +# 写入文件的loglevel +log-level-file=detail +# 不等下一个checkpoint +start-fast=y + +[$STANZA] +# 配置多个的pg的情况是primary+replica,编号不代表主备,自动识别 +pg1-path=/tmp/pgbackrest_ivorysql/pg1/data +pg1-port=6551 +pg1-socket-path='/tmp/.pgbr_sock_1000_6551' +pg-version-force=18 +---- + +== 使用 + +=== pgBackRest 命令 + +[source,bash] +---- +# 使用方式 +pgbackrest [选项] [命令] +---- + +`pgBackRest` 命令列表: + +[source,bash] +---- +# 增加或修改备份的注释,注释以JSON形式记录在backup.info文件 +annotate + +# 备份仓库中获取WAL段,PostgreSQL 通过 restore_command 调用。 +# 执行pgbackrest restore 时自动把它写进 postgresql.auto.conf: +# "restore_command = 'pgbackrest --stanza=ivory archive-get %f "%p"'" +archive-get + +# 向备份仓库存入WAL段,把 PostgreSQL 刚写完的 WAL 段推送到 pgbackrest 仓库。 +# 它和 archive-get 一进一出,构成 PITR 的基础。 +# 需要手动写入postgresql.conf: "archive_command = 'pgbackrest --stanza=ivory archive-push %p'" +archive-push + +# 备份PG数据库,对整个数据目录做一次一致性备份并写入仓库。 +backup + +# 检查配置、核对仓库信息、归档链路测试(会执行pg_switch_wal) +check + +# 删除超期的备份和不再需要的 WAL 归档 +expire + +# 显示帮助信息 +help + +# 获取备份的信息 +info + +# 用于调试,把仓库里的任意文件取出来写到 stdout 或本地文件。 +repo-get + +# 通过存储驱动列出仓库里的文件和目录 +repo-ls + +# 把仓库里的备份还原成可启动的数据目录,并自动配置好后续的 WAL 回放。 +restore + +# 运行多主机部署时的传输服务(TLS模式):在主机间搬运备份数据。PG和Repo主机都要运行。 +server + +# pgBackRest server探活命令 +server-ping + +# 初始化命令:在仓库里为一套集群建立 stanza 的元数据骨架 +stanza-create + +# 删除stanza +stanza-delete + +# 数据库大版本升级后,需要同步升级stanza +stanza-upgrade + +# 不启动任何进程/服务,唯一的工作是删掉 stop 命令留下的停止文件,让 pgbackrest 操作恢复运行。 +start + +# 创建停止文件,backup、archive-push、expire、stanza-create/upgrade 及 remote 请求在启动时检测到该文件即拒绝。 +stop + +# 检查已存在的备份和 WAL 是否完好 +verify + +# 获取当前版本 +version +---- + +`pgBackRest` 内部命令列表,这些命令不应该在生产场景下使用,可能导致数据损坏: + +[source,bash] +---- +# 以可读格式转储某次备份的 manifest +manifest + +# 往仓库写文件(自动加密),repo-get 的反向 +repo-put + +# 删仓库文件/目录(--recurse) +repo-rm +---- + +=== 执行操作 + +TIP: 由于操作过程较为复杂,为了便于测试,将命令进行参数化,并构造了辅助函数。下面的命令,请在同一终端回话内执行。 + +变量准备: + +[source,bash] +---- +# 根据实际情况修改:IVORY_PG_VERSION_MAJOR、IVORY_BIN、PGBACKREST_BIN,其他可默认 +IVORY_PG_VERSION_MAJOR=18 +IVORY_BIN="/usr/local/ivorysql/bin" +PGBACKREST_BIN="/home/lct/repos/pgbackrest/build/src/pgbackrest" +TEST_BASE="/tmp/pgbackrest_ivorysql_regress" +PG_PORT="6551" +STANDBY_PORT="6552" +ORA_PORT="6553" +STANDBY_ORA_PORT="6554" +DB_MODE="oracle" +STANZA="ivory" + +PG1_DATA="$TEST_BASE/pg1/data" +PG2_DATA="$TEST_BASE/pg2/data" +REPO_PATH="$TEST_BASE/repo" +# unix socket 路径有 107 字节上限,固定放在 /tmp 下的短目录 +SOCK_PATH="${SOCK_PATH:-/tmp/.pgbr_sock_$(id -u)_$PG_PORT}" +LOG_PATH="$TEST_BASE/log" +CONF="$TEST_BASE/pgbackrest.conf" +RUN_LOG="$TEST_BASE/regression.log" +TEST_DB="regress" +RESTORE_POINT="pgb_regress_rp" + +sql() +{ + local port="$1" db="$2" query="$3" + "$IVORY_BIN/psql" -h "$SOCK_PATH" -p "$port" -d "$db" -U "$(id -un)" \ + -v ON_ERROR_STOP=1 -Atc "$query" 2>>"$RUN_LOG" +} +switch_wal_and_wait() +{ + local wal i + # 先产生一条 WAL 记录,避免当前段为空时 pg_switch_wal() 空转(不会触发归档) + sql "$ORA_PORT" postgres "SELECT pg_create_restore_point('pgb_wal_sync')" >/dev/null || return 1 + wal=$(sql "$ORA_PORT" postgres "SELECT pg_walfile_name(pg_switch_wal())") || return 1 + for i in $(seq 1 60); do + local archived + archived=$(sql "$ORA_PORT" postgres "SELECT last_archived_wal FROM pg_stat_archiver") + [[ -n "$archived" && ! "$archived" < "$wal" ]] && return 0 + sleep 1 + done + return 1 +} +---- + +执行前准备: + +[source,bash] +---- +rm -rf "$SOCK_PATH" +mkdir -p "$PG1_DATA" "$REPO_PATH" "$SOCK_PATH" "$LOG_PATH" +chmod 700 "$PG1_DATA" "$SOCK_PATH" +: >"$RUN_LOG" +export LD_LIBRARY_PATH="$(dirname "$IVORY_BIN")/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" + +# 确认一下版本 +${IVORY_BIN}/pg_ctl --version +${PGBACKREST_BIN} --version +---- + +初始化主库及配置: + +[source,bash] +---- +# 初始化,使用oracle模式 +"$IVORY_BIN/initdb" -D "$PG1_DATA" -m "$DB_MODE" -E UTF8 --no-locale -A trust -U "$(id -un)" + +# 配置IvorySQL +cat >>"$PG1_DATA/postgresql.conf" <"$CONF" < 100;"; + +# 执行恢复 +"$IVORY_BIN/pg_ctl" -D "$PG1_DATA" -w -t 60 -m fast stop +"$PGBACKREST_BIN" --config="$CONF" --stanza="$STANZA" \ + --delta --type=name --target="$RESTORE_POINT" \ + --target-action=promote restore; + +# 验证,这次的md5输出应该与上面的一致 +"$IVORY_BIN/pg_ctl" -D "$PG1_DATA" -l "$LOG_PATH/pg1.log" -w start +sql "$ORA_PORT" "$TEST_DB" \ + "SELECT md5(string_agg(id::text || ':' || name, ',' ORDER BY id)) FROM t_ora;"; +---- diff --git a/EN/modules/ROOT/nav.adoc b/EN/modules/ROOT/nav.adoc index bef3ab4..b071b69 100644 --- a/EN/modules/ROOT/nav.adoc +++ b/EN/modules/ROOT/nav.adoc @@ -72,6 +72,7 @@ *** xref:master/ecosystem_components/pgdog.adoc[PgDog] *** xref:master/ecosystem_components/pg_readonly_en.adoc[pg_readonly] *** xref:master/ecosystem_components/zhparser_en.adoc[zhparser] +*** xref:master/ecosystem_components/pgbackrest.adoc[pgBackRest] * Monitor and O&M ** xref:master/getting-started/daily_monitoring.adoc[Monitoring] ** xref:master/getting-started/daily_maintenance.adoc[Maintenance] diff --git a/EN/modules/ROOT/pages/master/ecosystem_components/ecosystem_overview.adoc b/EN/modules/ROOT/pages/master/ecosystem_components/ecosystem_overview.adoc index 055705c..79180a5 100644 --- a/EN/modules/ROOT/pages/master/ecosystem_components/ecosystem_overview.adoc +++ b/EN/modules/ROOT/pages/master/ecosystem_components/ecosystem_overview.adoc @@ -37,9 +37,10 @@ IvorySQL, as an advanced open-source database compatible with Oracle and based o |*23*| xref:master/ecosystem_components/pg_bigm.adoc[pg_bigm] | 1.2 | Equips IvorySQL with bigram full-text search capability, supporting Chinese, Japanese and Korean texts to implement fuzzy retrieval and similarity query efficiently | text search for articles, commodities and addresses in CJK languages |*24*| xref:master/ecosystem_components/pg_profile.adoc[pg_profile] | 4.11 | Collects statistics on resource-intensive database activities and generates historic workload reports based on delta analysis between two sample points, helping identify performance bottlenecks | Database performance analysis |*25*| xref:master/ecosystem_components/pg_repack.adoc[pg_repack] | 1.5.3 | Rebuilds tables and indexes online with minimal locking, eliminating storage bloat and achieving effects similar to VACUUM FULL | Online table and index rebuild, storage bloat reclamation -|*26*| xref:master/ecosystem_components/pgdog.adoc[PgDog] | 0.1.45 | High-performance, open-source clustering middleware (proxy tool) designed specifically for PostgreSQL and written in Rust | Connection pooler, load balancer, distributed database. -|*27*| xref:master/ecosystem_components/pg_readonly_en.adoc[pg_read_only] | 1.0.5 | Allows to set all PostgreSQL cluster databases read only. | System debugging、disaster recevory. -|*28*| xref:master/ecosystem_components/zhparser_en.adoc[zhparser] | master branch | PostgreSQL extension for full-text search of Chinese language (Mandarin Chinese). It implements a Chinese language parser base on the | Search engine、keyword extraction. +|*26*| xref:master/ecosystem_components/pgdog.adoc[PgDog] | 0.1.45 | High-performance, open-source clustering middleware (proxy tool) designed specifically for PostgreSQL and written in Rust | Connection pooler, load balancer, distributed database +|*27*| xref:master/ecosystem_components/pg_readonly_en.adoc[pg_read_only] | 1.0.5 | Allows to set all PostgreSQL cluster databases read only. | System debugging、disaster recevory +|*28*| xref:master/ecosystem_components/zhparser_en.adoc[zhparser] | master branch | PostgreSQL extension for full-text search of Chinese language (Mandarin Chinese). It implements a Chinese language parser base on the | Search engine、keyword extraction +|*29*| xref:master/ecosystem_components/pgbackrest.adoc[pgBackRest] | 2.58.0 | pgBackRest is a reliable backup and restore solution for PostgreSQL that seamlessly scales up to the largest databases and workloads | Disaster recovery backup, large database backup, off-site/multi-tier disaster recovery |==== These plugins have all been tested and adapted by the IvorySQL team to ensure stable operation in the IvorySQL environment. Users can select appropriate plugins based on business needs to further enhance the capabilities and flexibility of the database system. diff --git a/EN/modules/ROOT/pages/master/ecosystem_components/pgbackrest.adoc b/EN/modules/ROOT/pages/master/ecosystem_components/pgbackrest.adoc new file mode 100644 index 0000000..39a9807 --- /dev/null +++ b/EN/modules/ROOT/pages/master/ecosystem_components/pgbackrest.adoc @@ -0,0 +1,499 @@ +:sectnums: +:sectnumlevels: 5 + += pgBackRest + +== Overview + +pgBackRest is a reliable backup and restore solution for PostgreSQL. At its core, it is built on PostgreSQL physical-level backups (files in the data directory) and the WAL archive management mechanism. The project is notable for its high quality: 100% test coverage, high-quality code, and minimal dependencies. + +NOTE: pgBackRest introduced a CRC check of the pg_control file in v2.48.0. Since IvorySQL modifies the pg_control file layout, the pg-version-force option must be used in the stanza configuration to specify the PostgreSQL version corresponding to IvorySQL. + +NOTE: pgBackRest works with IvorySQL 5.x without modification, but this is merely a coincidence. In practice, it is still recommended to add the pg-version-force option. + +Project URL: + +Version: v2.58.0 + +License: MIT License + +== Installation + +[TIP] +The official website recommends installing from a package manager. + +[TIP] +The source build was tested on Ubuntu 26.04. + +=== Dependencies + +[source,bash] +---- +sudo apt update && \ +sudo apt-get install python3-setuptools meson gcc \ + libpq-dev libssl-dev libxml2-dev \ + pkg-config liblz4-dev libzstd-dev \ + libbz2-dev libz-dev libyaml-dev \ + libssh2-1-dev +---- + +=== Building from Source + +[source,bash] +---- +cd ~ +mkdir -p build +wget -q -O - \ + https://github.com/pgbackrest/pgbackrest/archive/release/2.58.0.tar.gz | \ + tar zx -C build +meson setup build/pgbackrest build/pgbackrest-release-2.58.0 +ninja -C build/pgbackrest + +# After compilation, the pgbackrest executable will be generated under build/src +./build/src/pgbackrest --version +---- + +=== Verifying the Installation + +NOTE: pgBackRest itself is a single executable; simply pass in a configuration file when using it. This document is for usage instructions only — no additional installation steps are required. + +== Configuration + +NOTE: pgBackRest supports multiple backup repositories. For details, see: + +NOTE: In the demonstration in this document, the PG database and the backup repository are on the same host, and the backup repository is a local file system. + +Configuration is required in two places: + +[cols="1,2"] +|=== +| File name | Description + +| postgresql.conf +| Configures `PostgreSQL`: add `archive_command` to enable `WAL` backup + +| pgbackrest.conf +| Configuration for `pgBackRest` itself, including the source database, backup repository, etc. +|=== + +Append to the end of `postgresql.conf`: + +NOTE: This is an example only; for actual steps, refer to the later sections of this document. + +[source,conf] +---- +port = 6551 +ivorysql.port = 6553 +listen_addresses = '127.0.0.1' +unix_socket_directories = '/tmp/.pgbr_sock_1000_6551' +archive_mode = on +archive_command = '/path/to/pgbackrest --config=/path/to/pgbackrest.conf --stanza=ivory archive-push %p' +log_min_messages = info +---- + +Create `pgbackrest.conf`: + +NOTE: This is an example only; for actual steps, refer to the later sections of this document. + +[source,conf] +---- +[global] +# With multiple repos configured, WAL is fully redundant and backups must be run manually +repo1-path=/tmp/pgbackrest_ivorysql/repo +# Retention period for full backups +repo1-retention-full=9999 +# Log files +log-path=/tmp/pgbackrest_ivorysql/log +# Console log level +log-level-console=info +# Log level for the log file +log-level-file=detail +# Do not wait for the next checkpoint +start-fast=y + +[$STANZA] +# Configuring multiple pg entries is for primary+replica setups; the numbering does not indicate primary/standby roles, which are detected automatically +pg1-path=/tmp/pgbackrest_ivorysql/pg1/data +pg1-port=6551 +pg1-socket-path='/tmp/.pgbr_sock_1000_6551' +pg-version-force=18 +---- + +== Usage + +=== pgBackRest Commands + +[source,bash] +---- +# Usage +pgbackrest [options] [command] +---- + +List of `pgBackRest` commands: + +[source,bash] +---- +# Add or modify a backup annotation; annotations are recorded in JSON form in the backup.info file +annotate + +# Fetch a WAL segment from the backup repository; invoked by PostgreSQL via restore_command. +# When running pgbackrest restore, it is automatically written into postgresql.auto.conf: +# "restore_command = 'pgbackrest --stanza=ivory archive-get %f "%p"'" +archive-get + +# Push a WAL segment into the backup repository — pushes the WAL segment PostgreSQL has just finished writing to the pgbackrest repository. +# Together with archive-get (one in, one out), it forms the foundation of PITR. +# Must be manually written into postgresql.conf: "archive_command = 'pgbackrest --stanza=ivory archive-push %p'" +archive-push + +# Back up the PG database: take a consistent backup of the entire data directory and write it to the repository. +backup + +# Check the configuration, verify repository information, and test the archiving pipeline (executes pg_switch_wal) +check + +# Delete expired backups and WAL archives that are no longer needed +expire + +# Display help information +help + +# Get information about backups +info + +# For debugging: fetch any file from the repository and write it to stdout or a local file. +repo-get + +# List files and directories in the repository via the storage driver +repo-ls + +# Restore a backup from the repository into a startable data directory, and automatically configure subsequent WAL replay. +restore + +# Run the transport service for multi-host deployments (TLS mode): moves backup data between hosts. Must run on both the PG and Repo hosts. +server + +# pgBackRest server liveness-check command +server-ping + +# Initialization command: create the stanza metadata skeleton for a cluster in the repository +stanza-create + +# Delete a stanza +stanza-delete + +# After a major database version upgrade, the stanza must be upgraded accordingly +stanza-upgrade + +# Does not start any process/service; its only job is to delete the stop file left by the stop command, allowing pgbackrest operations to resume. +start + +# Create a stop file; backup, archive-push, expire, stanza-create/upgrade, and remote requests will refuse to run when they detect this file at startup. +stop + +# Check whether existing backups and WAL are intact +verify + +# Get the current version +version +---- + +List of `pgBackRest` internal commands. These commands should not be used in production scenarios, as they may cause data corruption: + +[source,bash] +---- +# Dump the manifest of a backup in readable format +manifest + +# Write a file into the repository (encrypted automatically); the reverse of repo-get +repo-put + +# Delete repository files/directories (--recurse) +repo-rm +---- + +=== Performing Operations + +TIP: Since the process is fairly complex, the commands have been parameterized and helper functions have been created to make testing easier. Please run the commands below within the same terminal session. + +Variable preparation: + +[source,bash] +---- +# Adjust as appropriate for your environment: IVORY_PG_VERSION_MAJOR, IVORY_BIN, PGBACKREST_BIN; the rest can be left at defaults +IVORY_PG_VERSION_MAJOR=18 +IVORY_BIN="/usr/local/ivorysql/bin" +PGBACKREST_BIN="/home/lct/repos/pgbackrest/build/src/pgbackrest" +TEST_BASE="/tmp/pgbackrest_ivorysql_regress" +PG_PORT="6551" +STANDBY_PORT="6552" +ORA_PORT="6553" +STANDBY_ORA_PORT="6554" +DB_MODE="oracle" +STANZA="ivory" + +PG1_DATA="$TEST_BASE/pg1/data" +PG2_DATA="$TEST_BASE/pg2/data" +REPO_PATH="$TEST_BASE/repo" +# Unix socket paths have a 107-byte limit, so use a fixed short directory under /tmp +SOCK_PATH="${SOCK_PATH:-/tmp/.pgbr_sock_$(id -u)_$PG_PORT}" +LOG_PATH="$TEST_BASE/log" +CONF="$TEST_BASE/pgbackrest.conf" +RUN_LOG="$TEST_BASE/regression.log" +TEST_DB="regress" +RESTORE_POINT="pgb_regress_rp" + +sql() +{ + local port="$1" db="$2" query="$3" + "$IVORY_BIN/psql" -h "$SOCK_PATH" -p "$port" -d "$db" -U "$(id -un)" \ + -v ON_ERROR_STOP=1 -Atc "$query" 2>>"$RUN_LOG" +} +switch_wal_and_wait() +{ + local wal i + # First generate a WAL record, to avoid pg_switch_wal() being a no-op (which would not trigger archiving) when the current segment is empty + sql "$ORA_PORT" postgres "SELECT pg_create_restore_point('pgb_wal_sync')" >/dev/null || return 1 + wal=$(sql "$ORA_PORT" postgres "SELECT pg_walfile_name(pg_switch_wal())") || return 1 + for i in $(seq 1 60); do + local archived + archived=$(sql "$ORA_PORT" postgres "SELECT last_archived_wal FROM pg_stat_archiver") + [[ -n "$archived" && ! "$archived" < "$wal" ]] && return 0 + sleep 1 + done + return 1 +} +---- + +Preparation before execution: + +[source,bash] +---- +rm -rf "$SOCK_PATH" +mkdir -p "$PG1_DATA" "$REPO_PATH" "$SOCK_PATH" "$LOG_PATH" +chmod 700 "$PG1_DATA" "$SOCK_PATH" +: >"$RUN_LOG" +export LD_LIBRARY_PATH="$(dirname "$IVORY_BIN")/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" + +# Confirm the versions +${IVORY_BIN}/pg_ctl --version +${PGBACKREST_BIN} --version +---- + +Initialize the primary database and configuration: + +[source,bash] +---- +# Initialize, using oracle mode +"$IVORY_BIN/initdb" -D "$PG1_DATA" -m "$DB_MODE" -E UTF8 --no-locale -A trust -U "$(id -un)" + +# Configure IvorySQL +cat >>"$PG1_DATA/postgresql.conf" <"$CONF" < 100;"; + +# Perform the restore +"$IVORY_BIN/pg_ctl" -D "$PG1_DATA" -w -t 60 -m fast stop +"$PGBACKREST_BIN" --config="$CONF" --stanza="$STANZA" \ + --delta --type=name --target="$RESTORE_POINT" \ + --target-action=promote restore; + +# Verify; this md5 output should match the one above +"$IVORY_BIN/pg_ctl" -D "$PG1_DATA" -l "$LOG_PATH/pg1.log" -w start +sql "$ORA_PORT" "$TEST_DB" \ + "SELECT md5(string_agg(id::text || ':' || name, ',' ORDER BY id)) FROM t_ora;"; +----