0

I have a multi-stage Docker container where I build jsonlog.

# Build stage
FROM postgres:11.5 AS build-env
ADD . /jsonlog
RUN apt-get update && apt-get install -y build-essential libkrb5-dev libssl-dev libpq-dev postgresql-server-dev-all
RUN cd /jsonlog && make install
# Used find to see where the output files are being installed
# RUN find / -name "*json*"

# Final stage
FROM postgres:11.5-alpine
COPY --from=build-env /usr/lib/postgresql/11/lib/bitcode/jsonlog/jsonlog.bc /usr/lib/postgresql/11/lib/bitcode/jsonlog/jsonlog.bc
COPY --from=build-env /usr/lib/postgresql/11/lib/bitcode/jsonlog.index.bc /usr/lib/postgresql/11/lib/bitcode/jsonlog.index.bc
COPY --from=build-env /usr/lib/postgresql/11/lib/jsonlog.so /usr/lib/postgresql/11/lib/jsonlog.so

The docker build seems to be okay. However, when I do a docker run, I get this error.

LOG:  invalid value for parameter "log_destination": "jsonlog"
DETAIL:  Unrecognized key word: "jsonlog".
FATAL:  configuration file "/etc/postgresql/postgresql.conf" contains errors

The jsonlog code comes from this repo, https://github.com/michaelpq/pg_plugins/tree/master/jsonlog, which I cloned. I mount just the jsonlog directory into the build container.

The postgresql.conf is vanilla, except for these lines.

log_destination = 'jsonlog'
logging_collector = on
shared_preload_libraries = 'jsonlog'

The reason for doing a multi-stage container is to get rid of build dependencies and have a smaller container. I'd like to run postgres:11.5-alpine, but I also get errors with the postgres:11.5 image.

Update

I tried getting rid of the multi-stage and just keeping everything in 1 container like this.

FROM postgres:11.5
ADD . /jsonlog
RUN apt-get update && apt-get install -y build-essential libkrb5-dev libssl-dev libpq-dev postgresql-server-dev-all
RUN cd /jsonlog && make install

But that results in the exact Unrecognized key word: "jsonlog" error.

Also, also, I tried building in a Postgres 9.5 container and the same thing happens.

  • Well at least don't mix alpine and no-alpine images. glibc and musl don't mix well. – ptman Oct 1 at 7:53
  • Yeah, that makes sense, that's why I tried keeping everything in just the debian image, but still doesn't work. :/ – 425nesp Oct 2 at 4:02
0

It's my understanding that you simply leave log_destination as 'stderr' and the jsonlog plugin overrides the log_hook in PG and, magically, logs start coming out in JSON format.

So the only change needed, AFAIK, is:

shared_preload_libraries = 'jsonlog'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.