71 lines
No EOL
3 KiB
YAML
71 lines
No EOL
3 KiB
YAML
---
|
|
- name: Upgrade PostgreSQL 15 to 16 in LXC
|
|
hosts: lab02
|
|
become: true
|
|
vars:
|
|
ct_id: 300
|
|
|
|
tasks:
|
|
- name: Stop PostgreSQL 15 service
|
|
command: pct exec {{ ct_id }} -- systemctl stop postgresql@15-main
|
|
|
|
- name: Add PostgreSQL APT repository key
|
|
command: pct exec {{ ct_id }} -- bash -c "wget -q -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -"
|
|
|
|
- name: Add PostgreSQL APT repository
|
|
command: pct exec {{ ct_id }} -- bash -c "echo 'deb http://apt.postgresql.org/pub/repos/apt bookworm-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
|
|
|
|
- name: Update apt cache
|
|
command: pct exec {{ ct_id }} -- apt-get update
|
|
|
|
- name: Install PostgreSQL 16
|
|
command: pct exec {{ ct_id }} -- apt-get install -y postgresql-16 postgresql-client-16 postgresql-contrib-16
|
|
|
|
- name: Stop PostgreSQL 16 (auto-started after install)
|
|
command: pct exec {{ ct_id }} -- systemctl stop postgresql@16-main
|
|
|
|
- name: Upgrade the cluster from 15 to 16
|
|
command: pct exec {{ ct_id }} -- sudo -u postgres /usr/lib/postgresql/16/bin/pg_upgrade -b /usr/lib/postgresql/15/bin -B /usr/lib/postgresql/16/bin -d /var/lib/postgresql/15/main -D /var/lib/postgresql/16/main -o "-c config_file=/etc/postgresql/15/main/postgresql.conf" -O "-c config_file=/etc/postgresql/16/main/postgresql.conf"
|
|
|
|
- name: Copy PostgreSQL 15 configuration
|
|
command: pct exec {{ ct_id }} -- bash -c "cp /etc/postgresql/15/main/postgresql.conf /etc/postgresql/16/main/ && cp /etc/postgresql/15/main/pg_hba.conf /etc/postgresql/16/main/"
|
|
|
|
- name: Update PostgreSQL 16 port to 5432
|
|
command: pct exec {{ ct_id }} -- sed -i "s/port = 5433/port = 5432/" /etc/postgresql/16/main/postgresql.conf
|
|
|
|
- name: Start PostgreSQL 16
|
|
command: pct exec {{ ct_id }} -- systemctl start postgresql@16-main
|
|
|
|
- name: Enable PostgreSQL 16
|
|
command: pct exec {{ ct_id }} -- systemctl enable postgresql@16-main
|
|
|
|
- name: Disable PostgreSQL 15
|
|
command: pct exec {{ ct_id }} -- systemctl disable postgresql@15-main
|
|
|
|
- name: Install PostGIS for PostgreSQL 16
|
|
command: pct exec {{ ct_id }} -- apt-get install -y postgresql-16-postgis-3
|
|
|
|
- name: Enable PostGIS in APRS database
|
|
command: pct exec {{ ct_id }} -- sudo -u postgres psql -d aprs -c "CREATE EXTENSION IF NOT EXISTS postgis;"
|
|
|
|
- name: Enable PostGIS in Forgejo database (if needed)
|
|
command: pct exec {{ ct_id }} -- sudo -u postgres psql -d forgejo -c "CREATE EXTENSION IF NOT EXISTS postgis;"
|
|
ignore_errors: yes
|
|
|
|
- name: Verify PostgreSQL version
|
|
command: pct exec {{ ct_id }} -- sudo -u postgres psql -c "SELECT version();"
|
|
register: pg_version
|
|
|
|
- name: Verify PostGIS installation
|
|
command: pct exec {{ ct_id }} -- sudo -u postgres psql -d aprs -c "SELECT PostGIS_Version();"
|
|
register: postgis_version
|
|
|
|
- name: Display results
|
|
debug:
|
|
msg: |
|
|
PostgreSQL upgrade completed!
|
|
|
|
{{ pg_version.stdout }}
|
|
|
|
PostGIS Version in APRS database:
|
|
{{ postgis_version.stdout }} |