This is a personal collection of shell scripts to easily develop and test several PostgreSQL at once.
Checkout the project somewhere convenient (e.g. ~/prj/pgenv)
git clone https://github.com/irionr/pgenv.git ~/prj/pgenv
The PostgreSQL/BDR source trees live in $HOME/pgsql by default. This is
controlled by the SOURCE_DIR variable in pgenv-lib.sh.
Add the following lines to ~/.bashrc or ~/.zshrc
# pgenv
if [ -r "$HOME/prj/pgenv/pgenv.sh" ] ; then
. "$HOME/prj/pgenv/pgenv.sh"
fi
Reload the current shell
exec bash
pgenv-lib.sh # shared library: configuration, helpers, all functions
pgenv.sh # interactive shell integration (pgworkon, etc.)
pull-all.sh # wrapper → pgenv_pull_all
clean-all.sh # wrapper → pgenv_clean_all
configure-all.sh # wrapper → pgenv_configure_all
install-all.sh # wrapper → pgenv_install_all
new-branch.sh # wrapper → pgenv_new_branch
All logic lives in pgenv-lib.sh as functions. The individual *.sh scripts
are thin wrappers for CLI use. After sourcing pgenv.sh, the functions are
also available directly in your shell (e.g. pgenv_clean_all 17).
pgenv-lib.sh defines two key variables at the top:
| Variable | Default | Purpose |
|---|---|---|
SOURCE_DIR |
$HOME/pgsql |
Where PostgreSQL/BDR source trees live |
CURRENT_DEVEL |
20 |
Current development branch major version |
When a new PostgreSQL major version enters development, bump CURRENT_DEVEL.
| Prefix | Example | Branch pattern | Base port |
|---|---|---|---|
| (none) | 17 |
REL_17_STABLE |
5400 |
PGE |
PGE |
BDRPG-master |
6400 |
PGE |
PGE14 |
2QREL_14_STABLE_dev |
7400 |
36PGE |
36PGE14 |
2QREL_14_STABLE_3_6 |
8400 |
EDBAS |
EDBAS |
EDBAS-master |
9400 |
EDBAS |
EDBAS16 |
EDBAS_16_STABLE |
10400 |
BDRPG |
BDRPG |
BDRPG-master |
11400 |
BDRPG |
BDRPG16 |
BDRPG_16_STABLE |
12400 |
Using master or the CURRENT_DEVEL number resolves to the master branch.
Bare flavor names without a version (e.g. PGE, EDBAS, BDRPG) resolve
to the corresponding *-master branch with their own base port.
Initial postgresql checkout
git clone git://git.postgresql.org/git/postgresql.git $HOME/pgsql/master
NOTE: Optionally, you can also use PGE or EDBAS, clone the repositories in
$HOME/pgsql/2QREL-masteror$HOME/pgsql/EDBAS-masterrespectively.
On Rocky linux, required packages:
sudo dnf install readline-devel openssl-devel libxml2-devel tcl-devel bison flex libcurl-devel
In Ubuntu, install these packages, which are necessary for configure-all.sh
sudo apt-get install tcl-dev libssl-dev build-essential bison flex \
libreadline-dev libxml2-dev
If you use openSUSE, you must install these packages:
sudo zypper in -t pattern devel_C_C++
sudo zypper in tcl-devel libxml2-devel readline-devel libopenssl-devel
If you use Archlinux, please be sure that these packages are installed:
sudo pacman -S tcl libxml2 openssl bison flex base-devel
On macOS, install these packages via Homebrew:
brew install openssl readline libxml2 llvm
openssl/readline/libxml2/llvm are all keg-only, so configure-all.sh
resolves their install paths itself — no manual PATH/LDFLAGS setup needed.
llvm in particular is required: --with-llvm is always passed, and
configure-all.sh looks for llvm-config under $(brew --prefix)/opt/llvm*,
picking the newest installed version if more than one is present (e.g.
llvm@18 and llvm@20). If none is installed, configure fails fast with an
error telling you to brew install llvm.
Build and install the development head version
./configure-all.sh master
./install-all.sh master
Add a $VERSION checkout (e.g. 17, 16, etc.)
To use PGE with 3.6 BDR/PGL stack use the 36PGE prefix (e.g. 36PGE14, 36PGE15)
To use PGE with BDR/PGL version 3.7 or later use only the PGE prefix (e.g. PGE14, PGE16)
For EDBAS use the EDBAS prefix (e.g. EDBAS15, EDBAS16)
Optionally set bdr and pglogical environment variables pointing to your
clone of the bdr and pglogical repository.
Add the following lines to ~/.bashrc
# github private repos
export PGL_REPO="$HOME/pgsql/pglogical"
export BDR_REPO="$HOME/pgsql/bdr"
./new-branch.sh $VERSION
Build and install the $VERSION version
./configure-all.sh $VERSION
./install-all.sh $VERSION
Upgrade all the installed versions
./pull-all.sh
./clean-all.sh
./configure-all.sh
./install-all.sh
Upgrade only one version (numeric version or master)
./pull-all.sh
./clean-all.sh $VERSION
./configure-all.sh $VERSION
./install-all.sh $VERSION
pull-all.sh and clean-all.sh run branches in parallel with a progress bar.
Output is redirected to per-branch log files under
$SOURCE_DIR/.pgenv/logs/{pull,clean}/<branch>.log. Failed branches are
reported at the end with a pointer to the relevant log file.
install-all.sh builds at most 4 branches concurrently (fewer if there are
fewer branches to build), splitting the available CPU cores across them for
make -j. This keeps overall CPU usage bounded instead of running every
branch's build at once. All branch subshells start immediately (so the
progress display is live from the start); each acquires a build slot via
atomic mkdir under $SOURCE_DIR/.pgenv/logs/install/.slots/ before
compiling and releases it on exit. The slots directory is wiped at the start
of every run, so an interrupted run cannot leak slots.
Usage: pgworkon <flavor><version> [<ticket> [<BDR version>]]
Activates a PostgreSQL development environment. See the Flavors table above for valid prefixes.
The second (optional) argument is the ticket number. It creates a work
directory under $HOME/work/<ticket>/ with a git worktree branched as
dev/fi/<ticket>.<branch> (e.g. dev/fi/BDR-8741.BDRPG_18_STABLE) — the
branch is suffixed with the PG worktree's own dir name so a second flavor
or version added later to the same ticket doesn't collide with one already
checked out. For BDR-* tickets, a bdr worktree is also created, plus a
pglogical worktree when the BDR version is 3.6/3.7 (pglogical was merged
into BDR from 4 on). For PG-* tickets, only the PostgreSQL worktree is set up.
Running pgworkon again for the same ticket with a different flavor/version
(e.g. pgworkon BDRPG17 BDR-8741 after pgworkon BDRPG18 BDR-8741) adds
that PG worktree alongside the existing one — it does not replace it.
The third (optional) argument is the BDR extension version (e.g. main, 6,
5, 4, 3.7, 3.6). Defaults to main. When a version other than main
is given, both the bdr worktree directory and its branch are named after it
— e.g. bdr6 on branch dev/fi/<ticket>.r6 — instead of the plain bdr on
dev/fi/<ticket>. This lets a different BDR version for the same ticket
coexist instead of colliding (git can't check out the same branch in two
worktrees). The pglogical worktree (pgl, branch dev/fi/<ticket>, BDR 3.x
only) is not version-suffixed — only one pglogical checkout exists per ticket regardless
of how many BDR versions you work on.
Example:
pgworkon PGE14 BDR-42 4
This creates the worktree $HOME/work/BDR-42/bdr4 (branch dev/fi/BDR-42.r4),
using Postgres Extended v14 and BDR v4. With 3.7 instead of 4 it would
also create $HOME/work/BDR-42/pgl (branch dev/fi/BDR-42).
Usage: pgreinit
Destroys the current $PGDATA and runs initdb again with BDR-friendly
defaults. Only available after a pgworkon call.
Controls the state of the current environment. Only available after a
pgworkon call. Accepts an optional test instance name to target a specific
TAP test node instead of the main instance.
Resets the environment and unsets all pgenv variables and functions.
Usage: pgpsql [<node>] [<database>]
Connects psql to a running test instance (regression or TAP). For TAP
instances, the first argument is the node name and the second is the database
(defaults to bdrtest).
Usage: pgpgbench <node> [<pgbench args>] [<database>]
Same as pgpsql but runs pgbench instead, with optional pgbench arguments.