Skip to content

Speed up integration-postgres specs#2770

Merged
aramprice merged 1 commit into
mainfrom
speedup-postgresql
Jul 14, 2026
Merged

Speed up integration-postgres specs#2770
aramprice merged 1 commit into
mainfrom
speedup-postgresql

Conversation

@aramprice

@aramprice aramprice commented Jul 13, 2026

Copy link
Copy Markdown
Member

Speed up integration-postgres by running PostgreSQL on tmpfs with WAL disabled

PostgreSQL integration tests were taking 3-5h vs MySQL's 2-3h despite running identical test suites. The root cause is that MySQL's data directory was explicitly mounted on a 512MB tmpfs (in-memory RAM disk) with binary logging disabled, while PostgreSQL used a plain on-disk path (/tmp/postgres) with default fsync and synchronous_commit settings.

Fix both asymmetries for PostgreSQL:

  • Mount a 512MB tmpfs on ${POSTGRES_ROOT} before initdb, mirroring the MySQL setup. All database I/O (schema creation, migrations, per-test drop/create cycles) now runs entirely in memory.
  • Add fsync = off and synchronous_commit = off to postgresql.conf, eliminating WAL flush overhead per transaction. This mirrors MySQL's skip-log-bin setting.

Expected result: integration-postgres build time drops from ~4h to ~2h30m, reaching parity with integration-mysql.

Integration run:

Compare with:

@aramprice aramprice requested a review from Copilot July 13, 2026 22:30
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The PostgreSQL setup defines data and log paths, ensures /tmp/postgres uses a correctly sized tmpfs, checks PG_VERSION, configures commit settings, conditionally starts or reloads PostgreSQL, waits for readiness, and creates the database idempotently. run_as now preserves quoted argument boundaries when invoking sudo.

Suggested reviewers: ivaylogi98, ay901246

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the main change and test results, but it omits several required template sections like release notes, breaking changes, and tags. Add the missing template sections: contextual info, release notes, breaking change status, tags, and AI review feedback.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: speeding up integration-postgres specs.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch speedup-postgresql

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to reduce integration-postgres runtime by aligning its filesystem and durability settings with the existing integration-mysql optimizations (tmpfs-backed data dir and reduced write-ahead logging overhead) in the CI task runner.

Changes:

  • Mount PostgreSQL’s data root (/tmp/postgres) on a 512MB tmpfs before initdb so database I/O stays in memory.
  • Append fsync = off and synchronous_commit = off to postgresql.conf to reduce WAL flush costs during tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ci/tasks/test-rake-task.sh Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread ci/tasks/test-rake-task.sh Outdated
Comment thread ci/tasks/test-rake-task.sh
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread ci/tasks/test-rake-task.sh
coderabbitai[bot]
coderabbitai Bot previously requested changes Jul 13, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/tasks/test-rake-task.sh`:
- Around line 94-101: Update the mount validation around POSTGRES_ROOT to verify
it is a tmpfs with the required 512 MB capacity, not merely any mounted
filesystem. If the existing mount does not match, fail closed or replace it
before continuing; preserve the current setup path for an unmounted directory.
- Line 142: Update the database setup command in the postgres task to remove the
unsupported --if-not-exists option; query pg_database for the uaa database
first, and invoke createdb only when that query confirms it is missing,
preserving idempotent behavior.
- Around line 140-142: Update the PostgreSQL startup flow around pg_ctl and
createdb to wait until the server accepts connections before running createdb.
Add a bounded pg_isready check or short retry loop using the existing DB_HOST
context, while preserving the current startup behavior and failing clearly if
readiness is not reached.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 85f5be65-15d4-4345-9a5f-a06e73b3dfff

📥 Commits

Reviewing files that changed from the base of the PR and between ff868dd and 811393d.

📒 Files selected for processing (1)
  • ci/tasks/test-rake-task.sh

Comment thread ci/tasks/test-rake-task.sh Outdated
Comment thread ci/tasks/test-rake-task.sh Outdated
Comment thread ci/tasks/test-rake-task.sh Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread ci/tasks/test-rake-task.sh Outdated
Comment thread ci/tasks/test-rake-task.sh
Comment thread ci/tasks/test-rake-task.sh Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/tasks/test-rake-task.sh`:
- Around line 99-103: Update the tmpfs setup around the _fstype check to also
validate the mounted POSTGRES_ROOT capacity is 512 MB. Remount it with the
existing 512M option when the filesystem type or capacity differs, and fail
closed if the capacity cannot be validated or the remount fails.
- Around line 128-129: Update the PostgreSQL setup flow in
ci/tasks/test-rake-task.sh so the fsync and synchronous_commit tuning settings
are written whenever the cluster is prepared, not only inside the
first-initialization path guarded by PG_VERSION. Keep the writes idempotent and
ensure reused clusters receive the settings before startup, or reload/restart
PostgreSQL if the configuration is changed after startup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f9b889f3-37ce-45e4-9546-a39a62a88ada

