系统环境

标题 版本 备注
系统版本 ubuntu 22.04.3 LTS (Jammy Jellyfish) -
内核版本 5.15.0-88-generic #98-Ubuntu SMP Mon Oct 2 15:18:56 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux -
PostgreSQL v12.6 -

PostgreSQL 简介

PostgreSQL 是一款功能强大的开源对象关系数据库管理系统(ORDBMS),用于安全的存储数据,允许在处理请求时检索它们。它支持多种数据类型,包括文本、图像、声音和视频,并提供用于 C/C++、Perl、Java、Python、Ruby、Tcl 和开放数据库连接 (ODBC) 的编程接口。

PostgreSQL 的主要特点:

  • 开源: PostgreSQL 是完全开源的,这意味着它是免费的,任何人都可以查看和修改它的源代码。
  • 功能强大: PostgreSQL 支持各种高级功能,例如事务处理、完整性约束、子查询、触发器和存储过程。
  • 可扩展性: PostgreSQL 可以扩展到非常大的数据量,并支持多处理器和多核系统。
  • 可靠性: PostgreSQL 以其稳定性和可靠性著称,即使在高负载情况下也能提供可靠的服务。
  • 安全性: PostgreSQL 提供多种安全功能,例如用户身份验证、授权和加密,以保护您的数据安全。

PostgreSQL 的应用场景:

  • Web 开发: PostgreSQL 可用于为各种 Web 应用程序提供数据存储,例如电子商务、内容管理系统和社交网络。
  • 企业应用: PostgreSQL 可用于为企业应用程序提供数据存储,例如客户关系管理 (CRM)、企业资源规划 (ERP) 和供应链管理 (SCM)。
  • 数据仓库: PostgreSQL 可用于构建数据仓库,用于存储和分析大量数据。
  • 科学计算: PostgreSQL 可用于科学计算和研究,例如生物信息学、地理信息系统 (GIS) 和金融建模。

PostgreSQL 的优势:

  • 性能: PostgreSQL 的性能可与其他商业数据库相媲美,甚至在某些情况下超过它们。
  • 成本: PostgreSQL 是免费的,这意味着您可以节省数据库许可证费用。
  • 社区: PostgreSQL 拥有一个庞大而活跃的社区,可以提供支持和帮助。

PostgreSQL 的劣势:

  • 复杂性: PostgreSQL 的功能非常丰富,这可能使其对于初学者来说过于复杂。
  • 文档: PostgreSQL 的文档可能不如其他商业数据库的文档完善。

总体而言,PostgreSQL 是一款功能强大、可靠且可扩展的开源数据库管理系统,适用于各种应用场景。

以下是一些关于 PostgreSQL 的学习资源:

PostgreSQL 安装

  • 本脚本不限于仅安装 12.6 版本;
  • postgresql 版本号可以从官方给出的归档列表地址:https://www.postgresql.org/ftp/source/ 获取;
  • 该脚本可以反复执行,每执行一次就等于重新安装一次 postgresql;
  • 实现了在同一个服务器上安装不同版本的 postgresql;
  • 实现了在同一个服务器上安装同一个版本(不同端口)的多次安装;

1.在服务器的 /usr/local/sbin/ 目录下创建 PostgreSQL 安装脚本文件 pg.sh ,内容为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env bash

set -eu

COLOR_R='\e[0;31m'
COLOR_G='\e[0;32m'
COLOR_Y='\e[0;33m'
COLOR_P='\e[0m'

## 确保脚本是在 root 用户下执行:
[[ $(id -u) -ne 0 ]] && { echo -e "${COLOR_R}Must run as root.${COLOR_P}"; exit 1; }
# [[ $EUID != 0 ]] && echo -e "${COLOR_R}Error:current user is not root...${COLOR_P}" && exit 0

## 读取用户输入的 PostgreSQL 版本号
# read -p "$(echo -e "${COLOR_Y}请输入你要安装的 PG 版本号(注意:后面带一位小数,比如 16.2): ${COLOR_P}")" VERSION
read -p "$(echo -e "${COLOR_Y}Please enter the version number of PostgreSQL you want to install (Note: it should have one decimal place, for example, 16.2): ${COLOR_P}")" VERSION

## 检查输入是否为空
# if [[ -z ${VERSION} ]]; then
# echo "${COLOR_R}Invalid input, your input is empty.${COLOR_P}"
# exit 1
# fi
[[ -z ${VERSION} ]] && { echo -e "${COLOR_R}Invalid input, your input is empty.${COLOR_P}"; exit 1; }



