Skip to content

Conversation

@gspanos
Copy link
Contributor

@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!

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.

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

4 participants