#include #include #include #include int main() { PGconn *conn; for (int i = 0; i < 100; i++) { printf("trying to connect...\n"); conn = PQconnectdb("host=localhost dbname=postgres user=postgres password="); if (PQstatus(conn) == CONNECTION_OK) { printf("connected :)\n"); break; } else { fprintf(stderr, "connection failed: %s", PQerrorMessage(conn)); sleep(2); } } PQfinish(conn); }