Add cancel option to terminate queries
This commit is contained in:
parent
750db87046
commit
dcb07c225e
5 changed files with 22 additions and 1 deletions
|
@ -38,6 +38,7 @@ type Config struct {
|
|||
ExcludeUsers StringFlags `yaml:"exclude-users"`
|
||||
ExcludeUsersRegex string `yaml:"exclude-users-regex"`
|
||||
ExcludeUsersRegexCompiled *regexp.Regexp
|
||||
Cancel bool `yaml:"cancel"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
14
base/db.go
14
base/db.go
|
@ -84,3 +84,17 @@ func (db *Db) TerminateSessions(sessions []Session) {
|
|||
Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// CancelSessions terminates current query of a list of sessions
|
||||
func (db *Db) CancelSessions(sessions []Session) {
|
||||
var pids []int64
|
||||
for _, session := range sessions {
|
||||
pids = append(pids, session.Pid)
|
||||
}
|
||||
if len(pids) > 0 {
|
||||
query := `select pg_cancel_backend(pid) from pg_stat_activity where pid = any($1);`
|
||||
log.Debugf("query: %s\n", query)
|
||||
_, err := db.conn.Exec(query, pq.Array(pids))
|
||||
Panic(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue