Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8225251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:21:17+00:00 2026-06-07T15:21:17+00:00

Context I’ve just installed postgres 9.1.4 on Lion, and i would like to write

  • 0

Context

I’ve just installed postgres 9.1.4 on Lion, and i would like to write a simple client in C (libpq) to connect to PG databases.

psql -l says that there is a database named mydb owned by postgresDB.

psql mydb says : mydb=#

Here the little program that tries to connect to mydb :

// Server coordinates
const char * keywords[] = {"dbname", "user", NULL};
const char * values[] = {"mydb", "postgresDB", NULL};

// Check server state
analyse_PQpingParams (PQpingParams (keywords, values, 0));

// Connect to the database
PGconn * conn; 
conn = PQconnectdbParams (keywords, values, 0);

// Check if the connection is healthy
analyse_PQstatus (PQstatus (conn));

// Clean exit
PQfinish (conn);
exit (0);

Problem

Here what the program retuns :

analyse_PQpingParams says :
------
The server is running and appears to be accepting connections.
------

analyse_PQstatus says :
------
The state returned was NULL.
------

Why is the conn object NULL ?

What the documentation says :

Note that these functions will always return a non-null object pointer, unless perhaps there is too little memory even to allocate the PGconn object. If it was a memory problem, then psql could not have connected to my db. So, the documentation doesn’t help here. Maybe elsewhere ?

Many thanks for your answers !

Pierre.

analyse_PQstatus code :

void analyse_PQstatus (int status) 
{
  cout << "\nanalyse_PQstatus says :" << endl;
  cout << "------" << endl;
  switch (status)
    {
    case CONNECTION_STARTED:
      cout << "Waiting for connection to be made." << endl;
      break;

    case CONNECTION_MADE:
      cout << "Connection OK; waiting to send." << endl;
      break;

    case CONNECTION_AWAITING_RESPONSE:
      cout << "Waiting for a response from the server." << endl;
      break;

    case CONNECTION_AUTH_OK:
      cout << "Received authentication; waiting for backend start-up to finish." << endl;
      break;

    case CONNECTION_SSL_STARTUP:
      cout << "Negotiating SSL encryption." << endl;
      break;

    case CONNECTION_SETENV:
      cout << "Negotiating environment-driven parameter settings." << endl;
      break;
    case 0 :
      cout << "The state returned was NULL" << endl;
      break;
    default :
      cout << "could not analyse this status code : " << status << endl;
    } 
    cout << "------\n" << endl;
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:21:18+00:00Added an answer on June 7, 2026 at 3:21 pm

    Can you show the analyse_PQstatus function? Are you really finding that conn is NULL or that the result of PQstatus(conn) (which is what you are passing to the function) is 0, i.e. CONNECTION_OK?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Context I would like to integrate [MediaWiki][1] as a helping tool to my system.
Context Sometimes, I like reading code on paper rather than on screen (so I
Context I'm currently reading about Clojure's implementation of monads: org.clojure/algo.monads Intuitively, reduce looks like
Context I want to use JavaFx with clojure. I am aware of http://nailthatbug.net/2011/06/clojure-javafx-2-0-simple-app/ Question:
Context: I'm making a simple solar system simulation in c++/OpenGL. Research: I've tried searching
I would like to run a str_replace or preg_replace which looks for certain words
Context I have 2 different versions of an assembly installed in GAC, version 1.0
Context: I want to use log4j to write audit-related logs to a specific log
Context: I'm working with a relatively simple winforms application, written in VB.NET on the
context.Response.ContentType = text/plain; context.Response.Write(returnString); If returnString is NULL what will it pass, or will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.