PGRouting functions prefixed with "_" not found

222 views Asked by At

New to Postgres / postgis / pgrouting galaxy here. I have to create a docker instance of a Posgres server. Several postgres extensions are installed on it, providing functions available in the public schema, some of them prefixed with an underscore. Building the container runs fine, but when I try to import the existing DB Schema into it, it fails with the following error :

2020-07-31 08:15:40.623 UTC [90] ERROR:  function public._pgr_dijkstra(text, anyarray, anyarray, boolean, boolean, boolean) does not exist
2020-07-31 08:15:40.623 UTC [90] STATEMENT:  GRANT ALL ON FUNCTION public._pgr_dijkstra(edges_sql text, start_vids anyarray, end_vids anyarray, directed boolean, only_cost boolean, normal boolean, OUT seq integer, OUT path_seq integer, OUT start_vid bigint, OUT end_vid bigint, OUT node bigint, OUT edge bigint, OUT cost double precision, OUT agg_cost double precision) TO owenzek;
psql:/scripts/04_mis_db_dev_schema.sql:23572: ERROR:  function public._pgr_dijkstra(text, anyarray, anyarray, boolean, boolean, boolean) does not exist

So apparently a PG routing function isn't available.

If I check the installed extensions in the container instance with \dx, PGrouting seems to be here :

                                                                    List of installed extensions
          Name          | Version |   Schema   |                                                     Description                                                     
------------------------+---------+------------+---------------------------------------------------------------------------------------------------------------------
 address_standardizer   | 3.0.1   | public     | Used to parse an address into constituent elements. Generally used to support geocoding address normalization step.
 fuzzystrmatch          | 1.1     | public     | determine similarities and distance between strings
 ogr_fdw                | 1.0     | public     | foreign-data wrapper for GIS data access
 pgrouting              | 3.0.2   | public     | pgRouting Extension
 plpgsql                | 1.0     | pg_catalog | PL/pgSQL procedural language
 plr                    | 8.4     | public     | load R interpreter and execute R script from within a database
 pointcloud             | 1.2.1   | public     | data type for lidar point clouds
 pointcloud_postgis     | 1.2.1   | public     | integration for pointcloud LIDAR data and PostGIS geometry data
 postgis                | 3.0.1   | public     | PostGIS geometry, geography, and raster spatial types and functions
 postgis_raster         | 3.0.1   | public     | PostGIS raster types and functions
 postgis_sfcgal         | 3.0.1   | public     | PostGIS SFCGAL functions
 postgis_tiger_geocoder | 3.0.1   | tiger      | PostGIS tiger geocoder and reverse geocoder
 postgis_topology       | 3.0.1   | topology   | PostGIS topology spatial types and functions
 tablefunc              | 1.0     | public     | functions that manipulate whole tables, including crosstab

\df public._pgr_dijkstra returns the following :

\df public._pgr_dijkstra
List of functions
 Schema |     Name      | Result data type |                                                                                                                                                                    Argument data types                                                                                                                                                                     | Type 
--------+---------------+------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------
 public | _pgr_dijkstra | SETOF record     | edges_sql text, start_vids anyarray, end_vids anyarray, directed boolean DEFAULT true, only_cost boolean DEFAULT false, normal boolean DEFAULT true, n_goals bigint DEFAULT 0, OUT seq integer, OUT path_seq integer, OUT start_vid bigint, OUT end_vid bigint, OUT node bigint, OUT edge bigint, OUT cost double precision, OUT agg_cost double precision | func
(1 row)

So I'm a bit confused about what I've done wrong until now :/ Any clue what I should check ?

Below : the files used up until now

Dockerfile :

