編譯環(huán)境為CentOS7.9 x64
安裝必要包
yum install gcc bison flex readline readline-devel openssl openssl-devel libxml2 libxml2-devel -y
添加pg用戶(hù)
adduser postgres
下載源碼
切換到 postgres 用戶(hù),執(zhí)行
wget -O postgres-REL_10_1.zip https://codeload.github.com/postgres/postgres/zip/refs/tags/REL_10_1
配置
./configure --prefix=`pwd`/release --with-openssl --without-ldap --with-libxml --enable-thread-safety --enable-debug
- –prefix=`pwd`/release: 指定安裝目錄為當(dāng)前目錄下的release。
- –enable-debug: 保留語(yǔ)法符號(hào),避免install時(shí)目標(biāo)文件被strip掉了符號(hào),調(diào)試時(shí)無(wú)法看到堆棧函數(shù)和變量名。
如果你先前已經(jīng)執(zhí)行./configure過(guò),但是你想重新來(lái)過(guò),你可以使用下面的命令恢復(fù)原狀:
make distclean
- make clean只是清除編譯產(chǎn)生的中間和目標(biāo)文件。
- make distclean可以清除configure產(chǎn)生的文件和安裝目錄,反正就是恢復(fù)到初始狀態(tài)。
如果configure過(guò)程中提示缺少包,參考:https://blog.csdn.net/qq_33714590/article/details/64437734
編譯
修改 src/Makefile.global 中的編譯選項(xiàng):O2改為O0,這樣編譯出來(lái)未優(yōu)化,方便調(diào)試代碼。
在根目錄下,執(zhí)行編譯:
make -j4
安裝
在根目錄下,執(zhí)行:
make install
會(huì)安裝到你configure配置的 –prefix 指定的目錄,我是在當(dāng)前目錄的release下:

啟動(dòng)
進(jìn)入bin目錄,初始化數(shù)據(jù)庫(kù):
$ ./initdb -D …/data -Upostgres -W
啟動(dòng):
$ ./pg_ctl start -D …/data
連接:
./psql -d postgres -Upostgres -W