Skip to main content
Last updated: 2 Mar 2021

Fix Mapit database not available

Each Mapit machine has its own PostgreSQL database which powers the Mapit application. When the machine is first created by AWS, the latest data is supposed to be imported into the database.

This feature is currently not working which means that new Mapit machines are not added to the load balancer until the data has been imported manually. There will also be numerous errors in Icinga related to 5xx errors and events in Sentry:

OperationalError: could not connect to server: Connection refused
        Is the server running on host "" and accepting
        TCP/IP connections on port 5432?

RE are aware that the automatic import process doesn’t work.

Manual process

SSH onto the machine which is experiencing the problem and run the following comments:

  1. Stop any running PostgreSQL instance
   $ ps aux | grep postgresql
   $ sudo kill -9 <pid>
  1. Recreate the PostgreSQL cluster
   $ sudo pg_dropcluster --stop 9.6 main; sudo pg_createcluster 9.6 main
  1. Run Puppet
   $ govuk_puppet --test
  1. Check that PostgreSQL is up and running correctly
   $ sudo service postgresql status
  1. Make the import script available
   $ wget
   $ chmod +x
  1. Run the import script
   $ sudo ./

The import script will take about 10 minutes to run. Sometimes your SSH connection might time out while the script runs, it’s worth checking on the terminal every few minutes to check that hasn’t happened. Once Mapit is healthy, the AWS load balancer will automatically detect this and add the machine into the rotation.