Upgrade PostgreSQL from 10 to 12

This commit is contained in:
Christian M. Adams
2020-12-15 15:03:18 -05:00
parent 1dec79b62d
commit 36466b9694
11 changed files with 30 additions and 31 deletions

View File

@@ -158,7 +158,7 @@ $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
44251b476f98 gcr.io/ansible-tower-engineering/awx_devel:devel "/entrypoint.sh /bin…" 27 seconds ago Up 23 seconds 0.0.0.0:6899->6899/tcp, 0.0.0.0:7899-7999->7899-7999/tcp, 0.0.0.0:8013->8013/tcp, 0.0.0.0:8043->8043/tcp, 0.0.0.0:8080->8080/tcp, 22/tcp, 0.0.0.0:8888->8888/tcp tools_awx_run_9e820694d57e 44251b476f98 gcr.io/ansible-tower-engineering/awx_devel:devel "/entrypoint.sh /bin…" 27 seconds ago Up 23 seconds 0.0.0.0:6899->6899/tcp, 0.0.0.0:7899-7999->7899-7999/tcp, 0.0.0.0:8013->8013/tcp, 0.0.0.0:8043->8043/tcp, 0.0.0.0:8080->8080/tcp, 22/tcp, 0.0.0.0:8888->8888/tcp tools_awx_run_9e820694d57e
40de380e3c2e redis:latest "docker-entrypoint.s…" 28 seconds ago Up 26 seconds 40de380e3c2e redis:latest "docker-entrypoint.s…" 28 seconds ago Up 26 seconds
b66a506d3007 postgres:10 "docker-entrypoint.s…" 28 seconds ago Up 26 seconds 0.0.0.0:5432->5432/tcp tools_postgres_1 b66a506d3007 postgres:12 "docker-entrypoint.s…" 28 seconds ago Up 26 seconds 0.0.0.0:5432->5432/tcp tools_postgres_1
``` ```
**NOTE** **NOTE**

View File

@@ -619,7 +619,7 @@ clean-elk:
docker rm tools_kibana_1 docker rm tools_kibana_1
psql-container: psql-container:
docker run -it --net tools_default --rm postgres:10 sh -c 'exec psql -h "postgres" -p "5432" -U postgres' docker run -it --net tools_default --rm postgres:12 sh -c 'exec psql -h "postgres" -p "5432" -U postgres'
VERSION: VERSION:
@echo "awx: $(VERSION)" @echo "awx: $(VERSION)"

View File

@@ -21,9 +21,10 @@ ENV LC_ALL en_US.UTF-8
USER root USER root
# Install build dependencies # Install build dependencies
RUN dnf -y module enable 'postgresql:12'
RUN dnf -y update && \ RUN dnf -y update && \
dnf -y install epel-release 'dnf-command(config-manager)' && \ dnf -y install epel-release 'dnf-command(config-manager)' && \
dnf module -y enable 'postgresql:10' && \ dnf module -y enable 'postgresql:12' && \
dnf config-manager --set-enabled powertools && \ dnf config-manager --set-enabled powertools && \
dnf -y install ansible \ dnf -y install ansible \
gcc \ gcc \
@@ -38,7 +39,7 @@ RUN dnf -y update && \
nss \ nss \
openldap-devel \ openldap-devel \
patch \ patch \
@postgresql:10 \ @postgresql:12 \
postgresql-devel \ postgresql-devel \
python3-devel \ python3-devel \
python3-pip \ python3-pip \
@@ -94,9 +95,10 @@ ENV LC_ALL en_US.UTF-8
USER root USER root
# Install runtime requirements # Install runtime requirements
RUN dnf -y module enable 'postgresql:12'
RUN dnf -y update && \ RUN dnf -y update && \
dnf -y install epel-release 'dnf-command(config-manager)' && \ dnf -y install epel-release 'dnf-command(config-manager)' && \
dnf module -y enable 'postgresql:10' && \ dnf module -y enable 'postgresql:12' && \
dnf config-manager --set-enabled powertools && \ dnf config-manager --set-enabled powertools && \
dnf -y install acl \ dnf -y install acl \
ansible \ ansible \
@@ -107,7 +109,7 @@ RUN dnf -y update && \
krb5-workstation \ krb5-workstation \
libcgroup-tools \ libcgroup-tools \
nginx \ nginx \
@postgresql:10 \ @postgresql:12 \
python3-devel \ python3-devel \
python3-libselinux \ python3-libselinux \
python3-pip \ python3-pip \

