Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Set application_name in maintenance jobs
Browse files Browse the repository at this point in the history
Let's users see what's going on through pg_stat_activity.
  • Loading branch information
cevian committed Jul 2, 2021
1 parent 0aa7f12 commit dd8b1ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/migrations/migration_files_generated.go

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions pkg/migrations/sql/idempotent/base.sql
Expand Up @@ -1631,6 +1631,7 @@ BEGIN

startT := clock_timestamp();

PERFORM set_config('application_name', format('promscale maintenance: data retention: metric %s', metric_name), false);
IF log_verbose THEN
RAISE LOG 'promscale maintenance: data retention: metric %: starting', metric_name;
END IF;
Expand Down Expand Up @@ -1668,6 +1669,7 @@ BEGIN
-- even though there are no new Ids in need of deletion,
-- we may still have old ones to delete
lastT := clock_timestamp();
PERFORM set_config('application_name', format('promscale maintenance: data retention: metric %s: delete expired series', metric_name), false);
PERFORM SCHEMA_CATALOG.delete_expired_series(metric_table, ran_at, present_epoch, last_updated);
IF log_verbose THEN
RAISE LOG 'promscale maintenance: data retention: metric %: done deleting expired series as only action in %', metric_name, clock_timestamp-lastT;
Expand All @@ -1678,6 +1680,7 @@ BEGIN

-- transaction 2
lastT := clock_timestamp();
PERFORM set_config('application_name', format('promscale maintenance: data retention: metric %s: mark unused series', metric_name), false);
PERFORM SCHEMA_CATALOG.mark_unused_series(metric_table, older_than, check_time);
IF log_verbose THEN
RAISE LOG 'promscale maintenance: data retention: metric %: done marking unused series in %', metric_name, clock_timestamp()-lastT;
Expand All @@ -1686,6 +1689,7 @@ BEGIN

-- transaction 3
lastT := clock_timestamp();
PERFORM set_config('application_name', format('promscale maintenance: data retention: metric %s: drop chunks', metric_name), false);
PERFORM SCHEMA_CATALOG.drop_metric_chunk_data(metric_name, older_than);
IF log_verbose THEN
RAISE LOG 'promscale maintenance: data retention: metric %: done dropping chunks in %', metric_name, clock_timestamp()-lastT;
Expand All @@ -1696,6 +1700,7 @@ BEGIN

-- transaction 4
lastT := clock_timestamp();
PERFORM set_config('application_name', format('promscale maintenance: data retention: metric %s: delete expired series', metric_name), false);
PERFORM SCHEMA_CATALOG.delete_expired_series(metric_table, ran_at, present_epoch, last_updated);
IF log_verbose THEN
RAISE LOG 'promscale maintenance: data retention: metric %: done deleting expired series in %', metric_name, clock_timestamp()-lastT;
Expand Down Expand Up @@ -1769,6 +1774,7 @@ BEGIN
SELECT *
FROM unnest(remaining_metrics)
LOOP
PERFORM set_config('application_name', format('promscale maintenance: data retention: metric %s: wait for lock', r.metric_name), false);
PERFORM SCHEMA_CATALOG.lock_metric_for_maintenance(r.id);
CALL SCHEMA_CATALOG.drop_metric_chunks(r.metric_name, NOW() - SCHEMA_CATALOG.get_metric_retention_period(r.metric_name), log_verbose=>log_verbose);
PERFORM SCHEMA_CATALOG.unlock_metric_for_maintenance(r.id);
Expand All @@ -1795,11 +1801,13 @@ BEGIN
IF log_verbose THEN
RAISE LOG 'promscale maintenance: data retention: starting';
END IF;
PERFORM set_config('application_name', format('promscale maintenance: data retention'), false);
CALL SCHEMA_CATALOG.execute_data_retention_policy(log_verbose=>log_verbose);
IF SCHEMA_CATALOG.get_timescale_major_version() >= 2 THEN
IF log_verbose THEN
RAISE LOG 'promscale maintenance: compression: starting';
END IF;
PERFORM set_config('application_name', format('promscale maintenance: compression'), false);
CALL SCHEMA_CATALOG.execute_compression_policy(log_verbose=>log_verbose);
END IF;
IF log_verbose THEN
Expand Down Expand Up @@ -2578,6 +2586,7 @@ BEGIN
startT := clock_timestamp();
RAISE LOG 'promscale maintenance: compression: metric %: starting, without lock wait', r.metric_name;
END IF;
PERFORM set_config('application_name', format('promscale maintenance: compression: metric %s', r.metric_name), false);
CALL SCHEMA_CATALOG.compress_metric_chunks(r.metric_name);
IF log_verbose THEN
RAISE LOG 'promscale maintenance: compression: metric %: finished in %', r.metric_name, clock_timestamp()-startT;
Expand All @@ -2595,11 +2604,13 @@ BEGIN
lockStartT := clock_timestamp();
RAISE LOG 'promscale maintenance: compression: metric %: waiting for lock', r.metric_name;
END IF;
PERFORM set_config('application_name', format('promscale maintenance: compression: metric %s: waiting on lock', r.metric_name), false);
PERFORM SCHEMA_CATALOG.lock_metric_for_maintenance(r.id);
IF log_verbose THEN
startT := clock_timestamp();
RAISE LOG 'promscale maintenance: compression: metric %: starting', r.metric_name;
END IF;
PERFORM set_config('application_name', format('promscale maintenance: compression: metric %s', r.metric_name), false);
CALL SCHEMA_CATALOG.compress_metric_chunks(r.metric_name);
IF log_verbose THEN
RAISE LOG 'promscale maintenance: compression: metric %: finished in % (lock took %; compression took %)', r.metric_name, clock_timestamp()-lockStartT, startT-lockStartT, clock_timestamp()-startT;
Expand Down

0 comments on commit dd8b1ed

Please sign in to comment.