Skip to content
This repository was archived by the owner on Dec 21, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1526028
PMM-5885 upgrade postgres to 14
nikita-b May 11, 2022
0899905
fix
nikita-b May 11, 2022
605d914
Merge branch 'main' into PMM-5885-upgrade-postgres-to-14
nikita-b May 19, 2022
507feaf
PMM-5885 clean yum
nikita-b May 19, 2022
abbfd23
Merge branch 'PMM-5885-upgrade-postgres-to-14' of github.com:percona/…
nikita-b May 19, 2022
241f53d
fix check mode
nikita-b May 19, 2022
79983bc
fix service name
nikita-b May 19, 2022
fea7544
fix become
nikita-b May 19, 2022
0d6c64b
fix
nikita-b May 19, 2022
2a6eb65
ansible check
nikita-b May 19, 2022
f8ad500
fix syntax
nikita-b May 19, 2022
d323438
Update ansible/playbook/tasks/roles/postgres/tasks/main.yml
nikita-b May 19, 2022
d8fe797
Update ansible/playbook/tasks/roles/initialization/tasks/main.yml
nikita-b May 19, 2022
b7f3838
Merge branch 'main' into PMM-5885-upgrade-postgres-to-14
May 25, 2022
4eaead7
Update ansible/playbook/tasks/roles/postgres/tasks/main.yml
nikita-b May 25, 2022
0676ea1
Update ansible/playbook/tasks/roles/postgres/tasks/main.yml
nikita-b May 25, 2022
7f6cdcb
Update ansible/playbook/tasks/roles/postgres/tasks/main.yml
nikita-b May 25, 2022
40b09b5
fix
nikita-b May 26, 2022
a153011
Merge branch 'PMM-5885-upgrade-postgres-to-14' of github.com:percona/…
nikita-b May 26, 2022
ffb52fd
fix
nikita-b May 26, 2022
c1d0ae1
fix
nikita-b May 27, 2022
44e3e48
fix python deps
nikita-b May 27, 2022
a02cbcc
fix ext postgres
nikita-b May 30, 2022
420b965
fix
nikita-b May 30, 2022
f7ce725
add supervisor config
nikita-b May 30, 2022
09ba813
fix
nikita-b May 30, 2022
5f95392
Merge branch 'main' into PMM-5885-upgrade-postgres-to-14
nikita-b May 30, 2022
9cd07e3
fix
nikita-b May 30, 2022
6b56d72
Merge branch 'PMM-5885-upgrade-postgres-to-14' of github.com:percona/…
nikita-b May 30, 2022
166f71f
move supervisor settings from pmm-server
nikita-b May 31, 2022
b9c372f
fix
nikita-b May 31, 2022
11fea48
fix module name
nikita-b May 31, 2022
46835de
fix upgrade bug
nikita-b Jun 7, 2022
71e2154
Merge branch 'main' into PMM-5885-upgrade-postgres-to-14
nikita-b Jun 7, 2022
ed00819
fix upgrade
nikita-b Jun 7, 2022
650bef6
Merge branch 'PMM-5885-upgrade-postgres-to-14' of github.com:percona/…
nikita-b Jun 7, 2022
dcd7323
fix
nikita-b Jun 7, 2022
df80942
fix upgrade
nikita-b Jun 7, 2022
da42706
fix
nikita-b Jun 7, 2022
f411364
fix
nikita-b Jun 7, 2022
eba1cf0
remove useless steps
nikita-b Jun 7, 2022
2bae6d2
fix supervisor issues
nikita-b Jun 7, 2022
4b8a1fd
fix
nikita-b Jun 8, 2022
fbfe714
add pmm-managed user
nikita-b Jun 10, 2022
3e1bab3
fix
nikita-b Jun 10, 2022
a3263dd
Merge branch 'main' into PMM-5885-upgrade-postgres-to-14
nikita-b Jul 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions ansible/playbook/tasks/roles/initialization/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,12 @@
path: /srv/backup
state: directory

- name: Wait until postgres socket is present before continuing
wait_for:
path: /var/run/postgresql/.s.PGSQL.5432

- name: Get postgres encoding
postgresql_query:
db: pmm-managed
query: SHOW SERVER_ENCODING;
register: postgres_encoding
become: yes
become_user: postgres
become_method: su

- debug:
var: postgres_encoding.query_result

- name: Change encoding of pmm-managed database
- name: Check if Postgres 11 exist
Comment thread
nikita-b marked this conversation as resolved.
Outdated
stat:
path: /srv/postgres
register: is_postgres_11

