From 5b0abe2e2762ee491aaaf309102f5695872da4de Mon Sep 17 00:00:00 2001 From: Timothy Messier Date: Mon, 23 May 2022 14:24:56 +0000 Subject: [PATCH] feat(session): Add migration to delete terminated sessions There is a new periodic job that will delete terminated sessions that are older than one hour. However, since until now terminated sessions were not deleted, the first time the job runs there could be a large number of sessions that need deleted. This could have a negative impact on a running cluster. To mitigate the operational risk, this adds a migration to perform an initial delete while the cluster is offline. --- .../postgres/31/01_delete_termianted_sessions.up.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 internal/db/schema/migrations/oss/postgres/31/01_delete_termianted_sessions.up.sql diff --git a/internal/db/schema/migrations/oss/postgres/31/01_delete_termianted_sessions.up.sql b/internal/db/schema/migrations/oss/postgres/31/01_delete_termianted_sessions.up.sql new file mode 100644 index 0000000000..9b0a49102d --- /dev/null +++ b/internal/db/schema/migrations/oss/postgres/31/01_delete_termianted_sessions.up.sql @@ -0,0 +1,12 @@ +begin; + delete from session + using session_state + where + session.public_id = session_state.session_id + and + session_state.state = 'terminated' + and + session_state.start_time < wt_sub_seconds_from_now(3600); + + analyze; +commit;