A couple more things to keep in mind: 1) The client has to re-prepare statements on "deallocate all", "alter", "create", "drop", "alter", "set search_path" statements. The backend does not automatically keep the prepared statement workable across those calls. The offending error messages are "ERROR: cached plan must not change result type", "ERROR: prepared statement "S_2" does not exist"
2) I've an answer regarding "prepared statement lifespan" at https://stackoverflow.com/questions/32297503/whats-the-life-span-of-a-postgresql-server-side-prepared-statement/32300222#32300222 Looking forward to adding more references there. Feel free pinging me in the comments. Vladimir