📥 Commits

Reviewing files that changed from the base of the PR and between 811393d and 0d2918a.

📒 Files selected for processing (1)
  • ci/tasks/test-rake-task.sh

Comment thread ci/tasks/test-rake-task.sh Outdated
Comment thread ci/tasks/test-rake-task.sh Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/tasks/test-rake-task.sh`:
- Around line 94-108: Update the remount logic in the ${POSTGRES_ROOT} tmpfs
validation block to fail immediately with a diagnostic if unmounting the
existing mount or mounting the 512M tmpfs fails. Remove the unconditional
suppression around umount, check the mount command’s exit status, and ensure
subsequent chown/processing only runs after a successful remount.
- Around line 167-171: Replace the raw sudo invocation in the pg_database check
with the existing run_as helper, passing postgres and the full psql command
arguments. Preserve the idempotent database existence check, its output piping
to grep, and the fallback run_as createdb invocation while restoring the
helper’s standard logging.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5470a5aa-8a9e-429e-ba54-8dced59f61a8

📥 Commits

Reviewing files that changed from the base of the PR and between 0d2918a and 905d3fb.

📒 Files selected for processing (1)
  • ci/tasks/test-rake-task.sh

Comment thread ci/tasks/test-rake-task.sh Outdated
Comment thread ci/tasks/test-rake-task.sh Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread ci/tasks/test-rake-task.sh Outdated
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread ci/tasks/test-rake-task.sh Outdated
Comment thread ci/tasks/test-rake-task.sh Outdated
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread ci/tasks/test-rake-task.sh Outdated
Comment thread ci/tasks/test-rake-task.sh
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 14, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/tasks/test-rake-task.sh`:
- Around line 157-159: Replace the single pg_isready invocation in the
PostgreSQL readiness check with a bounded retry loop that repeatedly runs
pg_isready until it succeeds. Preserve the existing postgres user, DB_HOST, and
DB_PORT arguments, add a short delay between attempts, and fail explicitly after
the retry limit is exhausted.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 773333b0-ba6e-4a8b-81ef-db4f715471be

📥 Commits

Reviewing files that changed from the base of the PR and between 0d2918a and d9a2797.

📒 Files selected for processing (1)
  • ci/tasks/test-rake-task.sh

Comment thread ci/tasks/test-rake-task.sh Outdated
@github-project-automation github-project-automation Bot moved this from Pending Merge | Prioritized to Waiting for Changes | Open for Contribution in Foundational Infrastructure Working Group Jul 14, 2026
… disabled

PostgreSQL integration tests were taking 3-5h vs MySQL's 2-3h despite running
identical test suites. The root cause is that MySQL's data directory was
explicitly mounted on a 512MB tmpfs (in-memory RAM disk) with binary logging
disabled, while PostgreSQL used a plain on-disk path (/tmp/postgres) with
default fsync and synchronous_commit settings.

