Re: PostgreSQL 9.3.5 - Enable SSL - Mailing list pgsql-admin

From Albe Laurenz
Subject Re: PostgreSQL 9.3.5 - Enable SSL
Date
Msg-id A737B7A37273E048B164557ADEF4A58B53828A3A@ntex2010a.host.magwien.gv.at
Whole thread Raw
In response to Re: PostgreSQL 9.3.5 - Enable SSL  (<shyamkant.dhamke@wipro.com>)
List pgsql-admin
shyamkant.dhamke@wipro.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

pgsql-admin by date:

Previous
From: Tom Lane
Date:
Subject: Re: pg_dump fails on temp tables
Next
From: "drum.lucas@gmail.com"
Date:
Subject: [INFO] - vm.dirty_ratio/background_ratio