# Access PostgreSQL trough sockets



## spaceportz (Feb 22, 2012)

Hi,

Is it possible to write and read records in a PostgreSQL database? Actually I would like to write a C program that would read sockets and then write to a PostgreSQL database and reverse, to read from PostgreSQL database and to send sockets to some TCP/IP address.

Thanks in advance.


----------



## Anonymous (Feb 22, 2012)

You would link your C program against the libpq C library of PostgreSQL. The documentation of which can be found in Chapter 31 of the PostgreSQL Manual.

At the end of that Chapter you will find programming examples.

If you don't assign a host name in the PQconnectdb() function, then your C program connects to the socket of the locally running postgres instance. Although, you can use the same program to connect to a PostgreSQL server on any other host, by only specifying a respective host name.

I found myself quickly comfortable with the very well documented libpq.


----------

