Re: PostgreSQL 9.3.5 - Enable SSL

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "shyamkant(dot)dhamke(at)wipro(dot)com *EXTERN*" <shyamkant(dot)dhamke(at)wipro(dot)com>, "nag1010(at)gmail(dot)com" <nag1010(at)gmail(dot)com>, "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: PostgreSQL 9.3.5 - Enable SSL
Date: 2016-04-04 14:02:18
Message-ID: A737B7A37273E048B164557ADEF4A58B53828A3A@ntex2010a.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

shyamkant(dot)dhamke(at)wipro(dot)com wrote:
> I need sample C program ( running on Unix ) to connect to PostgreSQL 9.3.5 (SSL Enabled) database.

#include <stdio.h>
#include <libpq-fe.h>

int main(int argc, char **argv) {
PGconn *conn;

conn = PQconnectdb("host=... port=... dbname=... user=... password=...");
if (conn == NULL) {
fprintf(stderr, "Out of memory.\n");
return 1;
}
if (PQstatus(conn) != CONNECTION_OK) {
fprintf(stderr, PQerrorMessage(conn));
PQfinish(conn);
return 1;
}

PQfinish(conn);
return 0;
}

Essentially, there's nothing special to do in the C code.

You have to have the server set up for SSL (ssl=on) and the certificate and key in place.
On the client side, you can add "sslmode=require" as connection option to make sure that
no unencrypted connection is attempted.

Yours,
Laurenz Albe

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message drum.lucas@gmail.com 2016-04-04 23:27:25 [INFO] - vm.dirty_ratio/background_ratio
Previous Message Tom Lane 2016-04-04 13:52:37 Re: pg_dump fails on temp tables