Skip to content

Inspect and kill database processes #243

@davenquinn

Description

@davenquinn

We should add a macrostrat db subcommand to inspect and kill long-running processes. Sometimes, it is useful to understand how our applications are interacting with the database.

As a starting point, we can wrap queries like this:

-- Describe all long-running processes
SELECT
  datname,
  pid,
  state,
  query,
  age(clock_timestamp(), query_start) AS duration
FROM
  pg_stat_activity
WHERE
  state <> 'idle'
  AND query NOT ILIKE '%pg_stat_activity%'
  AND pid <> pg_backend_pid()
ORDER BY
  duration DESC;

-- Terminate a specific query by PID
SELECT pg_terminate_backend(2121843);

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions