CI/CD Guide¶
pg_stat_insights uses GitHub Actions for continuous integration and deployment across multiple PostgreSQL versions and platforms.
Workflows Overview¶
1. Build Matrix Workflow¶
File: .github/workflows/build-matrix.yml
Builds and tests pg_stat_insights across multiple PostgreSQL versions and platforms.
Features¶
- [OK] Multi-version support: PostgreSQL 14, 15, 16, 17
 - [OK] Multi-platform: Ubuntu, macOS, Rocky Linux
 - [OK] Automated testing: Runs all 22 regression tests
 - [OK] Package generation: DEB and RPM packages
 - [OK] Release creation: Optional GitHub release with artifacts
 
Trigger¶
Manual only - Run via GitHub Actions UI:
on:
  workflow_dispatch:
    inputs:
      pg_versions:
        description: 'PostgreSQL versions (comma-separated)'
        default: '14,15,16,17'
      platforms:
        description: 'Platforms (ubuntu,macos,rocky)'
        default: 'ubuntu,macos,rocky'
      create_release:
        description: 'Create GitHub release'
        type: boolean
        default: false
Build Matrix¶
| Platform | PostgreSQL 14 | PostgreSQL 15 | PostgreSQL 16 | PostgreSQL 17 | 
|---|---|---|---|---|
| Ubuntu 22.04 | [OK] | [OK] | [OK] | [OK] | 
| macOS 14 | [OK] | [OK] | [OK] | [OK] | 
| Rocky Linux 9 | [OK] | [OK] | [OK] | [OK] | 
Jobs¶
- Authorize - Check user permissions
 - Prepare - Generate build matrix
 - Build - Compile extension for each version/platform
 - Package DEB - Create Debian packages
 - Package RPM - Create RPM packages
 - Test Packages - Install and verify packages
 - Release - Create GitHub release (optional)
 - Summary - Generate build report
 
Running the Workflow¶
- Go to GitHub Actions tab
 - Select "Build Matrix" workflow
 - Click "Run workflow"
 - Configure options:
 - PostgreSQL versions: e.g., 
14,15,16,17 - Platforms: e.g., 
ubuntu,macos - Create release: Check if creating a release
 - Release tag: e.g., 
v1.0.1 - Click "Run workflow"
 
Artifacts¶
Build artifacts are retained for 30 days: - pg_stat_insights-ubuntu-pg14.tar.gz - pg_stat_insights-ubuntu-pg15.tar.gz - pg_stat_insights-ubuntu-pg16.tar.gz - pg_stat_insights-ubuntu-pg17.tar.gz - Similar for macOS and Rocky Linux
Test results are retained for 7 days: - test-results-ubuntu-pg14/ - regression.diffs - regression.out
2. Documentation Workflow¶
File: .github/workflows/docs.yml
Deploys MkDocs documentation to GitHub Pages.
Features¶
- [OK] MkDocs Material theme
 - [OK] Python 3.11
 - [OK] Dependency caching
 - [OK] Strict mode (catches doc errors)
 - [OK] GitHub Pages deployment
 
Trigger¶
Manual only - Run via GitHub Actions UI:
Running the Workflow¶
- Go to GitHub Actions tab
 - Select "Deploy Documentation" workflow
 - Click "Run workflow"
 - Click "Run workflow" button
 
Documentation will be deployed to: - URL: https://pgelephant.github.io/pg_stat_insights/
Documentation Structure¶
docs/
├── index.md                 # Homepage
├── getting-started.md       # Installation guide
├── configuration.md         # Configuration parameters
├── views.md                 # View reference
├── metrics.md               # Metric reference
├── usage.md                 # Usage examples
├── testing.md               # Testing guide
├── ci-cd.md                 # This file
├── troubleshooting.md       # Common issues
├── zh_CN/                   # Chinese (Simplified)
├── zh_TW/                   # Chinese (Traditional)
└── ja_JP/                   # Japanese
Package Building¶
DEB Packages (Ubuntu/Debian)¶
Generated for: - Ubuntu 22.04 (Jammy) - Ubuntu 24.04 (Noble) - Debian 11 (Bullseye) - Debian 12 (Bookworm)
Package naming: postgresql-<version>-pg-stat-insights_<ver>-<rel>_<arch>.deb
Example:
RPM Packages (RHEL/Rocky/AlmaLinux)¶
Generated for: - Rocky Linux 9 - AlmaLinux 9 - CentOS Stream 9
Package naming: pg_stat_insights_<pgver>-<ver>-<rel>.<dist>.<arch>.rpm
Example:
Version Compatibility¶
PostgreSQL Version Detection¶
The code automatically detects PostgreSQL version:
#if PG_VERSION_NUM >= 170000
#include "nodes/queryjumble.h"
#else
#include "utils/queryjumble.h"
#endif
Supported Versions¶
| PostgreSQL | Status | Notes | 
|---|---|---|
| 14 | [OK] Supported | Uses utils/queryjumble.h |  
| 15 | [OK] Supported | Uses utils/queryjumble.h |  
| 16 | [OK] Supported | Uses utils/queryjumble.h |  
| 17 | [OK] Supported | Uses nodes/queryjumble.h |  
Environment Setup¶
Ubuntu/Debian¶
# Install PostgreSQL repository
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | \
  gpg --dearmor | sudo tee /usr/share/keyrings/postgresql.gpg
echo "deb [signed-by=/usr/share/keyrings/postgresql.gpg] \
  http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | \
  sudo tee /etc/apt/sources.list.d/pgdg.list
# Install build dependencies
sudo apt-get update
sudo apt-get install -y \
  build-essential \
  postgresql-server-dev-17
macOS (Homebrew)¶
# Install PostgreSQL
brew install postgresql@17
# Set PG_CONFIG
export PG_CONFIG=/opt/homebrew/opt/postgresql@17/bin/pg_config
Rocky Linux/RHEL¶
# Install PostgreSQL repository
sudo dnf install -y epel-release
sudo dnf install -y \
  https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Disable built-in module
sudo dnf -qy module disable postgresql
# Install build dependencies
sudo dnf install -y \
  gcc \
  make \
  postgresql17-devel
Local Testing¶
Test Against Multiple Versions¶
# PostgreSQL 14
export PG_CONFIG=/usr/lib/postgresql/14/bin/pg_config
make clean && make && make installcheck
# PostgreSQL 15
export PG_CONFIG=/usr/lib/postgresql/15/bin/pg_config
make clean && make && make installcheck
# PostgreSQL 16
export PG_CONFIG=/usr/lib/postgresql/16/bin/pg_config
make clean && make && make installcheck
# PostgreSQL 17
export PG_CONFIG=/usr/lib/postgresql/17/bin/pg_config
make clean && make && make installcheck
Docker Testing¶
# PostgreSQL 14
docker run --rm -v $(pwd):/build -w /build \
  postgres:14 bash -c "\
  apt-get update && \
  apt-get install -y build-essential postgresql-server-dev-14 && \
  make clean && make && make installcheck"
# PostgreSQL 17
docker run --rm -v $(pwd):/build -w /build \
  postgres:17 bash -c "\
  apt-get update && \
  apt-get install -y build-essential postgresql-server-dev-17 && \
  make clean && make && make installcheck"
Release Process¶
1. Update Version¶
Update version in: - pg_stat_insights.control - default_version - Makefile - PACKAGE_VERSION - .github/workflows/build-matrix.yml - PACKAGE_VERSION - CHANGELOG.md - Add new release section
2. Update Documentation¶
3. Run Tests Locally¶
# Test on all versions
for ver in 14 15 16 17; do
  export PG_CONFIG=/usr/lib/postgresql/$ver/bin/pg_config
  make clean && make && make installcheck || exit 1
done
4. Commit and Tag¶
git add -A
git commit -m "chore: release v1.0.1"
git tag -a v1.0.1 -m "Release v1.0.1"
git push origin main --tags
5. Run GitHub Workflow¶
- Go to GitHub Actions
 - Select "Build Matrix"
 - Run workflow with:
 create_release: truerelease_tag: v1.0.1
6. Verify Release¶
Check: - [OK] All builds passed - [OK] All tests passed (22/22) - [OK] Packages generated - [OK] Release created with artifacts - [OK] SHA256SUMS included
Monitoring¶
GitHub Actions Status¶
Monitor workflow runs: - https://github.com/pgElephant/pg_stat_insights/actions
Build Times¶
Typical workflow duration: - Build: 3-5 minutes per version/platform - Package DEB: 5-10 minutes - Package RPM: 5-10 minutes - Total: 45-60 minutes for full matrix
Resource Usage¶
Concurrent jobs: - Maximum 20 concurrent runners (GitHub Free tier) - Each job runs independently - Matrix strategy parallelizes builds
Troubleshooting¶
Build Failures¶
Check logs:
Common issues: - PostgreSQL not started: Check PostgreSQL service status - Permission denied: Check file permissions - Test failures: Check regression.diffs artifact
Package Issues¶
DEB installation fails:
# Check dependencies
apt-cache depends postgresql-17-pg-stat-insights
# Manual install with fixes
sudo dpkg -i package.deb || sudo apt-get install -f -y
RPM installation fails:
# Check dependencies
rpm -qpR package.rpm
# Install with dependencies
sudo dnf install -y package.rpm
Documentation Issues¶
MkDocs build fails:
# Test locally
pip install -r docs-requirements.txt
mkdocs build --strict
# Check for errors in docs
mkdocs serve
Best Practices¶
- Always test locally before pushing
 - Run full test suite on all versions
 - Update CHANGELOG.md for every change
 - Version compatibility - test new PostgreSQL versions
 - Document breaking changes prominently
 - Keep workflows fast - optimize build steps
 - Monitor artifact size - clean up old artifacts
 - Use semantic versioning - MAJOR.MINOR.PATCH