I want to write application which uses Postgresql as DBMS. To write client application do I need libpq library and header files? If yes where I would get libpq library and header files.
8 Answers
Libpq is included in the full PostgreSQL source code. You can use just libpq without the rest of PostgreSQL, but must download the full package.
You can download it from the PostgreSQL Downloads page.
Once you extract the full package it is inside src\interfaces\libpq
.
The PostgreSQL installation guide details how to install only the client libraries in the Installation section, under Client-only installation.
Libpq documentation is also available.
In postgresql sources, src\interfaces\libpq.
And yes, it is possible to compile only the libpq.

- 27,428
- 2
- 75
- 95
-
1Would you please detail how to download, compile & install only the libpq source on a server that DOES NOT have PostgreSQL installed. Thanks – Love and peace - Joe Codeswell Apr 22 '15 at 16:23
-
I think my answer is self explanatory: download sources, extract, `configure`, cd to `src\interfaces\libpq`, `make`. Note, however, that I was doing this for a static library. Not sure if dynamic library can be build. – Andrejs Cainikovs Apr 22 '15 at 18:17
-
On this server, I ONLY want to install `libpq` NOT PostgreSQL. Won't running `configure` for the "extract" create a `Makefile` for the **ENTIRETY** of PostgreSQL? – Love and peace - Joe Codeswell Apr 22 '15 at 19:00
-
You need to run `configure` in top dir of the source tree. This will create Makefiles for all components. Then you can step into library folder and execute `make` to build *only* the library. Google, and you'll find the answer. – Andrejs Cainikovs Apr 23 '15 at 08:20
-
1Btw, some Linux distros has *libpq* as a separate package. For example, on my Ubuntu 12.04 machine I can install *libpq* via `sudo apt-get install libpq5`. This will work for all Debian based systems. – Andrejs Cainikovs Apr 23 '15 at 08:24
-
Thanks for the GREAT help, Andrejs. – Love and peace - Joe Codeswell Apr 23 '15 at 18:44
I was also facing this issue but didn't got a clear answer:
This issue clearly states that while installing diesel-cli system is not able to locate libpq.lib
First of all you should have a Postgres installed on your machine.
Also diesel require visual c++, thus download and install it if not already, the size of setup will be ~5gb.
Once above installations are done you need to setup environment variables:
In my case path of Postgres installation is C:\Program Files\PostgreSQL
thus add 2 environment variable path under User variables
add new in Path
where your libpq.lib
is located in my case it is available in both C:\Program Files\PostgreSQL\12\lib
and C:\Program Files\PostgreSQL\12\bin
Once this is added create one more environment variable PQ_LIB_DIR
and set path as shown below
Note: Once done re-trigger the installation command in a new cmd window
Source: pq-sys and github-solution

- 4,870
- 14
- 54
- 83
For Windows users, it's in (version may be different)
C:\Program Files\PostgreSQL\11\lib
There you find libpq.lib
. Provide this directory to Linker input.
Don't forget to include C:\Program Files\PostgreSQL\11\include
directory for include directories.

- 753
- 6
- 11
I fix this problem reccently. This is a solution if you don't want to install Postgres in you windows.
At first, you need download Postgres Binaries. The version I download is 13.6, but it's seems like any version is fine.
Unzip the zip file.Copy libpq.lib
from pgsql\lib
to shomewhere like C:\Program Files\Postgres\lib
.
Execute the following command in cmd window.
setx PQ_LIB_DIR "{where_you_copy_to}"
Open a new cmd windows and install diesel_cli
cargo install diesel_cli --no-default-features --features postgres

- 111
- 1
- 5
In linux vertify you get the libpq.
1st, there is an app: pg_config: https://www.postgresql.org/docs/current/app-pgconfig.html
after you found out the pg_config absolute bin path.(if you installed multi version of postgressql) Then You can get
--includedir
Print the location of C header files of the client interfaces.
--libdir
Print the location of object code libraries.
Then try to compile/build some example code: https://www.postgresql.org/docs/current/libpq-example.html Some common failure example: https://www.postgresql.org/docs/current/libpq-build.html

- 4,119
- 1
- 17
- 32
You can install Postgres locally from https://www.enterprisedb.com/downloads/postgres-postgresql-downloads but select only "Command line tools" for install.
After that, you can found libpq.dll in C:\Program Files\PostgreSQL\15\bin

- 377
- 3
- 8