0 准备工作

PostgreSQL 源码的安装流程看这篇博文:
Linux环境PostgreSQL源码编译安装

在我们的虚拟机中已经安装了 PostgreSQL 的情况下,
应该有下面这两个目录:
pgsql : PostgreSQL 的应用程序
postgresql-14.4 : PostgreSQL 的源码

[root@localhost module]# ls
pgsql  postgresql-14.4

1 安装插件

进入postgresql源码目录

[root@localhost module]# cd /opt/module/postgresql-14.4/
[root@localhost postgresql-14.4]# ls
aclocal.m4  config.status  contrib    GNUmakefile     INSTALL   src
config      configure      COPYRIGHT  GNUmakefile.in  Makefile
config.log  configure.ac   doc        HISTORY         README

进入其中的contrib目录,可以看到其中有很多插件

[root@localhost postgresql-14.4]# cd contrib/
[root@localhost contrib]# ls
adminpack          dict_int         jsonb_plpython   pg_prewarm          sslinfo
amcheck            dict_xsyn        lo               pgrowlocks          start-scripts
auth_delay         earthdistance    ltree            pg_stat_statements  tablefunc
auto_explain       file_fdw         ltree_plpython   pgstattuple         tcn
bloom              fuzzystrmatch    Makefile         pg_surgery          test_decoding
bool_plperl        hstore           oid2name         pg_trgm             tsm_system_rows
btree_gin          hstore_plperl    old_snapshot     pg_visibility       tsm_system_time
btree_gist         hstore_plpython  pageinspect      postgres_fdw        unaccent
citext             intagg           passwordcheck    README              uuid-ossp
contrib-global.mk  intarray         pg_buffercache   seg                 vacuumlo
cube               isn              pgcrypto         sepgsql             xml2
dblink             jsonb_plperl     pg_freespacemap  spi

例如,我们要安装pg_prewarm插件:
① 进入pg_prewarm目录;
② make
③ make install

[root@localhost contrib]# cd pg_prewarm/
[root@localhost pg_prewarm]# make
...
[root@localhost pg_prewarm]# make install
...

2 使用插件

创建扩展:create extension 【extension name】;

create extension pg_prewarm;

删除扩展:drop extension 【extension name】;

drop extension pg_prewarm;