[maintenance base upload] COPY et VACUUM peuvent entrer en conflit.
This commit is contained in:
parent
7fc08aa975
commit
0706c41119
4 changed files with 39 additions and 4 deletions
31
surveillance/maintenance/check_activity.py
Executable file
31
surveillance/maintenance/check_activity.py
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash /usr/scripts/python.sh
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
import psycopg2
|
||||
import psycopg2.extras
|
||||
import time
|
||||
|
||||
PG_STAT_REQ = "SELECT * FROM pg_stat_activity;"
|
||||
|
||||
def pg_stat_ended(curseur):
|
||||
"""Fetch stat_activity from postgresql and check if
|
||||
all transactions active on first fetch is done before
|
||||
returning True.
|
||||
|
||||
"""
|
||||
curseur.execute(PG_STAT_REQ)
|
||||
data = curseur.fetchall()
|
||||
seuil = max([donnee['xact_start'] for donnee in data])
|
||||
while True and seuil:
|
||||
curseur.execute(PG_STAT_REQ)
|
||||
data = curseur.fetchall()
|
||||
front = min([donnee['xact_start'] for donnee in data])
|
||||
if front > seuil:
|
||||
break
|
||||
time.sleep(30)
|
||||
|
||||
if __name__ == "__main__":
|
||||
conn = psycopg2.connect(database='filtrage')
|
||||
conn.set_session(autocommit=True)
|
||||
curseur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
||||
pg_stat_ended(curseur)
|
|
@ -1,9 +1,6 @@
|
|||
-----------------------------------------------------------------
|
||||
-- Maintenance de la base pgsql filtrade sur odlyd, lancé par cron
|
||||
-- Maintenance de la base pgsql filtrage sur odlyd, lancé par cron
|
||||
-----------------------------------------------------------------
|
||||
|
||||
-- effacement des vieux enregistrements
|
||||
DELETE FROM upload where stamp_inserted < timestamp 'now' - interval '5 days';
|
||||
|
||||
-- suppression complète des entrées
|
||||
VACUUM (VERBOSE, ANALYZE);
|
5
surveillance/maintenance/upload_maint.sh
Executable file
5
surveillance/maintenance/upload_maint.sh
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
psql -d filtrage -f /usr/scripts/surveillance/maintenance/delete.sql;
|
||||
/usr/scripts/surveillance/maintenance/check_activity.py;
|
||||
psql -d filtrage -f /usr/scripts/surveillance/maintenance/vacuum.sql 2>&1 > /dev/null
|
2
surveillance/maintenance/vacuum.sql
Normal file
2
surveillance/maintenance/vacuum.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
-- suppression complète des entrées
|
||||
VACUUM (VERBOSE, ANALYZE);
|
Loading…
Add table
Add a link
Reference in a new issue