There is no need to open/close connection every time you want to fetch some data or update the database. You simple need to handle database errors correctly. When connection is lost you should catch exception, analyse error and try to reconnect if connection is lost. Also all inserts/updates can be surrounded by begin/commit/rollback and if you loose connection postgress will automatically drop unfinished inserts/updates.
Just check functions: ConnectionOK, ReOpen and callback WhenReconnect