在 postgres-alpine 容器上安装 pl/sh

Install pl/sh on a postgres-alpine container

我在图像 postgres:9.6-alpine 的 docker 容器中有一个 postgres 服务器 运行。我想编写一个执行一些 sh ​​命令的 postgres 函数。为此,我想在下面的函数中声明语言 plsh:

CREATE or REPLACE FUNCTION func2 (var1 text) RETURNS text AS '
#!/bin/bash
 touch /home/postgres/;
' LANGUAGE plsh;
commit;

我没有安装该语言,因为它是 postgres 的外部项目。有没有办法在高山上安装它? 这是 link 到 repo

是的,这是可能的。 plsh 应该从 source.

构建 postgres 扩展

Dockerfile是:

FROM postgres:9.6-alpine
RUN apk add --no-cache git g++ make
RUN git clone https://github.com/petere/plsh && \
    cd plsh && \
    make && \
    make install

Dockerfile 适用于 PostgreSQL13

FROM postgres:13-alpine
RUN apk add --no-cache git g++ make clang llvm10
RUN git clone https://github.com/petere/plsh && \
    cd plsh &&   \
    make &&      \
    make install

构建映像docker build --tag plsh:13 .

旋转容器并测试它

CREATE EXTENSION IF NOT EXISTS plsh;

CREATE OR REPLACE FUNCTION hello (who TEXT) RETURNS text
LANGUAGE plsh
AS $$
#!/bin/sh
echo "Hello,  !"
return 0;
$$;

SELECT hello(who:='world');