## 检查输入的内容是否为浮点型且带一位小数
# 定义正则表达式,表示小数点后带一位小数的模式
# pattern='^[0-9]+(\.[0-9])$'

## 使用=~运算符进行正则匹配
# if [[ ${VERSION} =~ ${pattern} ]]; then
# echo "输入内容是小数点后带一位小数。"
# else
# echo "输入内容不是小数点后带一位小数。"
# exit 1
# fi
[[ "${VERSION}" =~ ^[0-9]+\.[0-9]{1,2}$ ]] || { echo -e "${COLOR_R}Invalid version${COLOR_P}"; exit 1; }
## 两位小数的:
#leazhi@leazhi-ubuntu2310:/data/gitlab/hexo$ [[ 12 =~ ^[0-9]+\.[0-9]{2}$ ]] && echo ok || echo no
#no
#leazhi@leazhi-ubuntu2310:/data/gitlab/hexo$ [[ 12.0 =~ ^[0-9]+\.[0-9]{2}$ ]] && echo ok || echo no
#no
#leazhi@leazhi-ubuntu2310:/data/gitlab/hexo$ [[ 12.01 =~ ^[0-9]+\.[0-9]{2}$ ]] && echo ok || echo no
#ok

## 一位或两位小数的;
#leazhi@leazhi-ubuntu2310:/data/gitlab/hexo$ [[ 12.01 =~ ^[0-9]+\.[0-9]{1,2}$ ]] && echo ok || echo no
#ok
#leazhi@leazhi-ubuntu2310:/data/gitlab/hexo$ [[ 12.1 =~ ^[0-9]+\.[0-9]{1,2}$ ]] && echo ok || echo no
#ok
#leazhi@leazhi-ubuntu2310:/data/gitlab/hexo$ [[ 12. =~ ^[0-9]+\.[0-9]{1,2}$ ]] && echo ok || echo no
#no
#leazhi@leazhi-ubuntu2310:/data/gitlab/hexo$ [[ 12.003 =~ ^[0-9]+\.[0-9]{1,2}$ ]] && echo ok || echo no
#no

## 定义常量
# 随机生成端口号
#let PGPORT=$RANDOM+1000
PGPORT=$(shuf -i 1024-65535 -n 1)
PGUSER=postgres
SRCDIR='/usr/local/src/'
PGHOME="/usr/local/pg_${VERSION}/${PGPORT}"
PGDATA="/data/pg_${VERSION}/${PGPORT}/pgdata"
PGPASS=$(openssl rand -base64 8)
LOGFILE="/home/${PGUSER}/pg_${VERSION}_${PGPORT}_logfile"
SERVICE_FILE="/lib/systemd/system/pg_${VERSION}_${PGPORT}.service"

# 安装依赖包
apt update && apt install -y libossp-uuid-dev libsystemd-dev libpython3.10-dev libpq-dev libossp-uuid-dev

## 定义安装 PostgreSQL 函数
install_pg(){

# 下载 PostgreSQL 源码
wget -O "${SRCDIR}"/postgresql-"${VERSION}".tar.gz https://ftp.postgresql.org/pub/source/v"${VERSION}"/postgresql-"${VERSION}".tar.gz

# 解压源码
tar -zxf "${SRCDIR}"/postgresql-"${VERSION}".tar.gz -C "${SRCDIR}/"

# 进入源码目录
cd "${SRCDIR}"/postgresql-"${VERSION}"

# 配置编译参数
./configure --prefix="${PGHOME}" --with-pgport="${PGPORT}" --with-python --with-systemd --without-readline --with-ossp-uuid --with-libxml --with-libxslt --with-openssl

## 检查 configure 返回状态值!脚本顶部加了 set -eu ,所以这里可以省略
# if [[ $(echo $?) != 0 ]]; then
# echo -e "${COLOR_R}This script encounters an error.${COLOR_P}"
# exit 2
# fi
# [[ $(echo $?) != 0 ]] && { echo -e "${COLOR_R}This script encounters an error.${COLOR_P}"; exit 2; }

# 编译安装
make -j "$(nproc)" && make install && make world -j "$(nproc)" && make install-world

# 创建数据目录
mkdir -p "${PGDATA}"

# 创建 PostgreSQL 用户
# if [[ -z "$(egrep $PGUSER /etc/passwd)" ]]; then
# useradd -s /bin/bash ${PGUSER} -m
# fi
id -u "${PGUSER}" &>/dev/null || useradd -s /bin/bash "${PGUSER}" -m

# 更改数据目录所有者
chown -R "${PGUSER}.${PGUSER}" "${PGDATA}"

# 初始化数据库
su - ${PGUSER} -c "${PGHOME}/bin/initdb -D ${PGDATA} -E UTF8 --locale=en_US.utf8 -U ${PGUSER}"

# 修改配置文件
sed -i "s@#listen_addresses = 'localhost'@listen_addresses = '*'@" ${PGDATA}/postgresql.conf
sed -i "s@#port = ${PGPORT}@port = ${PGPORT}@" ${PGDATA}/postgresql.conf

}

