Linux CentOS 7 PostgreSQL 10 安装plpgsql_check扩展(源码编译)

前言

之前的博客记录了Linux CentOS 7 安装PostgreSQL 9.5(Linux CentOS 7 安装PostgreSQL 9.5),本博客记录一下Linux CentOS 7下 PostgreSQL 10通过源码编译的形式安装plpgsql_check扩展。

下载

打开网址:https://pgxn.org/dist/plpgsql_check,点击下载图标进行下载。

下载完成后上传至CentOS服务器的指定目录即可。

配置编译安装

1、解压缩。

[root@localhost opt]# unzip plpgsql_check-1.2.3.zip

2、权限赋postgres

[root@localhost opt]# chown -R postgres:postgres plpgsql_check-1.2.3

 3、移动到扩展目录

[root@localhost opt]# mv plpgsql_check-1.2.3 /opt/postgresql-10.0/contrib

 4、postgres用户进入目录进行编译

cd plpgsql_check-1.2.3/

make clean

make install

 

启动和创建check扩展

1、重启数据库

[postgres@localhost plpgsql_check-1.2.3]$ pg_ctl restart

2、进入psql

[postgres@localhost plpgsql_check-1.2.3]$ psql

3、创建、测试

postgres=# load 'plpgsql'; -- 1.1 and higher doesn't need it
LOAD
postgres=# CREATE EXTENSION plpgsql_check;
LOAD
postgres=# CREATE TABLE t1(a int, b int);
CREATE TABLE

postgres=#
CREATE OR REPLACE FUNCTION public.f1()
RETURNS void
LANGUAGE plpgsql
AS $function$
DECLARE r record;
BEGIN
  FOR r IN SELECT * FROM t1
  LOOP
    RAISE NOTICE '%', r.c; -- there is bug - table t1 missing "c" column
  END LOOP;
END;
$function$;

CREATE FUNCTION

postgres=# select f1(); -- execution doesn't find a bug due to empty table t1
  f1 
 ────

 (1 row)

postgres=# \x
Expanded display is on.
postgres=# select * from plpgsql_check_function_tb('f1()');
─[ RECORD 1 ]───────────────────────────
functionid │ f1
lineno     │ 6
statement  │ RAISE
sqlstate   │ 42703
message    │ record "r" has no field "c"
detail     │ [null]
hint       │ [null]
level      │ error
position   │ 0
query      │ [null]

postgres=# \sf+ f1
    CREATE OR REPLACE FUNCTION public.f1()
     RETURNS void
     LANGUAGE plpgsql
1       AS $function$
2       DECLARE r record;
3       BEGIN
4         FOR r IN SELECT * FROM t1
5         LOOP
6           RAISE NOTICE '%', r.c; -- there is bug - table t1 missing "c" column
7         END LOOP;
8       END;
9       $function$

如上,plpgsql_check扩展安装完成。

猜你喜欢

转载自blog.csdn.net/w345731923/article/details/82996178
今日推荐