pg_config
TLDR
Show the directory where PostgreSQL binaries are installed
Show the directory for library files
Show the directory for include files (C headers)
Show the directory for shared data files
Show the directory for locale data
Display help
Display version
SYNOPSIS
pg_config [option...]
PARAMETERS
--bindir
Show the location of user executables (e.g., psql, pg_dump).
--docdir
Show the location of documentation files.
--htmldir
Show the location of HTML documentation files.
--includedir
Show the location of C header files for client applications.
--pkgincludedir
Show the location of package-specific C header files, for use by other packages.
--includedir-server
Show the location of C header files for server programming (e.g., writing extensions).
--libdir
Show the location of object code libraries.
--pkglibdir
Show the location of package-specific object code libraries, for use by other packages.
--localedir
Show the location of locale data.
--mandir
Show the location of manual pages.
--sharedir
Show the location of architecture-independent support files.
--sysconfdir
Show the location of system configuration files.
--pgxs
Show the location of the pgxs extension makefile infrastructure.
--configure
Show the options that were given to the configure script when PostgreSQL was built.
--cc
Show the C compiler used to build PostgreSQL.
--cppflags
Show the preprocessor flags used to build PostgreSQL.
--cflags
Show the C compiler flags used to build PostgreSQL.
--cflags_sl
Show the C compiler flags used to build PostgreSQL shared libraries.
--ldflags
Show the linker flags used to build PostgreSQL.
--ldflags_ex
Show the linker flags used to build PostgreSQL executables.
--ldflags_sl
Show the linker flags used to build PostgreSQL shared libraries.
--libs
Show the libraries that client applications should link against.
--version
Show the PostgreSQL version string.
--help
Show a help message and exit.
DESCRIPTION
The pg_config command-line utility provides essential information about the installed PostgreSQL version. It is an invaluable tool for developers and administrators needing to programmatically discover PostgreSQL's installation layout, compiler flags, and library paths. When invoked without any options, it outputs a comprehensive list of all available configuration parameters, including directories for executables, documentation, header files, and libraries, as well as the configure options used during its build.
Specifically, pg_config reports on paths like bindir (executables), libdir (libraries), and includedir (header files), which are crucial for compiling client applications or server extensions. It also reveals important build-time details such as the C compiler (cc), preprocessor flags (cppflags), and linker flags (ldflags). By standardizing access to this information, pg_config significantly simplifies the process of integrating third-party software with PostgreSQL, ensuring compatibility and reducing manual configuration errors across different environments.
CAVEATS
While pg_config provides details about the installed PostgreSQL version, it's crucial to ensure that the executable being run corresponds to the desired PostgreSQL installation, especially in environments with multiple PostgreSQL versions. The command reports on the configuration as determined at build time and how it was installed, not necessarily the runtime configuration of a specific database cluster. Always check your PATH or specify the full path to pg_config if you have multiple installations.
COMMON USAGE EXAMPLES
Here are a few practical examples demonstrating how to use pg_config:
1. Get the path to PostgreSQL client executables:pg_config --bindir
2. Find the compiler flags needed for client applications:pg_config --cflags
3. Display all available configuration parameters:pg_config
This command, executed without any options, provides a comprehensive overview of all reported paths, compiler flags, and build information, making it an excellent starting point for understanding your PostgreSQL installation.
HISTORY
The pg_config utility has been a fundamental component of PostgreSQL for many years, designed to provide a standardized, programmatic interface for querying PostgreSQL's build and installation parameters. Its introduction and continuous evolution reflect PostgreSQL's commitment to supporting robust third-party application development and simplifying integration across diverse operating systems and build environments. It ensures that applications can dynamically adapt to the specific PostgreSQL setup they are interacting with, rather than relying on brittle, hard-coded paths.


