I'm running a powershell script on windows that connects to a postgres database.
Under normal conditions everything works fine, but I'm trying to make the system more robust, and make everything re-start automatically after a power failure or re-boot.
The problem is that although both the script and the database successfully start on boot-up, the script does so much more quickly - in fact it re-starts before the database becomes available.
The script connects with a connection-string that includes this....
Timeout=60;CommandTimeout=8
My understand (perhaps flawed?) is that Timeout=60 refers to the connection timeout, and should mean "attempt to connect to the database for up to 60 seconds and if no connection is made quit with an error message". However, in practice the connection attempt fails immediately with the error
the database system is starting
Why is it failing immediately and not waiting for 60 seconds? Is there any way of testing if the database has re-started before attempting to connect? Or do I just need to keep attempting to connect until it's successful?