在 CentOS 上安装 PostgreSQL 扩展(Extension)一般分两种情况:
# 以 PostgreSQL 15 为例
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
(CentOS 7 用 yum,CentOS 8+ 用 dnf)
PostgreSQL 扩展通常以 postgresql<版本>-<扩展名> 命名。
例如安装 pg_stat_statements:
sudo dnf install -y postgresql15-contrib
常用扩展对应的包:
postgresql15-contrib → 包含很多基础扩展(pg_stat_statements、pgcrypto 等)postgresql15-pglogicalpostgresql15-postgis3postgresql15-repack-- 登录数据库
psql -U postgres -d 数据库名
-- 创建扩展
CREATE EXTENSION pg_stat_statements;
sudo dnf install -y postgresql15-devel gcc make
以 pg_buffercache 为例(通常已在 contrib 中):
git clone https://github.com/postgres/postgres.git
cd postgres/contrib/pg_buffercache
make
sudo make install
CREATE EXTENSION pg_buffercache;
\dx
确认是否已安装。
说明扩展文件没装:
sudo dnf install postgresql15-contrib
SELECT * FROM pg_available_extensions;
pg_stat_statements(SQL 性能分析)pgcrypto(加密)postgis(地理信息)pglogical(逻辑复制)pg_repack(表重整)如果你能告诉我:
我可以给你精确到命令的安装方案。