- name: Upgrade Postgres database
include_role:
name: postgres-ascii-to-utf8
when: "'SQL_ASCII' == postgres_encoding.query_result[0].server_encoding"

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.

I removed this role because we use new instance and this instance has UTF8 by default

name: postgres
when: is_postgres_11.stat.exists

This file was deleted.

145 changes: 145 additions & 0 deletions ansible/playbook/tasks/roles/postgres/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
---
# Install Postgres
- name: Create Postgres data dir
file:
path: "/srv/postgres14"
state: directory
owner: postgres
group: postgres

- name: Add PostgreSQL YUM repository
Comment thread
nikita-b marked this conversation as resolved.
Outdated
yum_repository:
name: percona-ppg-14
description: PostgreSQL YUM repository - x86_64
baseurl: http://repo.percona.com/ppg-14/yum/release/7/RPMS/x86_64
gpgcheck: yes
enabled: yes
gpgkey: file:///etc/pki/rpm-gpg/PERCONA-PACKAGING-KEY

- name: Add PostgreSQL YUM repository
Comment thread
nikita-b marked this conversation as resolved.
Outdated
yum_repository:
name: percona-ppg-11
description: PostgreSQL YUM repository - x86_64
baseurl: http://repo.percona.com/ppg-11/yum/release/7/RPMS/x86_64
gpgcheck: yes
enabled: yes
gpgkey: file:///etc/pki/rpm-gpg/PERCONA-PACKAGING-KEY

# we need old postgres binary for upgrade process
- name: Install Postgres
yum:
name:
- percona-postgresql14-server
- percona-postgresql14-contrib
- percona-postgresql14
- percona-postgresql11-server
- percona-postgresql11-contrib
- percona-postgresql11
state: installed
when: not ansible_check_mode

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.

We need old postgres for migration



- name: Create Postgres log file
file:
path: /srv/logs/postgresql14.log
state: touch
force: yes
group: postgres
owner: postgres
mode: 0644

- name: Add the user 'postgres' to group 'pmm'
user:
name: postgres
groups: pmm
append: yes

- name: Check if Postgres 11 exist
Comment thread
nikita-b marked this conversation as resolved.
Outdated
stat:
path: /srv/postgres
register: is_postgres_11

- name: Upgrade postgres from 11 to 14
block:
- name: Create Postgres data cluster
Comment thread
nikita-b marked this conversation as resolved.
Outdated
command: /usr/pgsql-14/bin/initdb -D /srv/postgres14
become: yes
become_user: postgres
become_method: su

- name: Stop pmm-managed and postgres before changing encoding
supervisorctl:
name: "{{ item }}"
state: stopped
loop:
- pmm-managed
- postgresql

- name: Run Postgres database without supervisor
command: /usr/pgsql-11/bin/pg_ctl start -D /srv/postgres
become: yes
become_user: postgres
become_method: su

- name: Dump pmm-managed database
postgresql_db:
name: pmm-managed
state: dump
target: /tmp/pmm-managed-upgrade.sql

- name: Stop Postgres database without supervisor
command: /usr/pgsql-11/bin/pg_ctl stop -D /srv/postgres
become: yes
become_user: postgres
become_method: su

- name: Start Postgres 14 database without supervisor
command: /usr/pgsql-14/bin/pg_ctl stop -D /srv/postgres14
become: yes
become_user: postgres
become_method: su

- name: Create pmm-managed database
postgresql_db:
name: pmm-managed
state: present

- name: Restore pmm-managed database
postgresql_db:
name: pmm-managed
state: restore
target: /tmp/pmm-managed-upgrade.sql

- name: Stop Postgres 14 database without supervisor
command: /usr/pgsql-14/bin/pg_ctl stop -D /srv/postgres14
become: yes
become_user: postgres
become_method: su

- name: Remove old postgres packages
yum:
name:
- percona-postgresql11-server
- percona-postgresql11-contrib
- percona-postgresql11
- percona-postgresql11-libs
state: absent

- name: Delete old repo file
file:
state: absent
path: "/etc/yum.repos.d/percona-ppg-11.repo"

- name: Rename old Postgres directory
copy:
remote_src: true
src: /srv/postgres
dest: /srv/postgres11
when: is_postgres_11.stat.exists

- name: Disable logging_collector
lineinfile:
path: /srv/postgres14/postgresql.conf
regexp: '^logging_collector'
line: 'logging_collector = off'
when: not ansible_check_mode
4 changes: 4 additions & 0 deletions ansible/playbook/tasks/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
include_role:
name: grafana

- name: Install postgres
include_role:
name: postgres

# Start the services
- name: Supervisord start | Start supervisord service for AMI/OVF
when: not is_docker
Expand Down