暂无图片
postgresql数据库hint功能扩展包pg_hint_plan安装步骤
最近更新:2022-03-11 14:21:05

在pg数据库中不像oracle和mysql可以直接使用hint来固定SQL的执行计划。如果想要使用pg数据库中的hint功能来实现固定SQL的执行计划 需要安装PG数据库的hint功能扩展包,下载地址: https://zh.osdn.net/projects/pghintplan/releases/ 或者 https://github.com/ossc-db/pg_hint_plan/releases

1 插件安装

从上面的下载地址下载对应自己数据库版本的pg_hint_plan扩展包

上传到pg数据库所在的服务器上然后解压 我安装的数据库版本是12的所以我下载的是pg_hint_plan-REL12_1_3_5.tar.gz这个压缩包 解压

[root@postgres pgsql]#tar -xzvf pg_hint_plan-REL12_1_3_5.tar.gz
[root@postgres pgsql]#cd pg_hint_plan-REL12_1_3_5
[root@postgres pgsql]#make 
[root@postgres pgsql]#make install

安装完之后需要检查几个文件查看是否存在

[root@postgres pgsql]# ls -l /usr/local/pgsql/lib |grep -i hint

-rwxr-xr-x 1 postgres postgres  85409 4月  30 00:24 pg_hint_plan.so


[root@postgres pgsql]# ls -l /usr/local/pgsql/share/extension |grep -i hint

-rw-r--r-- 1 postgres postgres 545 4月  30 01:16 pg_hint_plan--1.3.5.sql
-rw-r--r-- 1 postgres postgres 104 4月  30 01:15 pg_hint_plan.control

2 加载插件

2.1 当前会话加载

LOAD 'pg_hint_plan';

注意这样加载只在当前回话生效。

如果出现以下错误: ERROR: relation "hint_plan.hints" does not exist

在template1数据库下执行以下SQL

......