FROM postgres:11.2
ADD sql/*.sql /scripts/
LABEL maintainer="TRALALA"

ENV POSTGRES_VERSION 11
ENV POSTGIS_VERSION 3

# GIS Extensions installation
RUN apt-get update \
    && apt-get -y --no-install-recommends install \
        postgresql-common \
        postgis \
        postgresql-${POSTGRES_VERSION}-postgis-${POSTGIS_VERSION} \
        postgresql-${POSTGRES_VERSION}-postgis-${POSTGIS_VERSION}-scripts \
        postgresql-${POSTGRES_VERSION}-ogr-fdw \
        postgresql-${POSTGRES_VERSION}-cron \
        postgresql-plpython3-${POSTGRES_VERSION} \
        postgresql-${POSTGRES_VERSION}-pgrouting \
        postgresql-${POSTGRES_VERSION}-pgrouting-scripts \
        # postgresql-${POSTGRES_VERSION}-plr \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get update && apt-get autoremove -y

# Pointcloud install
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        git \
        ca-certificates \
        build-essential \
        autoconf \
        automake \
        cmake \
        zlib1g-dev \
        postgresql-server-dev-all \
        libxml2-dev \
        ## PGRouting librairies
        libblkid-dev \
        e2fslibs-dev \
        libboost-all-dev \
        libaudit-dev \
    && rm -rf /var/lib/apt/lists/* \
    ## PGRouting install
    && git clone git://github.com/pgRouting/pgrouting.git \
    && cd pgrouting \
    && git checkout v3.0.2 \
    && mkdir build \
    && cd build \
    && cmake  .. \
    && make \
    && make install \
    && cd ../.. \
    && rm -r pgrouting \
    ## Laz-Perf install (pgpointcloud)
    && git clone https://github.com/verma/laz-perf.git \
    && cd laz-perf \
    && cmake . \
    && make \
    && make install \
    && cd .. \
    && rm -r laz-perf \
    ## PGPointcloud install
    && git clone https://github.com/pgpointcloud/pointcloud \
    && cd pointcloud \
    && ./autogen.sh \
    && ./configure --with-lazperf=/usr/local --with-pgconfig=/usr/lib/postgresql/${POSTGRES_VERSION}/bin/pg_config CFLAGS="-Wall -Werror -O2 -g" \
    && make \
    && make install \
    && apt-get purge -y --auto-remove \
        git \
        ca-certificates \
        build-essential \
        autoconf \
        automake \
        cmake \
        zlib1g-dev \
        postgresql-server-dev-all \
        libxml2-dev

# Somehow plr has to be installed after Pointcloud otherwise it gets uninstalled
RUN apt-get update \
    && apt-get -y --no-install-recommends install \
        postgresql-${POSTGRES_VERSION}-plr \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get update && apt-get autoremove -y

EXPOSE 5433

ADD pointcloud/initdb-pgpointcloud.sh /docker-entrypoint-initdb.d/01_pgpointcloud.sh

initdb-pgpointcloud.sh

#!/bin/sh

##### Script based on initialization script from postgis-docker #####

set -e

# Perform all actions as $POSTGRES_USER
export PGUSER="$POSTGRES_USER"


# shellcheck disable=SC2002
"${psql[@]}" --dbname="$POSTGRES_DB" -f "/scripts/01_extensions.sql"
"${psql[@]}" --dbname="$POSTGRES_DB" -f "/scripts/02_globals.sql"
#"${psql[@]}" --dbname="$POSTGRES_DB" -f "/scripts/03_custom_functions.sql"
"${psql[@]}" --dbname="$POSTGRES_DB" -f "/scripts/04_mis_db_dev_schema.sql"

01_extensions.sql :

CREATE EXTENSION IF NOT EXISTS plpgsql CASCADE;
CREATE EXTENSION IF NOT EXISTS ogr_fdw CASCADE;
CREATE EXTENSION IF NOT EXISTS plr CASCADE;
CREATE EXTENSION IF NOT EXISTS tablefunc CASCADE;
CREATE EXTENSION IF NOT EXISTS postgis CASCADE;
CREATE EXTENSION IF NOT EXISTS postgis_raster CASCADE;
CREATE EXTENSION IF NOT EXISTS postgis_sfcgal CASCADE;
-- CREATE EXTENSION IF NOT EXISTS postgis_topology CASCADE;
-- CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder CASCADE;
CREATE EXTENSION IF NOT EXISTS address_standardizer CASCADE;
CREATE EXTENSION IF NOT EXISTS fuzzystrmatch CASCADE;
CREATE EXTENSION IF NOT EXISTS pgrouting CASCADE;
1

There are 1 answers

0
dkastl On

In general it's not a good idea to make use of pgRouting functions in your application, that are starting with _. These functions are supposed to be used internally, but they are not documented and may change in future releases without notice.