Fix both asymmetries for PostgreSQL:
- Mount a 512MB tmpfs on ${POSTGRES_ROOT} before initdb, mirroring the MySQL
  setup. All database I/O (schema creation, migrations, per-test drop/create
  cycles) now runs entirely in memory.
- Disable fsync and synchronous_commit, eliminating WAL flush overhead per
  transaction. This mirrors MySQL's skip-log-bin setting.

Initialization guard uses ${PGDATA}/PG_VERSION (written only by a successful
initdb) rather than directory existence; a partial previous run cannot skip
re-initialization.

The tmpfs mount check runs unconditionally before the PG_VERSION guard and
requires all three conditions to accept an existing mount: (1) POSTGRES_ROOT
is itself a mountpoint — not merely on a parent tmpfs (e.g. if /tmp itself is
a 512M tmpfs, findmnt would report the parent's type/size without this check,
falsely passing), (2) the filesystem type is tmpfs, and (3) the mounted size
is 512M. The SIZE field is compared as bytes via findmnt --bytes to avoid
locale/version-dependent human-formatted output (e.g. "512M" vs "512.0M")
which could cause a false remount on every run. _fstype and _fssize are
declared local.

When remounting is needed, the server stop is structured as an explicit if
block so that pg_ctl stop failures surface rather than being masked; a masked
failure would cause the subsequent umount to fail with EBUSY. The existing
mount is removed without || true (fail closed on umount) and the new 512M
tmpfs is mounted.

The password file for initdb is explicitly chowned to postgres before initdb
runs so that restrictive umask values (e.g. 077) cannot prevent the postgres
user from reading the file.

run_as now correctly quotes "${@}" instead of ${@}, which previously caused
arguments containing spaces (such as -c "ALTER SYSTEM ...") to be word-split
by the shell. The # shellcheck disable=SC2068 annotation is also removed.

pg_ctl start, the readiness check, and createdb all run on every invocation:
- PGLOGS is created unconditionally before startup in case the cluster was
  preserved but the container was partially reset.
- A bounded retry loop (up to 30s) waits for the server to accept connections
  before any SQL is run. Raw sudo is used in the loop body to avoid printing
  "Running ... as postgres" on every retry iteration.
- Performance settings are applied via separate ALTER SYSTEM calls (one per
  statement) after startup. A compound -c "stmt1; stmt2" is not used because
  psql's simple query protocol wraps multi-statement strings in a single
  implicit transaction, and ALTER SYSTEM cannot run inside a transaction block.
  ALTER SYSTEM writes idempotently to postgresql.auto.conf (not postgresql.conf)
  and ensures fsync=off and synchronous_commit=off are active for both fresh
  and reused clusters. Both have sighup context so pg_reload_conf() applies
  them without a restart.
- createdb lacks --if-not-exists; pg_database is queried with command
  substitution (not a pipe) so that psql connection failures abort the script
  rather than being silently treated as "database does not exist". Raw sudo is
  used to prevent run_as's stdout echo from polluting the captured query result.
- All pg_isready, psql, and createdb calls use ${DB_HOST} and ${DB_PORT}
  consistently.

Expected result: integration-postgres build time drops from ~4h to ~2h30m,
reaching parity with integration-mysql.
@aramprice aramprice force-pushed the speedup-postgresql branch from d9a2797 to ace1ffd Compare July 14, 2026 01:47
@github-project-automation github-project-automation Bot moved this from Waiting for Changes | Open for Contribution to Pending Merge | Prioritized in Foundational Infrastructure Working Group Jul 14, 2026

@ragaskar ragaskar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM -- I assume any unexpected issues that might fall out from the config changes could be addressed w/ future commits.

@aramprice aramprice merged commit bb4c067 into main Jul 14, 2026
24 checks passed
@github-project-automation github-project-automation Bot moved this from Pending Merge | Prioritized to Done in Foundational Infrastructure Working Group Jul 14, 2026
@aramprice aramprice deleted the speedup-postgresql branch July 14, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants