diff options
Diffstat (limited to 'service.c')
| -rw-r--r-- | service.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/service.c b/service.c new file mode 100644 index 0000000..edc6fd0 --- /dev/null +++ b/service.c @@ -0,0 +1,22 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <libpq-fe.h> + +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); +} + |
