zoukankan      html  css  js  c++  java
  • postgresql plv8 安装

    网上可以看到pg 9.6 版本的plv8容器镜像,没有pg 高版本的支持镜像,但是在基于原有dockerfile 进行构建的时候,居然失败了,有墙的问题,有版本的问题
    所以通过虚拟机尝试下构建方式安装以及对于碰到问题的解决

    说明centos 系统不太好使,安装起来有点费事,使用的Debian

    安装pg

    pg11

    • pg repo
     
    touch /etc/apt/sources.list.d/pgdg.list
    deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main
    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
    sudo apt-get update
    • 安装
    apt-get install postgresql-11 postgresql-server-dev-11 
    • 配置pg_Config
      可选,默认会自动配置,对于多环境的可能需要,可以结合find locate 工具查找

    构建

    • 预备
     
    apt install  git pkg-config libc++-dev libc++abi-dev
    • clone 代码
    wget https://github.com/plv8/plv8/archive/v2.3.9.tar.gz
    • 构建
    tar -xvzf v2.3.9.tar.gz
    cd plv8-2.3.9
    make
    make install

    使用

    • 启动扩展
    CREATE EXTENSION plv8;
    • 简单函数
    CREATE OR REPLACE FUNCTION plv8_eval_test()
    RETURNS text AS $$
      var result = eval("1+2")
      return JSON.stringify(result);
    $$ LANGUAGE plv8 IMMUTABLE STRICT;
    • 调用
    select * from plv8_eval_test();
    • 效果

    docker 镜像

     
    FROM postgres:10
    MAINTAINER Chia-liang Kao <clkao@clkao.org>
    ENV PLV8_VERSION=v2.1.0 
        PLV8_SHASUM="207d712e919ab666936f42b29ff3eae413736b70745f5bfeb2d0910f0c017a5c v2.1.0.tar.gz"
    RUN buildDependencies="build-essential 
        ca-certificates 
        curl 
        git-core 
        python 
        postgresql-server-dev-$PG_MAJOR" 
      && apt-get update 
      && apt-get install -y --no-install-recommends ${buildDependencies} 
      && mkdir -p /tmp/build 
      && curl -o /tmp/build/${PLV8_VERSION}.tar.gz -SL "https://github.com/plv8/plv8/archive/$PLV8_VERSION.tar.gz" 
      && cd /tmp/build 
      && echo ${PLV8_SHASUM} | sha256sum -c 
      && tar -xzf /tmp/build/${PLV8_VERSION}.tar.gz -C /tmp/build/ 
      && cd /tmp/build/plv8-${PLV8_VERSION#?} 
      && sed -i 's/(depot_tools.git)/1; cd depot_tools; git checkout 46541b4996f25b706146148331b9613c8a787e7e; rm -rf .git;/' Makefile.v8 
      && make static 
      && make install 
      && strip /usr/lib/postgresql/${PG_MAJOR}/lib/plv8.so 
      && cd / 
      && apt-get clean 
      && apt-get remove -y ${buildDependencies} 
      && apt-get autoremove -y 
      && rm -rf /tmp/build /var/lib/apt/lists/*
     

    v2.3.8

    # Docker image for PostgreSQL with the plv8 extensions installed
    # Note: building plv8 from source takes a long time, and will timeout with Docker Hub's
    # automated builds. See the main Dockerfile for an image that uses pre-built binaries
    # (built using this Dockerfile.build)
    # Provided by Ionx Solutions: https://www.ionxsolutions.com
    # Begin by building plv8
    FROM postgres:11.2 AS build
    ENV PLV8_VERSION 2.3.8
    ENV PLV8_SHASUM="b3ffb95daeb21b17bc5670f372403879dfad7eee86e0152e4da763ffd16fbf07 ${PLV8_VERSION}.tar.gz"
    RUN buildDeps="curl build-essential ca-certificates git python gnupg libc++-dev libc++abi-dev pkg-config glib2.0 postgresql-server-dev-$PG_MAJOR" 
        && apt-get update 
        && apt-get install -y --no-install-recommends libc++1 ${buildDeps} 
      && echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" > /etc/apt/sources.list.d/pgdg.list 
      && curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - 
      && apt-get update 
      && apt-get install -y --no-install-recommends libc++1 postgresql-server-dev-$PG_MAJOR 
        && git config --global user.email "nobody@example.com" 
        && git config --global user.name "nobody" 
        && mkdir -p /tmp/build 
        && curl -o /tmp/build/${PLV8_VERSION}.tar.gz -SL "https://github.com/plv8/plv8/archive/v${PLV8_VERSION}.tar.gz" 
        && cd /tmp/build 
        && echo ${PLV8_SHASUM} | sha256sum -c 
        && tar -xzf /tmp/build/${PLV8_VERSION}.tar.gz -C /tmp/build/ 
        && cd /tmp/build/plv8-${PLV8_VERSION} 
        && sed -i '104i%.bc : %.cc
    	$(COMPILE.cxx.bc) $(CCFLAGS) $(CPPFLAGS) -fPIC -c -o $@ $<
    ' Makefile.shared 
        && make static 
        && make install 
        && cd / 
        && rm -rf /tmp/build 
        && apt-get remove -y --purge ${buildDeps} 
        && apt-get autoremove -y --purge 
        && rm -rf /var/lib/apt/lists/
     
     

    v2.3.9

    FROM postgres:11.2
    ENV PLV8_VERSION=v2.3.9 
    RUN buildDependencies="curl build-essential ca-certificates git python gnupg libc++-dev libc++abi-dev pkg-config glib2.0 postgresql-server-dev-$PG_MAJOR" 
      && apt-get update 
      && apt-get install -y --no-install-recommends libc++1 ${buildDependencies} 
      && mkdir -p /tmp/build 
      && curl -o /tmp/build/${PLV8_VERSION}.tar.gz -SL "https://github.com/plv8/plv8/archive/$PLV8_VERSION.tar.gz" 
      && cd /tmp/build 
      && tar -xzf /tmp/build/${PLV8_VERSION}.tar.gz -C /tmp/build/ 
      && cd /tmp/build/plv8-${PLV8_VERSION#?} 
      && make static 
      && make install 
      && cd / 
      && apt-get clean 
      && apt-get remove -y ${buildDependencies} 
      && apt-get autoremove -y 
      && rm -rf /tmp/build /var/lib/apt/lists/*

    几个问题

    • v8 代码包的问题
      主要是墙的问题,合理上网解决
    • make: * No rule to make target 'plv8.bc', needed by 'all
      参考 https://github.com/plv8/plv8/issues/304 使用高版本,比如我使用2.3.9 ,在测试2.3.8 版本的时候碰到的此问题
    • undefined symbol: getmissingattr
      这个是因为pg版本的问题,主要是在2.3.8 集成pg 11 的时候,当时使用的11.1 后边发现是11.2 才支持的

    参考资料

    https://github.com/plv8/plv8
    https://github.com/clkao/plv8x
    https://github.com/plv8/plv8/issues/304
    https://github.com/clkao/docker-postgres-plv8

  • 相关阅读:
    js -- use strict
    css布局—— 固定+自适应
    web前端安全问题(转载)
    清除float浮动
    源码核心动画01-CALayer-基本使用(了解)
    源码0308-画板
    源码0306-手势解锁
    源码0301-图片水印-裁剪-截屏-截取-擦除
    源码0309-雪花(定时器)-图形上下文状态栈-矩阵操作
    源码0308-模仿UIImageView
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/11813889.html
Copyright © 2011-2022 走看看