Здесь мы рассмотрим вариант установки расширения pg_store_plans в случае отсутствия его в репозиториях операционной системы. 

На примере :

root@deb-127-2:~# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@deb-127-2:~#
CODE

Установим пакеты

apt install build-essential
apt install autoconf automake gdb git libffi-dev zlib1g-dev libssl-dev
CODE

В данном примере рассматривается сборка под уже установленный postgresql версии 16

root@deb-127-2:~# apt list --installed | grep ^postgres

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

postgresql-16/bookworm-pgdg,now 16.6-1.pgdg120+1 amd64 [installed]
postgresql-client-16/bookworm-pgdg,now 16.6-1.pgdg120+1 amd64 [installed,automatic]
postgresql-client-common/bookworm-pgdg,now 267.pgdg120+1 all [installed,automatic]
postgresql-common/bookworm-pgdg,now 267.pgdg120+1 all [installed,automatic]
root@deb-127-2:~#
CODE

нам требуется установить пакет postgresql-server-dev-16

root@deb-127-2:~# apt install postgresql-server-dev-16
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  postgresql-server-dev-16
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,173 kB of archives.
After this operation, 7,142 kB of additional disk space will be used.
Get:1 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 postgresql-server-dev-16 amd64 16.6-1.pgdg120+1 [1,173 kB]
Fetched 1,173 kB in 1s (1,671 kB/s)
Selecting previously unselected package postgresql-server-dev-16.
(Reading database ... 50931 files and directories currently installed.)
Preparing to unpack .../postgresql-server-dev-16_16.6-1.pgdg120+1_amd64.deb ...
Unpacking postgresql-server-dev-16 (16.6-1.pgdg120+1) ...
Setting up postgresql-server-dev-16 (16.6-1.pgdg120+1) ...
root@deb-127-2:~#
CODE


В зависимости от установленной версии PostgreSQL скачиваем и распаковываем версию расширения pg_store_plans


wget https://github.com/ossc-db/pg_store_plans/archive/refs/tags/1.8.tar.gz
tar xvfz 1.8.tar.gz
cd pg_store_plans-1.8/
CODE

убедится что прописан путь к pg_config

# which pg_config
/usr/bin/pg_config
CODE

в случае если не находит, необходимо прописать 

export PATH=<<POSTGRESQL_DIRECTORY>>/bin:$PATH
CODE

Выполним сборку расширения

make USE_PGXS=1
CODE

в случае успеха последними строками на консоль выведется 

/usr/bin/clang-16 -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Xclang -no-opaque-pointers -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -O2  -I. -I./ -I/usr/include/postgresql/16/server -I/usr/include/postgresql/internal  -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2  -flto=thin -emit-llvm -c -o pgsp_json_text.bc pgsp_json_text.c
/usr/bin/clang-16 -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Xclang -no-opaque-pointers -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -O2  -I. -I./ -I/usr/include/postgresql/16/server -I/usr/include/postgresql/internal  -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2  -flto=thin -emit-llvm -c -o pgsp_explain.bc pgsp_explain.c
CODE

Выполним установку расширения 

root@deb-127-2:~/pg_store_plans-1.8# make install USE_PGXS=1
/bin/mkdir -p '/usr/lib/postgresql/16/lib'
/bin/mkdir -p '/usr/share/postgresql/16/extension'
/bin/mkdir -p '/usr/share/postgresql/16/extension'
/bin/mkdir -p '/usr/lib/postgresql/16/lib'
/usr/bin/install -c -m 755  pg_store_plans.so '/usr/lib/postgresql/16/lib/pg_store_plans.so'
/usr/bin/install -c -m 644 .//pg_store_plans.control '/usr/share/postgresql/16/extension/'
/usr/bin/install -c -m 644 .//pg_store_plans--1.8.sql  '/usr/share/postgresql/16/extension/'
/usr/bin/install -c -m 755  pg_store_plans.so '/usr/lib/postgresql/16/lib/'
/bin/mkdir -p '/usr/lib/postgresql/16/lib/bitcode/pg_store_plans'
/bin/mkdir -p '/usr/lib/postgresql/16/lib/bitcode'/pg_store_plans/
/usr/bin/install -c -m 644 pg_store_plans.bc '/usr/lib/postgresql/16/lib/bitcode'/pg_store_plans/./
cd '/usr/lib/postgresql/16/lib/bitcode' && /usr/lib/llvm-16/bin/llvm-lto -thinlto -thinlto-action=thinlink -o pg_store_plans.index.bc pg_store_plans/pg_store_plans.bc
/bin/mkdir -p '/usr/lib/postgresql/16/lib/bitcode/pg_store_plans'
/bin/mkdir -p '/usr/lib/postgresql/16/lib/bitcode'/pg_store_plans/
/usr/bin/install -c -m 644 pg_store_plans.bc '/usr/lib/postgresql/16/lib/bitcode'/pg_store_plans/./
/usr/bin/install -c -m 644 pgsp_json.bc '/usr/lib/postgresql/16/lib/bitcode'/pg_store_plans/./
/usr/bin/install -c -m 644 pgsp_json_text.bc '/usr/lib/postgresql/16/lib/bitcode'/pg_store_plans/./
/usr/bin/install -c -m 644 pgsp_explain.bc '/usr/lib/postgresql/16/lib/bitcode'/pg_store_plans/./
cd '/usr/lib/postgresql/16/lib/bitcode' && /usr/lib/llvm-16/bin/llvm-lto -thinlto -thinlto-action=thinlink -o pg_store_plans.index.bc pg_store_plans/pg_store_plans.bc pg_store_plans/pgsp_json.bc pg_store_plans/pgsp_json_text.bc pg_store_plans/pgsp_explain.bc
root@deb-127-2:~/pg_store_plans-1.8#
CODE

Данное расширение нужно добавить в параметр shared_preload_libraries

shared_preload_libraries = 'pg_stat_statements, pg_store_plans'
CODE

выполнит рестарт сервера  postgresql

systemctl restart postgresql
CODE

Добавить расширение в базу данных

root@deb-127-2:~/pg_store_plans-1.8# su - postgres
postgres@deb-127-2:~$
postgres@deb-127-2:~$ psql
psql (16.6 (Debian 16.6-1.pgdg120+1))
Type "help" for help.

postgres=# create extension pg_store_plans;
LOG:  statement: create extension pg_store_plans;
CREATE EXTENSION
postgres=#
postgres=# \dx
                                            List of installed extensions
        Name        | Version |   Schema   |                              Description
--------------------+---------+------------+------------------------------------------------------------------------
 pg_stat_statements | 1.10    | public     | track planning and execution statistics of all SQL statements executed
 pg_store_plans     | 1.8     | public     | track plan statistics of all SQL statements executed
 plpgsql            | 1.0     | pg_catalog | PL/pgSQL procedural language
(3 rows)

postgres=#
postgres=#

CODE