View File

@@ -76,7 +76,7 @@
-e POSTGRESQL_USER={{ pg_username }} \ -e POSTGRESQL_USER={{ pg_username }} \
-e POSTGRESQL_PASSWORD={{ pg_password | quote }} \ -e POSTGRESQL_PASSWORD={{ pg_password | quote }} \
-e POSTGRESQL_DATABASE={{ pg_database | quote }} \ -e POSTGRESQL_DATABASE={{ pg_database | quote }} \
-e POSTGRESQL_VERSION=10 \ -e POSTGRESQL_VERSION=12 \
-n {{ kubernetes_namespace }} -n {{ kubernetes_namespace }}
register: openshift_pg_activate register: openshift_pg_activate
no_log: true no_log: true
@@ -133,9 +133,9 @@
seconds: "{{ postgress_activate_wait }}" seconds: "{{ postgress_activate_wait }}"
when: openshift_pg_activate.changed or kubernetes_pg_activate.changed when: openshift_pg_activate.changed or kubernetes_pg_activate.changed
- name: Check postgres version and upgrade Postgres if necessary - name: Check postgres version and upgrade Postgres if necessary (Openshift)
block: block:
- name: Check if Postgres 9.6 is being used - name: Check if Postgres 10 is being used
shell: | shell: |
POD=$({{ kubectl_or_oc }} -n {{ kubernetes_namespace }} \ POD=$({{ kubectl_or_oc }} -n {{ kubernetes_namespace }} \
get pods -l=name=postgresql --field-selector status.phase=Running -o jsonpath="{.items[0].metadata.name}") get pods -l=name=postgresql --field-selector status.phase=Running -o jsonpath="{.items[0].metadata.name}")
@@ -145,7 +145,7 @@
block: block:
- name: Set new pg image - name: Set new pg image
shell: | shell: |
IMAGE=registry.redhat.io/rhel-8/postgresql-10 IMAGE=registry.redhat.io/rhel-8/postgresql-12
{{ kubectl_or_oc }} -n {{ kubernetes_namespace }} set image dc/postgresql postgresql=$IMAGE {{ kubectl_or_oc }} -n {{ kubernetes_namespace }} set image dc/postgresql postgresql=$IMAGE
- name: Wait for change to take affect - name: Wait for change to take affect
@@ -162,7 +162,7 @@
- name: Set env var for new pg version - name: Set env var for new pg version
shell: | shell: |
{{ kubectl_or_oc }} -n {{ kubernetes_namespace }} set env dc/postgresql POSTGRESQL_VERSION=10 {{ kubectl_or_oc }} -n {{ kubernetes_namespace }} set env dc/postgresql POSTGRESQL_VERSION=12
- name: Wait for Postgres to redeploy - name: Wait for Postgres to redeploy
pause: pause:
@@ -185,9 +185,11 @@
- name: Wait for Postgres to redeploy - name: Wait for Postgres to redeploy
pause: pause:
seconds: "{{ postgress_activate_wait }}" seconds: "{{ postgress_activate_wait }}"
when: "pg_version is success and '9.6' in pg_version.stdout" when: "pg_version is success and '10' in pg_version.stdout"
when: when:
- pg_hostname is not defined or pg_hostname == '' - pg_hostname is not defined or pg_hostname == ''
- postgres_svc_details is defined and postgres_svc_details.rc != 0
- openshift_host is defined
- name: Set image names if using custom registry - name: Set image names if using custom registry
block: block:

View File

@@ -99,7 +99,7 @@ objects:
name: ${DATABASE_SERVICE_NAME} name: ${DATABASE_SERVICE_NAME}
- name: POSTGRESQL_MAX_CONNECTIONS - name: POSTGRESQL_MAX_CONNECTIONS
value: ${POSTGRESQL_MAX_CONNECTIONS} value: ${POSTGRESQL_MAX_CONNECTIONS}
image: registry.redhat.io/rhel8/postgresql-10 image: registry.redhat.io/rhel8/postgresql-12
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
livenessProbe: livenessProbe:
exec: exec:

View File

