Skip to content
Snippets Groups Projects
Commit 1a1a2396 authored by Alexander Hinneburg's avatar Alexander Hinneburg
Browse files

kill long queries

parent 88717975
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,10 @@ version: '3.4'
services:
db:
image: postgres:11.6-alpine
container_name: postgres
build:
context: ./src
dockerfile: Dockerfile-postgresql
container_name: edb-postgres
restart: always
environment:
- POSTGRES_PASSWORD
......@@ -16,6 +18,7 @@ services:
build:
context: ./src
dockerfile: Dockerfile
container_name: edb-adminer
restart: always
environment:
- ADMINER_PLUGINS=account-nolock-plugin
......
from postgres:11.6-alpine
RUN mkdir /home/postgres
COPY postgres-crontab /home/postgres/.
COPY kill-long-running-queries.sh /home/postgres/.
COPY start-cron.sh /start-cron.sh
RUN chown -R postgres:postgres /home/postgres && \
chmod 755 /home/postgres/kill-long-running-queries.sh && \
crontab -u postgres /home/postgres/postgres-crontab && \
chmod 755 /start-cron.sh
CMD /start-cron.sh && su -c postgres postgres
#!/bin/bash
set -e
/usr/local/bin/psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
SELECT
pg_cancel_backend(pid)
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '20 seconds'
and state='active';
EOSQL
# min hour day month weekday command
* * * * * /home/postgres/kill-long-running-queries.sh >>/dev/null
#!/bin/sh
# start cron
/usr/sbin/crond -f -l 8 &
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment