Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New module postgresql_slot: Add or remove slots from a PostgreSQL database #55079

Merged
merged 5 commits into from
Apr 10, 2019

Conversation

Andersson007
Copy link
Contributor

SUMMARY

Add or remove physical or logical slots from a PostgreSQL database.

For more information see:
https://www.postgresql.org/docs/current/protocol-replication.html and
https://www.postgresql.org/docs/current/logicaldecoding-explanation.html

ISSUE TYPE
  • New Module Pull Request
SPECIFIC OPTIONS
  • name: Name of the slot to add or remove. aliases: [ slot_name]
  • slot_type: Slot type. choices: [ logical, physical ]
  • state: The slot state.
  • immediately_reserve: Optional parameter the when C(yes) specifies that the LSN for this replication slot be reserved immediately, otherwise the default, C(no), specifies that the LSN is reserved on the first connection from a streaming replication client. Uses only with I(slot_type=physical).
  • output_plugin: All logical slots must indicate which output plugin decoder they're using. This parameter does not apply to physical slots. It will be ignored with I(slot_type=physical).
RETURN
name:
  description: Name of the slot
  returned: always
  type: str
  sample: "physical_one"
queries:
  description: List of executed queries.
  returned: always
  type: str
  sample: [ "SELECT pg_create_physical_replication_slot('physical_one', False, False)" ]
EXAMPLES
- name: Create physical_one physical slot if doesn't exist
  become_user: postgres
  postgresql_slot:
    slot_name: physical_one
    db: ansible

- name: Remove physical_one slot if exists
  become_user: postgres
  postgresql_slot:
    slot_name: physical_one
    db: ansible
    state: absent

- name: Create logical_one logical slot to the database acme if doen't exist
  postgresql_slot:
    name: logical_slot_one
    slot_type: logical
    state: present
    output_plugin: custom_decoder_one

- name: Remove logical_one slot if exists from the cluster running on another host and non-standard port
  postgresql_slot:
    name: logical_one
    login_host: mydatabase.example.org
    port: 5433
    login_user: ourSuperuser
    login_password: thePassword
    state: absent

@ansibot
Copy link
Contributor

ansibot commented Apr 10, 2019

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 community_review In order to be merged, this PR must follow the community review workflow. database Database category module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_module This PR includes a new module. new_plugin This PR includes a new plugin. postgresql PostgreSQL community support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests. labels Apr 10, 2019
@Andersson007
Copy link
Contributor Author

instead of #39902

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Apr 10, 2019
Copy link
Contributor

@gundalow gundalow left a comment

Choose a reason for hiding this comment

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

Do we have a test for updating from slot_type physical to logical (or reversed)?

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Apr 10, 2019
@Andersson007
Copy link
Contributor Author

Andersson007 commented Apr 10, 2019

Do we have a test for updating from slot_type physical to logical (or reversed)?

@gundalow
If I understood your question right it's impossible to make logical from physical, etc.
(technically I can implement this but it looks quite dangerous. better to remove a slot at first, then create new one with suitable type)

@Andersson007
Copy link
Contributor Author

@gundalow , and I remember about moving function connect_to_db() to module_utils.
I've added also get_pg_version().
Going to do it by single PR for all modules.

@ansibot
Copy link
Contributor

ansibot commented Apr 10, 2019

@Dorn- @andytom @antoinell @archf @b6d @dschep @jbscalia @jensdepuydt @kostiantyn-nemchenko @kustodian @matburt @nerzhul @sebasmannem @wrouesnel

As a maintainer of a module in the same namespace this new module has been submitted to, your vote counts for shipits. Please review this module and add shipit if you would like to see it merged.

click here for bot help

@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Apr 10, 2019
@gundalow
Copy link
Contributor

Does the module need to gracefully error if someone attempts to change slot_type then?

@Andersson007
Copy link
Contributor Author

Does the module need to gracefully error if someone attempts to change slot_type then?

@gundalow , lines 243-244 below

238     def create(self, kind='physical', immediately_reserve=False, output_plugin=False, just_check=False):
239         if self.exists:
240             if self.kind == kind:
241                 return False
242             else:
243                 self.module.warn("slot with name '%s' already exists "
244                                  "but has another type '%s'" % (self.name, self.kind))
245                 return False

@gundalow gundalow merged commit a971a0e into ansible:devel Apr 10, 2019
@gundalow
Copy link
Contributor

@Andersson007 Thank you for another great module and test :)

@Andersson007
Copy link
Contributor Author

@gundalow , thank you for reviews and merge !

@ansible ansible locked and limited conversation to collaborators Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 community_review In order to be merged, this PR must follow the community review workflow. database Database category module This issue/PR relates to a module. new_module This PR includes a new module. new_plugin This PR includes a new plugin. postgresql PostgreSQL community support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants