blob: edc6fd0dab5b232e03713ad1f0088ec6ab8d1897 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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);
}
|