make fails because pgxs.mk is missing when building a PostgreSQL extension
Makefile:10: /usr/pgsql-14/lib/pgxs/src/makefiles/pgxs.mk: No such file or directoryShort answer
The extension's Makefile asks pg_config where the PGXS makefile is, then includes it. The error means that path does not exist: the PostgreSQL development files are not installed for that version, or pg_config belongs to a different installation than the one you meant. Print pg_config --pgxs and check the file.
Fix it fast
1Find out which cause you have
Print which pg_config make uses, what it reports, and whether the makefile it names exists.
which pg_config pg_config --version ls -l "$(pg_config --pgxs)"2Match what you see, then jump to its fix
What does the error look like?
Makefile:10: /usr/pgsql-14/lib/pgxs/src/makefiles/pgxs.mk: No such file or directorymake: *** No rule to make target '/usr/pgsql-14/lib/pgxs/src/makefiles/pgxs.mk'. Stop.
Cause 1 of 2
The PostgreSQL development package is not installed
1Check
pg_config reports where the extension makefiles are meant to be. If the build files were never installed, the path points at nothing. The PGDG packages ship the headers and libraries for C development in a separate postgresql-devel package.
rpm -qa | grep -i postgresql2Fix
Install the devel package for the same major version as the server, from the same repository, and run make again.
sudo dnf install postgresql14-devel
make3Verify
The makefile now exists, and the build runs.
ls -l "$(pg_config --pgxs)"
makeConfirmed by postgresql.org
Cause 2 of 2
make picks up a pg_config from another installation
1Check
By default PGXS builds for the first pg_config found in PATH. The extension will be built, and installed, for that installation.
pg_config --version --bindir2Fix
Name the pg_config of the target installation on the make command line, or put its bin folder first in PATH.
make PG_CONFIG=/usr/pgsql-14/bin/pg_config
sudo make install PG_CONFIG=/usr/pgsql-14/bin/pg_config3Verify
pg_config --pgxs for that installation points at an existing file.
ls -l "$(/usr/pgsql-14/bin/pg_config --pgxs)"Confirmed by postgresql.org
How do I stop it coming back?
- Install the devel package at the same time as the server package, always for the same major version.
- Pass PG_CONFIG explicitly in build scripts when more than one PostgreSQL version is installed.
- Print pg_config --version at the start of a build script so the log shows what it built against.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Databases
C compiler cannot find postgres.h when building a PostgreSQL extension
fatal error: 'postgres.h' file not found
postgres.h lives in the server header directory, which is not on the compiler's default include path.
2 causes, each with a fixDatabases
DBeaver cannot run pg_restore: the utility is not found in the client home
Utility 'pg_restore' not found in client home '/usr/lib' (/usr/lib)
DBeaver runs pg_restore from a local PostgreSQL client folder; it does not bundle one.
3 causes, each with a fixDatabases
Django cannot connect to PostgreSQL: connection refused on port 5432, locally or in Docker
Is the server running on that host and accepting TCP/IP connections?
Connection refused means nothing accepted the connection at the host and port Django used.
4 causes, each with a fixDatabases
manage.py test stops with 'permission denied to create database' on PostgreSQL
django.db.utils.ProgrammingError: permission denied to create database
Django creates a separate database called test_ plus your database name, using the DATABASES USER.
2 causes, each with a fixDatabases
An EC2 instance cannot reach its RDS database
Could not open connection to the host, on port <port>: Connect failed
RDS denies all access until a security group allows it.
3 causes, each with a fixDatabases
IntelliJ IDEA Test Connection fails for a PostgreSQL data source
Connection to localhost:5432 refused.
When Test Connection fails, work from the bottom up.
4 causes, each with a fix