Ham Burg
Ham Burg

Reputation: 79

Can't use timescaledb functions inside docker compose

This is my docker compose:

version: "3.6"
services:
    postgres:
        image: timescale/timescaledb-ha:pg16.3-ts2.15.2-all
        restart: always
        environment:
            - DATABASE_HOST=127.0.0.1
            - POSTGRES_USER=foobar
            - POSTGRES_PASSWORD==***
            - POSTGRES_DB=example

        ports:
            - "5434:5432"
        volumes:
            - ./scripts/init.sql:/docker-entrypoint-initdb.d/init.sql

And my initial script (init.sql):

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

\connect example

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

CREATE TABLE public.measurement (
    check_time timestamptz NOT NULL,
    value int4 NULL,
);

ALTER TABLE public.measurement OWNER TO foobar;

SELECT create_hypertable('measurement', by_range('check_time'), migrate_data => TRUE);

When I try to build it, I get an error:

function by_range(unknown) does not exist

This is weird, because timescaledb is properly installed - I can also run create_hypertable function directly on the database and it is working. Why it doesn't work when launched from initial scipt?

Upvotes: 0

Views: 394

Answers (1)

jjanes
jjanes

Reputation: 44305

This line just sabotaged your ability to find anything:

SELECT pg_catalog.set_config('search_path', '', false);

Either drop that line, or schema qualify everything after it, including function calls. Why did you include that in the first place?

This is weird, because timescaledb is properly installed - I can also run create_hypertable function directly on the database and it is working. Why it doesn't work when launched from initial scipt?

I suppose because only the initial script has been sabotaged.

Upvotes: 0

Related Questions