The below instructions are only to be used for starting up the Postgres manually for local testing outside of the usual Instant OpenHIE start instructions.
Proceed with care. This very manual deployment can get complicated. For the regular start up, please see the README.md.
Ensure that docker is installed. For details on how to install docker click here. For installing docker click here.
For our compose scripts to work, one needs to be able to run docker commands without the sudo preface. You can configure your system to run without needing the sudo preface by running the following command
./configure-docker.shFrom the instant root directory, run the following command to start up the fhir data store.
./database-postgres/swarm.sh initTo take down the service run:
./database-postgres/swarm.sh destroyTo shut down the services run:
./database-postgres/swarm.sh downTo start the services when they have been stopped run:
./database-postgres/swarm.sh upTo run in dev mode in which the ports are exposed pass the flag --dev as done below
./database-postgres/swarm.sh init --devThid service is accessible on port 5432 when deployed in dev mode.
This section assumes postgres backups are made using
pg_basebackup
To enable backups, ensure that you have created the Hapi FHIR bind mount directory (eg./backup)
NB!!! DO NOT UNTAR OR EDIT THE FILE PERMISSIONS OF THE POSTGRES BACKUP FILE
Preliminary steps:
- Do a
destroyofdatabase-postgresusing the CLI binary (./instant-linux for linux) - Make sure the Postgres volumes on nodes other than the swarm leader have been removed as well! You will need to ssh into each server and manually remove them.
- Do an
initofdatabase-postgresusing the CLI binary
After running the premilinary steps, run the following commands on the node hosting the Postgres leader:
NOTE: The value of the
REPMGR_PRIMARY_HOSTvariable in your .env file indicates the Postgres leader
- Retrieve the Postgres leader's container-ID using
docker ps -a, hereafter calledpostgres_leader_container_id - Do
docker exec -t <postgres_leader_container_id> pg_ctl stop -D /bitnami/postgresql/data - Wait for the Postgres leader container to die and start up again... monitor this using
docker ps -a - Do
docker rm <postgres_leader_container_id> - Retrieve the new Postgres leader's container-ID using
docker ps -a, be weary to not use the oldpostgres_leader_container_id - Retrieve the Postgres backup file's name as an absolute path (/backups/postgresql_xxxxxxxxxx), hereafter called
backup_file - Run the following commands in the order listed :
# Stop the server running in the container docker exec -t <postgres_leader_container_id> pg_ctl stop -D /bitnami/postgresql/data # Clear the contents of /bitnami/postgresql/data docker exec -t --user root <postgres_leader_container_id> sh -c 'cd /bitnami/postgresql/data && rm -rf $(ls)' # Copy over the base.tar file sudo docker cp <backup_file>/base.tar <postgres_leader_container_id>:/bitnami/postgresql # Extract the base.tar file docker exec -t --user root <postgres_leader_container_id> sh -c 'tar -xf /bitnami/postgresql/base.tar --directory=/bitnami/postgresql/data' # Copy over the pg_wal.tar file sudo docker cp <backup_file>/pg_wal.tar <postgres_leader_container_id>:/bitnami/postgresql # Extract pg_wal.tar docker exec -t --user root <postgres_leader_container_id> sh -c 'tar -xf /bitnami/postgresql/pg_wal.tar --directory=/bitnami/postgresql/data/pg_wal' # Copy conf dir over docker exec -t --user root <postgres_leader_container_id> sh -c 'cp -r /bitnami/postgresql/conf/. /bitnami/postgresql/data' # Set pg_wal.tar permissions docker exec -t --user root <postgres_leader_container_id> sh -c 'cd /bitnami/postgresql/data/pg_wal && chown -v 1001 $(ls)' # Start the server docker exec -t <postgres_leader_container_id> pg_ctl start -D /bitnami/postgresql/data
- Do a
downofdatabase-postgresusing the CLI binary - Wait for the
downoperation to complete - Do an
initofdatabase-postgresusing the CLI binary
Postgres should now be recovered
Note: after performing the data recovery, it is possible to get an error from services using postgres (eg 500 internal server error for Hapi-fhir) while the data is still being replicated across the cluster. Wait a minute and try again.