version: '2' | |
services: | |
db: | |
image: postgres:9.5 | |
ports: | |
- "5432:5432" | |
volumes: | |
- /var/lib/postgresql/data | |
- ./contrib/postgres:/docker-entrypoint-initdb.d | |
environment: | |
POSTGRES_USER: myproject |
#!/bin/sh | |
# Place this file at contrib/postgres/pg_stat_statements.sh inside your project folder | |
perl -pi -e "s/#shared_preload_libraries = ''/shared_preload_libraries = 'pg_stat_statements'/g" /var/lib/postgresql/data/postgresql.conf | |
echo "Enabled pg_stat_statements" |
I'm still getting ERROR: pg_stat_statements must be loaded via shared_preload_libraries
. Tried some different solution, but still couldn't find one, which solves this error
Found another way (it worked for me):
version: '2'
services:
db:
image: postgres
ports:
- "5432:5432"
volumes:
- /var/lib/postgresql/data
command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c max_connections=200
environment:
POSTGRES_USER: myproject
docker cp postgres:/var/lib/postgresql/data/postgresql.conf postgresql.conf
vi postgresql.conf
docker cp postgresql.conf postgres:/var/lib/postgresql/data/postgresql.conf
docker restart postgres
This helped. Great article.
Finally, login to the container with postgres user and enable the extension with command:
CREATE EXTENSION pg_stat_statements;
Check if good:
SELECT *
FROM pg_available_extensions
WHERE
name = 'pg_stat_statements' and
installed_version is not null;
Found another way (it worked for me):
version: '2' services: db: image: postgres ports: - "5432:5432" volumes: - /var/lib/postgresql/data command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c max_connections=200 environment: POSTGRES_USER: myproject
This worked for me.
Found another way (it worked for me):
version: '2' services: db: image: postgres ports: - "5432:5432" volumes: - /var/lib/postgresql/data command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c max_connections=200 environment: POSTGRES_USER: myproject
thank you, worked fine here
Found another way (it worked for me):
version: '2' services: db: image: postgres ports: - "5432:5432" volumes: - /var/lib/postgresql/data command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c max_connections=200 environment: POSTGRES_USER: myproject
Works for me, too! tks⛄︎
Notes
If you are on alpine and dont have perl then use:
sed -i "s/#shared_preload_libraries = ''/shared_preload_libraries = 'pg_stat_statements'/g" /var/lib/postgresql/data/postgresql.conf