Troubleshooting

The pem.alert Table Fails to Restore

When restoring the pem backing database from backup, you may encounter an error during the restoration of the pem.alert table. This is caused by a missing table pre-requisite for the table - the pg_restore utility may restore the pem.alert pre-requisites after it attempts to restore pem.alert.

If this happens, the output from pg_restore will include error messages that refer to the alert table:

pg_restore: [archiver (db)] could not execute query: ERROR: insert or
 update on table "alert_history" violates foreign key constraint
 "alert_history_alert_id_fkey"
DETAIL: Key (alert_id)=(3) is not present in table "alert".
Command was: ALTER TABLE ONLY alert_history
ADD CONSTRAINT alert_history_alert_id_fkey FOREIGN KEY (alert_id)
 REFERENCES alert(id) ON...
pg_restore: creating FK CONSTRAINT alert_status_alert_id_fkey
pg_restore: [archiver (db)] Error from TOC entry 3265; 2606 18355 FK
 CONSTRAINT alert_status_alert_id_fkey postgres
pg_restore: [archiver (db)] could not execute query: ERROR: insert or
 update on table "alert_status" violates foreign key constraint
 "alert_status_alert_id_fkey"
DETAIL: Key (alert_id)=(1) is not present in table "alert".
Command was: ALTER TABLE ONLY alert_status
ADD CONSTRAINT alert_status_alert_id_fkey FOREIGN KEY (alert_id)
 REFERENCES alert(id) ON U...

If you encounter this problem, restore the pem database before restoring the pem.alert table. Restoring the pem database will install the pre-requisites for pem.alert, and the restoration of the table should complete as expected.