PGXN使用求助:json_fdw检查安装失败及连接参数配置问题
问题2:
sudo pgxn install json_fdw 编译失败(缺少nodes/relation.h) 报错详情:
INFO: best version: json_fdw 1.0.0 INFO: saving /tmp/tmpinndxvp9/json_fdw-1.0.0.zip INFO: unpacking: /tmp/tmpinndxvp9/json_fdw-1.0.0.zip INFO: building extension gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC -pie -fno-omit-frame-pointer -fPIC -I. -I./ -I/usr/include/postgresql/12/server -I/usr/include/postgresql/internal -I/usr/include/x86_64-linux-gnu -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/mit-krb5 -c -o json_fdw.o json_fdw.c In file included from json_fdw.c:15:0: json_fdw.h:22:28: fatal error: nodes/relation.h: No such file or directory compilation terminated. <builtin>: recipe for target 'json_fdw.o' failed make: *** [json_fdw.o] Error 1 ERROR: command returned 2: make PG_CONFIG=/usr/bin/pg_config all
问题原因:
从报错路径/usr/include/postgresql/12/server能看出来,pgxn调用的是PostgreSQL 12的头文件,但你实际运行的是10.12版本的PostgreSQL服务器,且大概率缺少PostgreSQL 10对应的开发包(包含编译扩展所需的头文件)。另外psql版本(12.2)和服务器版本不一致,也导致pg_config指向了错误的版本。
解决方法:
步骤1:确认pg_config的版本
先检查当前pg_config指向的版本:
pg_config --version
如果显示12.2,说明它指向的是PostgreSQL 12的工具,你需要切换到PostgreSQL 10的pg_config,一般路径是/usr/lib/postgresql/10/bin/pg_config。
步骤2:安装PostgreSQL 10的开发包
Ubuntu上必须安装对应版本的开发包才能获取编译扩展的头文件:
sudo apt-get update sudo apt-get install postgresql-server-dev-10
步骤3:指定正确的pg_config重新安装
用--pg-config参数指定PostgreSQL 10的工具路径:
sudo pgxn install json_fdw --pg-config=/usr/lib/postgresql/10/bin/pg_config
如果还是有问题,可以尝试手动编译:
- 用
pgxn download json_fdw下载源码包(已经下载过可跳过) - 进入解压后的目录,执行:
make PG_CONFIG=/usr/lib/postgresql/10/bin/pg_config sudo make PG_CONFIG=/usr/lib/postgresql/10/bin/pg_config install
内容的提问来源于stack exchange,提问作者Peter Krauss
相关产品推荐
相关产品推荐