@@ -36,11 +36,14 @@ master:
{% endif %} {% endif %}
image: image:
{% if pg_image_registry is defined %} {% if pg_image_registry is defined %}
# The default bitnami image from the chart doesn't work on ARM
registry: {{ pg_image_registry }} registry: {{ pg_image_registry }}
{% endif %} {% endif %}
# The default bitnami image from the chart doesn't work on ARM {% if pg_image_registry is not defined %}
repository: postgres registry: docker.io/bitnami
tag: '11' {% endif %}
repository: postgresql
tag: '12.5.0'
volumePermissions: volumePermissions:
image: image:
{% if pg_image_registry is defined %} {% if pg_image_registry is defined %}

View File

@@ -4,7 +4,7 @@ dockerhub_version: "{{ lookup('file', playbook_dir + '/../VERSION') }}"
awx_image: "awx" awx_image: "awx"
redis_image: "redis" redis_image: "redis"
postgresql_version: "10" postgresql_version: "12"
postgresql_image: "postgres:{{postgresql_version}}" postgresql_image: "postgres:{{postgresql_version}}"
compose_start_containers: true compose_start_containers: true

View File

@@ -31,20 +31,20 @@
- name: Upgrade Postgres - name: Upgrade Postgres
shell: | shell: |
docker run --rm \ docker run --rm \
-v {{ postgres_data_dir }}/pgdata:/var/lib/postgresql/9.6/data \
-v {{ postgres_data_dir }}/10/data:/var/lib/postgresql/10/data \ -v {{ postgres_data_dir }}/10/data:/var/lib/postgresql/10/data \
-v {{ postgres_data_dir }}/12/data:/var/lib/postgresql/12/data \
-e PGUSER={{ pg_username }} -e POSTGRES_INITDB_ARGS="-U {{ pg_username }}" \ -e PGUSER={{ pg_username }} -e POSTGRES_INITDB_ARGS="-U {{ pg_username }}" \
tianon/postgres-upgrade:9.6-to-10 --username={{ pg_username }} tianon/postgres-upgrade:10-to-12 --username={{ pg_username }}
when: upgrade_postgres | bool when: upgrade_postgres | bool
- name: Copy old pg_hba.conf - name: Copy old pg_hba.conf
copy: copy:
src: "{{ postgres_data_dir + '/pgdata/pg_hba.conf' }}" src: "{{ postgres_data_dir + '/pgdata/pg_hba.conf' }}"
dest: "{{ postgres_data_dir + '/10/data/' }}" dest: "{{ postgres_data_dir + '/12/data/' }}"
when: upgrade_postgres | bool when: upgrade_postgres | bool
- name: Remove old data directory - name: Remove old data directory
file: file:
path: "{{ postgres_data_dir + '/pgdata' }}" path: "{{ postgres_data_dir + '/10/data' }}"
state: absent state: absent
when: compose_start_containers|bool when: compose_start_containers|bool

View File

@@ -96,5 +96,5 @@ services:
- "./redis/redis.conf:/usr/local/etc/redis/redis.conf" - "./redis/redis.conf:/usr/local/etc/redis/redis.conf"
- "./redis/redis_socket_ha_3:/var/run/redis/" - "./redis/redis_socket_ha_3:/var/run/redis/"
postgres: postgres:
image: postgres:10 image: postgres:12
container_name: tools_postgres_1 container_name: tools_postgres_1

View File

@@ -44,7 +44,7 @@ services:
# Postgres Database Container # Postgres Database Container
postgres: postgres:
image: postgres:10 image: postgres:12
container_name: tools_postgres_1 container_name: tools_postgres_1
environment: environment:
POSTGRES_HOST_AUTH_METHOD: trust POSTGRES_HOST_AUTH_METHOD: trust

View File

@@ -1,12 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Enable needed Software Collections, if installed
for scl in rh-postgresql10; do
if [ -f /etc/scl/prefixes/$scl ]; then
if [ -f `cat /etc/scl/prefixes/$scl`/$scl/enable ]; then
. `cat /etc/scl/prefixes/$scl`/$scl/enable
fi
fi
done
# Enable Tower virtualenv # Enable Tower virtualenv
for venv_path in /var/lib/awx/venv/awx; do for venv_path in /var/lib/awx/venv/awx; do