Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker compose #91

Closed
skovzhaw opened this issue Jun 20, 2017 · 3 comments
Closed

Docker compose #91

skovzhaw opened this issue Jun 20, 2017 · 3 comments
Labels

Comments

@skovzhaw
Copy link

Hey guys,

I am trying to bring up TimescaleDB via Docker Compose (as opposed to Docker run) and it seems to me that the extension is not being loaded.

Dockerfile

FROM timescale/timescaledb

ENV PGDATA=/var/lib/postgresql/data/timescaledb
VOLUME /var/lib/postgresql
EXPOSE 5432

ADD initialize.sh /docker-entrypoint-initdb.d/init-user-db.sh

initialize.sh

#!/bin/bash

psql --username "$POSTGRES_USER" <<EOF
CREATE DATABASE my_db WITH OWNER $POSTGRES_USER;
GRANT ALL PRIVILEGES ON DATABASE my_db TO $POSTGRES_USER;

\c my_db
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;

CREATE TABLE IF NOT EXISTS  my_table (
  time      TIMESTAMP         NOT NULL,
  metric    TEXT              NOT NULL,
  usage     DOUBLE PRECISION  NOT NULL
);
SELECT create_hypertable('my_table', 'time');
CREATE INDEX IF NOT EXISTS usage_metric ON my_table (metric, time DESC);
EOF

Compose.yml

version: '3'

services:
  timescale:
    image: my_timescale
    command: postgres -c shared_preload_libraries=timescaledb
    ports:
      - 5432:5432
    environment:
      - POSTGRES_USER=my_user
      - POSTGRES_PASSWORD=my_password
    volumes:
      - ./timescale:/var/lib/postgresql

As you can see I am trying to load timescaledb extension via command: postgres -c shared_preload_libraries=timescaledb but it looks like nothing is happening. This is what I get as an output:

NOTICE:  installing required extension "postgres_fdw"
ERROR:  The timescaledb library is not preloaded
HINT:  Please preload the timescaledb library via shared_preload_libraries.

  This can be done by editing the config file at: /var/lib/postgresql/data/timescaledb/postgresql.conf
  and adding 'timescaledb' to the list in the shared_preload_libraries config.

    # Modify postgresql.conf:
      shared_preload_libraries = 'timescaledb'

  Another way to do this, if not preloading other libraries, is with the command:
  echo "shared_preload_libraries = 'timescaledb'" >> /var/lib/postgresql/data/timescaledb/postgresql.conf 

  (Will require a database restart.)

  If you REALLY know what you are doing and would like to load the library without preloading, you can disable   this check with: 
    SET timescaledb.allow_install_without_preload = 'on';

STATEMENT:  CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;

And consequently that's why create_hypertable fails.

Starting TimescaleDB via Docker run works for me without any issues. I also tried to put aftermentioned postgres -c shared_preload_libraries=timescaledb command to Dockerfile, but it did not help.

Am I missing something? How are you doing your Docker compose?

Thanks in advance.

Best wishes,
Martin

@Romathonat
Copy link

Hello,
I had the same problem and struggled with this way too long.
The probleme is that you add an init file to /docker-entrypoint-initdb.d : if you look at the Dockerfile of postgres, you will see that this docker-entrypoint launch your init files before using timescaledb as a dependency !

In order to fix that, I created another container, expecially for the init of the db, it looks like this :

FROM debian:jessie
RUN apt-get update && apt-get install -y netcat

# in order to have psql
RUN apt-get install -y postgresql-client

ADD ./init_schema.sql /
ADD ./start.sh /start.sh

CMD ["/start.sh"]

and the start.sh looks like this :

#!/bin/sh

while ! nc -z postgres 5432;do sleep 3;done

# now that the database is up, we can log into it and launch the init
PGPASSWORD=my password psql -h name_in_docker_compose -U user database< init_schema.sql

echo 'init done'

The part with the while is here to be sure the database is up before filling it with data.

version: '3'
services:
  postgres:
    build:
      context: ./postgres
    container_name: postgres

  postgres_init:
    build:
      context: ./postgres/postgres_init
    container_name: postgres_init
    depends_on:
      - postgres

I also put the command "postgres -c shared_preload_libraries=timescaledb" in the dockerfile as CMD [...] instead of the docker-compose.

This workaround works but it is not really clean, I admit, but it works until we find something better.

@RobAtticus
Copy link
Member

Hi, we just released a new version (0.0.12-beta) that also included a new build process for Docker images (using the timescale/timescaledb-docker repo). This should have streamlined the build image, so maybe give it a try and see if it works better with Docker Compose? If not we can do some more investigating.

@Romathonat
Copy link

I tested it today, it works perfectly, good job. Now you can add you init scripts to /docker-entrypoint-initdb.d in the timescaledb docker, postgres will use it correctly (without saying that it can't use plugin timescaledb or whatever)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants