Currently all the templates using libpq make use of prepared statements. These are created per session and only last for the duration of that session. When a database connection is lost the templates correctly detect this and re-connect. The new session however won't have the prepared statements and they must be re-created for that session.
If the statements are not rebuilt at this point Postgres will generate a logged error idenifying the missing statement.
The only way to get the template correctly operational again is to restart the template executable.
Diff: