diff --git a/roles/matrix-postgres/tasks/migrate_postgres_data_directory.yml b/roles/matrix-postgres/tasks/migrate_postgres_data_directory.yml index 5a4e0689..22d584a9 100644 --- a/roles/matrix-postgres/tasks/migrate_postgres_data_directory.yml +++ b/roles/matrix-postgres/tasks/migrate_postgres_data_directory.yml @@ -23,6 +23,15 @@ We'll stop Postgres and relocate the files there for you. when: "result_pg_old_data_dir_stat.stat.exists" +# We should stop Postgres first, before building a list of files, +# as to ignore any `postmaster.pid` files, etc. +- name: Ensure matrix-postgres is stopped + service: + name: matrix-postgres + state: stopped + daemon_reload: yes + when: "result_pg_old_data_dir_stat.stat.exists" + - name: Find files and directories in old Postgres data path find: paths: "{{ matrix_postgres_base_path }}" @@ -40,13 +49,6 @@ group: "{{ matrix_user_username }}" when: "result_pg_old_data_dir_stat.stat.exists" -- name: Ensure matrix-postgres is stopped - service: - name: matrix-postgres - state: stopped - daemon_reload: yes - when: "result_pg_old_data_dir_stat.stat.exists" - - block: - name: Relocate Postgres data files from old directory to new command: "mv {{ item.path }} {{ matrix_postgres_data_path }}/{{ item.path|basename }}"