Skip to content

fix(pgrx-tests): respect configured PostgreSQL GUCs#2337

Merged
eeeebbbbrrrr merged 1 commit into
pgcentralfoundation:developfrom
0xPoe:poe-patch-guc
Jul 13, 2026
Merged

fix(pgrx-tests): respect configured PostgreSQL GUCs#2337
eeeebbbbrrrr merged 1 commit into
pgcentralfoundation:developfrom
0xPoe:poe-patch-guc

Conversation

@0xPoe

@0xPoe 0xPoe commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

close #2151

pgrx-tests sets a few session-level logging defaults when creating a client. In this PR, I have baked pgrx's defaults into postgresql.conf. Now they can be overridden by the user's postgresql_conf_options.

I just added a simple unit test instead of an integration test, as there is no existing integration test suite in the pgrx-tests crate.

@0xPoe 0xPoe left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🔢 Self-check (PR reviewed by myself and ready for feedback)

  • Code compiles successfully

  • Unit tests added

  • No AI-generated elegant nonsense in PR.

  • Comments added where necessary

  • PR title and description updated

  • PR size is reasonable

Comment thread pgrx-tests/src/framework.rs Outdated
@eeeebbbbrrrr

Copy link
Copy Markdown
Contributor

Rather than issuing SETs ourselves I think we should bake pgrx's defaults into "postgresql.conf" and allow what an extension specifies in its fn postgresql_conf_options() to override our defaults.

Thoughts? Wanna rework this?

@0xPoe

0xPoe commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Rather than issuing SETs ourselves I think we should bake pgrx's defaults into "postgresql.conf" and allow what an extension specifies in its fn postgresql_conf_options() to override our defaults.

Thoughts? Wanna rework this?

Makes sense. I'll rework this by moving the pgrx logging defaults into the generated Postgres config.

@0xPoe

0xPoe commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

I have tested locally:

  1. Setup a new pgrx project:
WORK="$(mktemp -d)"
cd "$WORK"

cargo install --git "https://github.com/0xPoe/pgrx.git" --branch "poe-patch-guc" cargo-pgrx --root "$WORK/.tools"

"$WORK/.tools/bin/cargo-pgrx" pgrx new pgrx_issue2151_check
cd pgrx_issue2151_check
  1. Update the Cargo.toml to use this PR:
[patch.crates-io]
pgrx = { git = "https://github.com/0xPoe/pgrx.git", branch = "poe-patch-guc" }
pgrx-tests = { git = "https://github.com/0xPoe/pgrx.git", branch = "poe-patch-guc" }
  1. Replace src/lib.rs with this full file:
cat > src/lib.rs <<'EOF'
use pgrx::prelude::*;

::pgrx::pg_module_magic!(name, version);

#[pg_extern]
fn hello_pgrx_issue2151_check() -> &'static str {
    "Hello, pgrx_issue2151_check"
}

#[cfg(any(test, feature = "pg_test"))]
#[pg_schema]
mod tests {
    #[pgrx::pg_test]
    fn postgresql_conf_options_controls_log_min_messages() {
        let value = pgrx::Spi::get_one::<String>("SELECT current_setting('log_min_messages');")
            .expect("SPI should succeed")
            .expect("current_setting should return a value");

        assert_eq!(value, "debug1");
    }
}

/// This module is required by `cargo pgrx test` invocations.
/// It must be visible at the root of your extension crate.
#[cfg(test)]
pub mod pg_test {
    pub fn setup(_options: Vec<&str>) {}

    #[must_use]
    pub fn postgresql_conf_options() -> Vec<&'static str> {
        vec!["log_min_messages = debug1"]
    }
}
EOF
  1. Run the test:
CARGO_PGRX_TEST_PGDATA="$WORK/pgdata" \
cargo test --no-default-features --features pg18 --lib \
postgresql_conf_options_controls_log_min_messages -- --nocapture
  1. Test result:
test tests::pg_postgresql_conf_options_controls_log_min_messages ... ok

@0xPoe 0xPoe left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🔢 Self-check (PR reviewed by myself and ready for feedback)

Comment thread pgrx-tests/src/framework.rs
@eeeebbbbrrrr
eeeebbbbrrrr merged commit 60cf79c into pgcentralfoundation:develop Jul 13, 2026
16 checks passed
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.

Setting log_min_messages in postgresql_conf_options does not work

2 participants