-
Notifications
You must be signed in to change notification settings - Fork 37
Switch to PostgreSQL 16 image #577
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,79 @@ | ||||||||
| --- | ||||||||
| - name: Check if PG_VERSION file exists | ||||||||
| ansible.builtin.stat: | ||||||||
| path: "{{ postgresql_data_dir }}/userdata/PG_VERSION" | ||||||||
| register: postgresql_version_file | ||||||||
|
|
||||||||
| - name: Set postgresql_version version fact | ||||||||
| when: postgresql_version_file.stat.exists | ||||||||
| block: | ||||||||
| - name: Read PG_VERSION file | ||||||||
| ansible.builtin.slurp: | ||||||||
| src: "{{ postgresql_data_dir }}/userdata/PG_VERSION" | ||||||||
| register: postgresql_version_encoded | ||||||||
|
|
||||||||
| - name: Register PG version fact | ||||||||
| ansible.builtin.set_fact: | ||||||||
| postgresql_version: "{{ postgresql_version_encoded.content | b64decode | trim }}" | ||||||||
|
|
||||||||
| - name: Upgrade PostgreSQL 13 to 16 | ||||||||
| when: | ||||||||
| - "postgresql_version is defined" | ||||||||
| - "postgresql_version == '13'" | ||||||||
| block: | ||||||||
| - name: Stop foreman target | ||||||||
| ansible.builtin.systemd: | ||||||||
| name: foreman.target | ||||||||
| state: stopped | ||||||||
|
|
||||||||
| - name: Wait for port 5432 to be completely freed by Podman | ||||||||
| ansible.builtin.wait_for: | ||||||||
| port: 5432 | ||||||||
| state: stopped | ||||||||
| timeout: 30 | ||||||||
|
|
||||||||
| - name: Deploy PostgreSQL upgrade container | ||||||||
| containers.podman.podman_container: | ||||||||
| name: "{{ postgresql_container_name }}-upgrade" | ||||||||
| image: postgresql.image | ||||||||
| state: quadlet | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it need to be a quadlet? In favor of it means you get logs in the journal, but it's also fragile: if Ansible somehow starts, it can leave the system in an unpredictable state.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't follow this logic. However, I assume you are asking the question of a quadlet which generates a systemd service vs. just running the container directly with the equivalent of a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I had the same question. I decided to go on with a quadlet to reuse the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And I messed up: I intended to write "Ansible somehow stops in the middle". Not start.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it is disastrous:
There are options to add the upgrade as a dependency for the I think it's too complex for a one time only step. |
||||||||
| sdnotify: false | ||||||||
| volumes: | ||||||||
| - "{{ postgresql_data_dir }}:/var/lib/pgsql/data:rw,Z" | ||||||||
| secrets: | ||||||||
| - 'postgresql-admin-password,target=POSTGRESQL_ADMIN_PASSWORD,type=env' | ||||||||
| env: | ||||||||
| POSTGRESQL_MAX_CONNECTIONS: "{{ postgresql_max_connections }}" | ||||||||
| POSTGRESQL_SHARED_BUFFERS: "{{ postgresql_shared_buffers }}" | ||||||||
| POSTGRESQL_EFFECTIVE_CACHE_SIZE: "{{ postgresql_effective_cache_size }}" | ||||||||
| # explicitly set the previous version to avoid the upgrade failure | ||||||||
| # see https://github.com/sclorg/postgresql-container/issues/661 | ||||||||
| POSTGRESQL_PREV_VERSION: "{{ postgresql_version }}" | ||||||||
| POSTGRESQL_UPGRADE: "{{ postgresql_upgrade }}" | ||||||||
| command: "run-postgresql -V" | ||||||||
| quadlet_options: | ||||||||
| - | | ||||||||
| [Unit] | ||||||||
| Description=PostgreSQL Database Upgrade from 13 to 16 | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps make sure that systemd knows it's 1 or the other? Or will this introduce too much uncertainty?
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Gemini, the directive is symmetric, so it won't protect us from someone that tries to start the server. Actually it will just cause the upgrade container to stop (even more problematic in the middle of an upgrade). |
||||||||
| [Service] | ||||||||
| Type=oneshot | ||||||||
| RemainAfterExit=yes | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means the service will remain as active. Is that useful?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will mark the service as |
||||||||
| TimeoutStartSec=30m | ||||||||
| - name: Run daemon reload to make Quadlet create the upgrade service file | ||||||||
| ansible.builtin.systemd: | ||||||||
| daemon_reload: true | ||||||||
|
|
||||||||
| - name: Upgrade the database from 13 to 16 but don't start the server | ||||||||
| ansible.builtin.systemd: | ||||||||
| name: "{{ postgresql_container_name }}-upgrade.service" | ||||||||
| state: restarted | ||||||||
|
|
||||||||
| - name: Remove the quadlet file | ||||||||
| ansible.builtin.file: | ||||||||
| path: "/etc/containers/systemd/{{ postgresql_container_name }}-upgrade.container" | ||||||||
| state: absent | ||||||||
|
|
||||||||
| - name: Reload systemd | ||||||||
| ansible.builtin.systemd_service: | ||||||||
| daemon_reload: true | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,17 @@ | |
| ansible.builtin.include_role: | ||
| name: debug_tools | ||
|
|
||
| - name: 'Enable postgresql:16 module' | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @evgeni, let me ask this question again: wouldn't it be more resilient to run the PG commands from inside a PG container instead of installing the client tooling directly on the host?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would, sure. I just had none that I could integrate easily into the various workflows where we need Postgres tooling on the host.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'd likely want to write a module that does this to be re-used because there are postgres actions that are run in a lot more places. I am not sure I see the value of it at the moment but it might be worth exploring after we get everything else.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ehelms Debian 13 has PostgreSQL 17. That probably means you can't run |
||
| ansible.builtin.command: dnf module enable -y postgresql:16 | ||
| # can't use the `dnf` module for modules without a default stream | ||
| # https://github.com/ansible/ansible/issues/56504 | ||
| # https://github.com/ansible/ansible/issues/64852 | ||
| args: | ||
| creates: /etc/dnf/modules.d/postgresql.module | ||
| when: | ||
| - ansible_facts['os_family'] == 'RedHat' | ||
| - ansible_facts['distribution_major_version'] == '9' | ||
|
|
||
| - name: Install podman and utilities | ||
| ansible.builtin.package: | ||
| name: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.