# 调用安装函数
install_pg

# 创建 PG 启动脚本:
cat << EOF > "${SERVICE_FILE}"
[Unit]
After=network.target

[Service]
Type=forking
User=${PGUSER}
Group=${PGUSER}
Environment=PGDATA=$PGDATA
Environment=LOGFILE=${LOGFILE}
OOMScoreAdjust=-1000
#ExecStartPre=/usr/postgres-9.6/bin/postgresql96-check-db-dir ${PGDATA}
ExecStart=${PGHOME}/bin/pg_ctl start -D ${PGDATA} -l ${LOGFILE}
ExecStop=${PGHOME}/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=${PGHOME}/bin/pg_ctl reload -D ${PGDATA} -s
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=300

[Install]
WantedBy=multi-user.target
EOF

# 重启 PostgreSQL 服务
systemctl daemon-reload
systemctl start "pg_${VERSION}_${PGPORT}.service"

# 创建数据库用户和密码
#su - ${PGUSER} -c "${PGHOME}/bin/psql -d postgres -c \"CREATE USER ${PGUSER} WITH PASSWORD '${PGPASS}';\""

# 清理安装文件
rm -rf "${SRCDIR}/postgresql-${VERSION}" "${SRCDIR}/postgresql-${VERSION}.tar.gz"

# 清屏
clear

# 打印下 postgresql 启动状态
systemctl status "pg_${VERSION}_${PGPORT}"

# 输出登录信息
echo -e "${COLOR_G}=========================================================${COLOR_P}"
echo -e "${COLOR_G}PostgreSQL ${VERSION} 安装成功!${COLOR_P}"
echo -e "${COLOR_G}=========================================================${COLOR_P}"
echo -e "${COLOR_G}数据库用户:${PGUSER}${COLOR_P}"
echo -e "${COLOR_G}数据库密码:${PGPASS}${COLOR_P}"
echo -e "${COLOR_G}数据库端口:${PGPORT}${COLOR_P}"
echo -e "${COLOR_G}数据目录:${PGDATA}${COLOR_P}"
echo -e "${COLOR_G}=========================================================${COLOR_P}"

2.执行脚本:

1
bash pg.sh    # 也可以加 -x 参数对脚本进行调试执行: bash -x pg.sh     

3.脚本执行完成后,终端返回的结果为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
● pg_12.6_39441.service
Loaded: loaded (/lib/systemd/system/pg_12.6_39441.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2024-03-12 08:56:09 CST; 167ms ago
Process: 2241101 ExecStart=/usr/local/pg_12.6/39441/bin/pg_ctl start -D /data/pg_12.6/39441/pgdata -l /home/postgre>
Main PID: 2241104 (postgres)
Tasks: 7 (limit: 4150)
Memory: 15.9M
CPU: 32ms
CGroup: /system.slice/pg_12.6_39441.service
├─2241104 /usr/local/pg_12.6/39441/bin/postgres -D /data/pg_12.6/39441/pgdata
├─2241106 "postgres: checkpointer " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
├─2241107 "postgres: background writer " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
├─2241108 "postgres: walwriter " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
├─2241109 "postgres: autovacuum launcher " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ">
├─2241110 "postgres: stats collector " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
└─2241111 "postgres: logical replication launcher " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ">

Mar 12 08:56:09 iZ5ts4ir4avgeumt2dhyhmZ systemd[1]: Starting pg_12.6_39441.service...
Mar 12 08:56:09 iZ5ts4ir4avgeumt2dhyhmZ pg_ctl[2241101]: waiting for server to start.... done
Mar 12 08:56:09 iZ5ts4ir4avgeumt2dhyhmZ pg_ctl[2241101]: server started
Mar 12 08:56:09 iZ5ts4ir4avgeumt2dhyhmZ systemd[1]: Started pg_12.6_39441.service.
=========================================================
PostgreSQL 12.6 安装成功!
=========================================================
数据库用户:postgres
数据库密码:xZaDuzqQoZE=
数据库端口:39441
数据目录:/data/pg_12.6/39441/pgdata
=========================================================

报错及解决方法

configure 错:

错误一:error: library ‘ossp-uuid’ or ‘uuid’ is required for OSSP UUID

报错信息:

1
configure: error: library 'ossp-uuid' or 'uuid' is required for OSSP UUID

解决方法:

安装 libossp-uuid-dev

1
apt install -y libossp-uuid-dev

错误二:error: library ‘xslt’ is required for XSLT support

报错信息:

1
configure: error: library 'xslt' is required for XSLT support

解决方法

安装 libxslt1-dev

1
apt install -y libxslt1-dev

错误三:error: C compiler “gcc” does not support C99

注意:
这个报错信息是在同一台服务器同时编译安装 14.7 版本时出现的。而一次只编译一个就没有问题!

报错信息:

1
2
3
4
5
6
7
8
9
checking for gcc option to accept ISO C99... sed: can't read conftest.c: No such file or directory
sed: can't read conftest.c: No such file or directory
sed: can't read conftest.c: No such file or directory
sed: can't read conftest.c: No such file or directory
sed: can't read conftest.c: No such file or directory
sed: can't read conftest.c: No such file or directory
sed: can't read conftest.c: No such file or directory
unsupported
configure: error: C compiler "gcc" does not support C99

解决方法:

等其他 postgresql 编译安装进程退出后再进行编译安装即可!

make 报错

报错一:error: unknown type name ‘PG_INT64_TYPE’

注意:
这个报错信息是在同一台服务器同时编译安装 14.7 版本时出现的。而一次只编译一个就没有问题!

报错信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2 -DFRONTEND -I. -I../../src/common -I../../src/include  -D_GNU_SOURCE -I/usr/include/libxml2  -DVAL_CC="\"gcc\"" -DVAL_CPPFLAGS="\"-D_GNU_SOURCE -I/usr/include/libxml2\"" -DVAL_CFLAGS="\"-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2\"" -DVAL_CFLAGS_SL="\"-fPIC\"" -DVAL_LDFLAGS="\"-Wl,--as-needed -Wl,-rpath,'/usr/local/pg_14.7/lib',--enable-new-dtags\"" -DVAL_LDFLAGS_EX="\"\"" -DVAL_LDFLAGS_SL="\"\"" -DVAL_LIBS="\"-lpgcommon -lpgport -lxslt -lxml2 -lssl -lcrypto -lz -lm \""  -c -o archive.o archive.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2 -DFRONTEND -I. -I../../src/common -I../../src/include -D_GNU_SOURCE -I/usr/include/libxml2 -DVAL_CC="\"gcc\"" -DVAL_CPPFLAGS="\"-D_GNU_SOURCE -I/usr/include/libxml2\"" -DVAL_CFLAGS="\"-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2\"" -DVAL_CFLAGS_SL="\"-fPIC\"" -DVAL_LDFLAGS="\"-Wl,--as-needed -Wl,-rpath,'/usr/local/pg_14.7/lib',--enable-new-dtags\"" -DVAL_LDFLAGS_EX="\"\"" -DVAL_LDFLAGS_SL="\"\"" -DVAL_LIBS="\"-lpgcommon -lpgport -lxslt -lxml2 -lssl -lcrypto -lz -lm \"" -c -o base64.o base64.c
In file included from ../../src/include/c.h:49,
from ../../src/include/postgres_fe.h:25,
from archive.c:19:
../../src/include/postgres_ext.h:47:9: error: unknown type name ‘PG_INT64_TYPE’
47 | typedef PG_INT64_TYPE pg_int64;
| ^~~~~~~~~~~~~
In file included from ../../src/include/c.h:49,
from ../../src/include/postgres_fe.h:25,
from base64.c:18:
../../src/include/postgres_ext.h:47:9: error: unknown type name ‘PG_INT64_TYPE’
47 | typedef PG_INT64_TYPE pg_int64;
| ^~~~~~~~~~~~~
In file included from ../../src/include/postgres_fe.h:25,
from archive.c:19:
../../src/include/c.h:507:2: error: #error must have a working 64-bit integer datatype
507 | #error must have a working 64-bit integer datatype
| ^~~~~
In file included from ../../src/include/postgres_fe.h:25,
from base64.c:18:
../../src/include/c.h:507:2: error: #error must have a working 64-bit integer datatype
507 | #error must have a working 64-bit integer datatype
| ^~~~~
../../src/include/c.h:1171:9: error: unknown type name ‘int64’
1171 | int64 force_align_i64;
| ^~~~~
../../src/include/c.h:1179:9: error: unknown type name ‘int64’
1179 | int64 force_align_i64;
| ^~~~~
../../src/include/c.h:1171:9: error: unknown type name ‘int64’
1171 | int64 force_align_i64;
| ^~~~~
../../src/include/c.h:1179:9: error: unknown type name ‘int64’
1179 | int64 force_align_i64;
| ^~~~~
In file included from ../../src/include/c.h:1390,
from ../../src/include/postgres_fe.h:25,
from base64.c:18:
../../src/include/port.h:203:1: warning: ‘PG_PRINTF_ATTRIBUTE’ is an unrecognized format function type [-Wformat=]
203 | extern int pg_snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3, 4);
| ^~~~~~
../../src/include/port.h:205:1: warning: ‘PG_PRINTF_ATTRIBUTE’ is an unrecognized format function type [-Wformat=]
205 | extern int pg_sprintf(char *str, const char *fmt,...) pg_attribute_printf(2, 3);
| ^~~~~~
../../src/include/port.h:207:1: warning: ‘PG_PRINTF_ATTRIBUTE’ is an unrecognized format function type [-Wformat=]
207 | extern int pg_fprintf(FILE *stream, const char *fmt,...) pg_attribute_printf(2, 3);
| ^~~~~~
../../src/include/port.h:209:1: warning: ‘PG_PRINTF_ATTRIBUTE’ is an unrecognized format function type [-Wformat=]
209 | extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
| ^~~~~~
In file included from ../../src/include/c.h:1390,
from ../../src/include/postgres_fe.h:25,
from archive.c:19:
../../src/include/port.h:203:1: warning: ‘PG_PRINTF_ATTRIBUTE’ is an unrecognized format function type [-Wformat=]
203 | extern int pg_snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3, 4);
| ^~~~~~
../../src/include/port.h:205:1: warning: ‘PG_PRINTF_ATTRIBUTE’ is an unrecognized format function type [-Wformat=]
205 | extern int pg_sprintf(char *str, const char *fmt,...) pg_attribute_printf(2, 3);
| ^~~~~~
../../src/include/port.h:207:1: warning: ‘PG_PRINTF_ATTRIBUTE’ is an unrecognized format function type [-Wformat=]
207 | extern int pg_fprintf(FILE *stream, const char *fmt,...) pg_attribute_printf(2, 3);
| ^~~~~~
../../src/include/port.h:209:1: warning: ‘PG_PRINTF_ATTRIBUTE’ is an unrecognized format function type [-Wformat=]
209 | extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
| ^~~~~~
In file included from ../../src/include/postgres_fe.h:27,
from base64.c:18:
../../src/include/common/fe_memutils.h:70:1: warning: ‘PG_PRINTF_ATTRIBUTE’ is an unrecognized format function type [-Wformat=]
70 | extern char *psprintf(const char *fmt,...) pg_attribute_printf(1, 2);
| ^~~~~~
../../src/include/common/fe_memutils.h:71:1: warning: ‘PG_PRINTF_ATTRIBUTE’ is an unrecognized format function type [-Wformat=]
71 | extern size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args) pg_attribute_printf(3, 0);
| ^~~~~~
In file included from ../../src/include/postgres_fe.h:27,
from archive.c:19:
../../src/include/common/fe_memutils.h:70:1: warning: ‘PG_PRINTF_ATTRIBUTE’ is an unrecognized format function type [-Wformat=]
70 | extern char *psprintf(const char *fmt,...) pg_attribute_printf(1, 2);
| ^~~~~~
../../src/include/common/fe_memutils.h:71:1: warning: ‘PG_PRINTF_ATTRIBUTE’ is an unrecognized format function type [-Wformat=]
71 | extern size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args) pg_attribute_printf(3, 0);
| ^~~~~~
In file included from archive.c:23:
../../src/include/lib/stringinfo.h:96:1: warning: ‘PG_PRINTF_ATTRIBUTE’ is an unrecognized format function type [-Wformat=]
96 | extern void appendStringInfo(StringInfo str, const char *fmt,...) pg_attribute_printf(2, 3);
| ^~~~~~
../../src/include/lib/stringinfo.h:107:1: warning: ‘PG_PRINTF_ATTRIBUTE’ is an unrecognized format function type [-Wformat=]
107 | extern int appendStringInfoVA(StringInfo str, const char *fmt, va_list args) pg_attribute_printf(2, 0);
| ^~~~~~
make[2]: *** [<builtin>: archive.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [<builtin>: base64.o] Error 1
make[2]: Leaving directory '/usr/local/src/postgresql-14.7/src/common'
make[1]: *** [Makefile:42: all-common-recurse] Error 2
make[1]: Leaving directory '/usr/local/src/postgresql-14.7/src'
make: *** [GNUmakefile:11: all-src-recurse] Error 2

解决方法:

等其他 postgresql 编译安装进程退出后再进行编译安装即可!