Skip to content

Fix CREATE DATABASE/DROP DATABASE pipeline error; bump CI postgres to 17 - #102

Closed
Magisus wants to merge 3 commits into
mainfrom
fix-create-db-pipeline-error
Closed

Fix CREATE DATABASE/DROP DATABASE pipeline error; bump CI postgres to 17#102
Magisus wants to merge 3 commits into
mainfrom
fix-create-db-pipeline-error

Conversation

@Magisus

@Magisus Magisus commented Aug 19, 2026

Copy link
Copy Markdown

Summary

  • Root-caused the CI failure seen on other PRs (e.g. (PE-46077) Fix swapped select-keys args in select-user-configurable-hikari-options #101): create-db!-test/drop-db!-test error with PSQLException: CREATE DATABASE cannot be executed within a pipeline.
  • Root cause: clojure.java.jdbc/execute! always issues SQL through a PreparedStatement (extended query protocol), and create-db!'s multi-role branch additionally combined GRANT/CREATE DATABASE/REVOKE into one semicolon-joined string. Postgres now rejects CREATE DATABASE/DROP DATABASE issued this way — enforced as of Postgres 11.19/12.14/13.10/14.7/15.2 (see https://www.postgresql.org/message-id/841565.1677254194@sss.pgh.pa.us).
  • Fix: added execute-unpiped!, which runs each SQL string as its own plain, unbatched java.sql.Statement on a single connection, and used it in create-db!/drop-db!. Updated the handful of tests that issued CREATE/DROP DATABASE directly via jdbc/execute! to go through create-db!/drop-db! instead.
  • Also bumped the CI Postgres fixture from 14 to 17, to align with the Postgres version PE actually ships.

Test plan

  • lein check — no new warnings/errors from the changed code
  • clj-kondo --lint on changed files — no new warnings
  • CI (lein test :all against Postgres 17) — verifying create-db!-test/drop-db!-test now pass

🤖 Generated with Claude Code

Magisus and others added 2 commits August 19, 2026 14:19
Align the CI test database with the Postgres version PE actually ships,
rather than an older release.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…atement

create-db! and drop-db! (and several tests) ran their SQL through
clojure.java.jdbc's execute!, which always issues statements via a
PreparedStatement and, for create-db!'s multi-role branch, combined
GRANT/CREATE DATABASE/REVOKE into one semicolon-joined string. Postgres
now rejects CREATE DATABASE and DROP DATABASE when they arrive this way,
reporting "cannot be executed within a pipeline" (enforced as of Postgres
11.19/12.14/13.10/14.7/15.2, since running these commands without waiting
for a prior command's result could previously leave the database in an
inconsistent state if an earlier command failed).

Add execute-unpiped!, a small helper that runs each SQL string as its own
plain, unbatched java.sql.Statement on a single connection, and use it for
create-db! and drop-db!. Update the tests that issued CREATE/DROP DATABASE
directly via jdbc/execute! to go through create-db!/drop-db! instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Magisus
Magisus requested a review from a team as a code owner August 19, 2026 21:19
… owner

CREATE DATABASE ... OWNER other_role requires the connecting role to be
able to SET ROLE to other_role. Postgres 16 split that ability out of
plain role membership into its own SET privilege (pg_has_role's MEMBER
type now only means "some form of membership exists", regardless of
whether SET ROLE will work). Postgres 16 also changed CREATEROLE
semantics so creating a role only grants the creator an ADMIN-only,
SET-false membership over it automatically - enough to satisfy the old
MEMBER check, but not enough to actually SET ROLE to it.

create-db!'s pre-check therefore incorrectly concluded the caller could
already act as the target owner, skipped the temporary GRANT, and then
failed to CREATE DATABASE with "must be able to SET ROLE" on Postgres 16+.

Add a version-aware can-set-role? check (SET privilege on 16+, MEMBER
before) and include "WITH SET TRUE" on the temporary GRANT on 16+, where
that clause is available.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Magisus

Magisus commented Aug 19, 2026

Copy link
Copy Markdown
Author

Closing — same repo-mismatch issue as #101: PE builds puppetlabs/jdbc-util from puppetlabs/jdbc-util-private, not this repo. Also, on closer inspection jdbc-util-private's create-db! already avoids the 'cannot be executed within a pipeline' bug fixed here (it issues GRANT/CREATE DATABASE/REVOKE as separate statements rather than one combined string). The SET ROLE (Postgres 16+) issue may still apply there though — tracked in PE-46082.

@Magisus Magisus closed this Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant