Skip site navigation (1) Skip section navigation (2)

connecting with libpq interface

From: Vincent Predoehl <vpredoehl(at)phoenixwebgroup(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: connecting with libpq interface
Date: 2008-07-11 16:53:00
Message-ID: 8EAB9EDC-BC0E-4C5F-BE0F-20F6DBAE1660@phoenixwebgroup.com (view raw or flat)
Thread:
Lists: pgsql-interfaces
I installed postgresql in two places - MacOS X and Ubuntu Linux  
7.10.  Connections with libpq works fine on OS X, but not on Ubuntu  
and I can't figure out why.  Here's the code:  On MacOS X, the  
Connected!! message is displayed, on Ubuntu 7.10 I get Connect error.

#include </usr/local/pgsql/include/libpq-fe.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    PGconn *cn;

    cn = PQconnectdb("dbname=bdp");
    if(PQstatus(cn) != CONNECTION_OK)
       printf("Connect error\n");
    else
       printf("Connected!!\n");
}

I am using libpqxx, which is built on libpq and it gives me this  
detailed message, so I ran the above test program to determine if it  
was libpqxx or libpq.  Apparently, libpq is not connecting for some  
reason:

terminate called after throwing an instance of 'pqxx::broken_connection'
   what():  could not connect to server: No such file or directory
         Is the server running locally and accepting
         connections on Unix domain socket "/var/run/ 
postgresql/.s.PGSQL.5432"?

the server is running and I can connect to it with psql -p 5432.  I  
have these environment variables set, but I don't see how they could  
be the problem.

export PGDATA=~/bdp/db
export PGDATABASE=bdp

-- 
Vincent


Responses

pgsql-interfaces by date

Next:From: Tom LaneDate: 2008-07-11 20:05:25
Subject: Re: connecting with libpq interface
Previous:From: Keary SuskaDate: 2008-07-10 22:51:45
Subject: Re: libPQ -Canceling Blocking Calls

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group