Skip to content

Conversation

@gspanos
Copy link
Collaborator

@gspanos gspanos commented Jun 3, 2025

SUMMARY

Fixes #864

Fixes postgresql_db "session_role" behavior when state is dump/restore for binary (.pgc) archives.
It was being ignored but now it behaves as intended by pg_dump/pg_restore

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

postgresql_db

ADDITIONAL INFORMATION

When pg_dump is used, the --role parameter is used to switch to a different user/role that has sufficient permissions to perform the dump.

When pg_restore is used, the --role parameter, in combination with --no-owner, allows you to restore the objects contained in the archive under new ownership (the one specified with --role).

Up to now, whenever pg_dump/pg_restore was used, the session_role parameter was being ignored and it would give surprising results (or errors).

Now the session_role below will be relayed as the --role parameter for pg_dump/pg_restore.

- name: pg_restore archive on dst_db with session_role
  postgresql_db:
    login_user: postgres
    name: dst_db
    state: restore
    target: /tmp/archive.pgc
    session_role: restoration_role
    target_opts: "--no-owner"

I chose to create a new test python module for this feature, as it seemed cleaner and less intrusive with regards to the current integration tests.

@gspanos gspanos marked this pull request as draft June 3, 2025 12:25
@gspanos gspanos force-pushed the db_dump_restore_session_role branch from 7887aa1 to 78b5b68 Compare June 3, 2025 12:50
@Andersson007
Copy link
Collaborator

@gspanos thanks for the fix! LGTM
Could you please:

  • add a changelog fragment
  • mark it as "ready for review" when it's ready. now it's still a draft

Thanks

@gspanos gspanos force-pushed the db_dump_restore_session_role branch from 78b5b68 to 1aa047f Compare June 4, 2025 10:24
@gspanos gspanos marked this pull request as ready for review June 4, 2025 10:26
@Andersson007 Andersson007 merged commit de36216 into ansible-collections:main Jun 5, 2025
30 checks passed
@Andersson007
Copy link
Collaborator

@gspanos @hunleyd @andreasscherbaum thanks for the contribution!

@Andersson007 Andersson007 added the backport-3 Put it on PR to backport to stable-3 (only bug/doc fixes) label Dec 4, 2025
@patchback
Copy link

patchback bot commented Dec 4, 2025

Backport to stable-3: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-3/de362160f4be9459dd2ad6292565ae700f4c625e/pr-865

Backported as #903

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Dec 4, 2025
Andersson007 pushed a commit that referenced this pull request Dec 8, 2025
… support for raw connections (#903)

* postgresql_db: fix session_role support for raw connections (#865)

(cherry picked from commit de36216)

* postgresql_db: fix integration test for fedora42 (#906)

---------

Co-authored-by: George Spanos <gspanos@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-3 Put it on PR to backport to stable-3 (only bug/doc fixes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

community.postgresql.postgresql_db - session_role not respected when state is dump/restore

4 participants