Database Reference
In-Depth Information
Using PQconnectdb
The
PQconnectdb
function is the most basic function to connect to the PostgreSQL
backend. This function takes only one parameter: the
conninfo
string. The syntax for
PQconnectdb
is as follows:
PGconn *PQconnectdb (const char *conninfo);
The
conninfo
string is a space-delimited string that contains the keyword value
pairs, for example,
keyword = 'foo'
. Here is the list of all
conninfo
keywords:
•
hostaddr
: This is the IP address of the PostgreSQL server
•
host
: This is the hostname of the PostgreSQL server; it can be the name of the
path of the Unix domain socket. The default value is the
/tmp
directory
If the operating system does not support Unix domain sockets,
the default value is
localhost
.
•
port
: This is the port number of the PostgreSQL server; the default port
is
5432
•
dbname
: This is the name of the database we need to connect to; the default
value for this is the username
•
user
: This is the username to connect as; the default is the operating
system user
•
password
: This is the password used during authentication
•
connect_timeout
: The
connect_timeout
keyword shows how long the
PQconnectdb
function waits before giving up
Here are some more options that are not commonly used:
•
client_encoding
•
options
•
application_name
•
fallback_application_name
•
keepalives
•
keepalives_idle
•
keepalives_interval
•
keepalives_count
•
tty