-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to gets all active connections to the database.
This adds the ability to get all active connections to the database. Co-authored-by: Matt Hall <matt.hall@binarynoggin.com>
- Loading branch information
Showing
4 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
defmodule EctoPSQLExtras.Connections do | ||
@behaviour EctoPSQLExtras | ||
|
||
def info do | ||
%{ | ||
title: "Returns the list of all active database connections", | ||
columns: [ | ||
%{name: :username, type: :string}, | ||
%{name: :client_address, type: :string}, | ||
%{name: :application_name, type: :string} | ||
] | ||
} | ||
end | ||
|
||
def query(_args \\ []) do | ||
""" | ||
/* ECTO_PSQL_EXTRAS: Returns the list of all active database connections */ | ||
SELECT usename as username, client_addr::text as client_address, application_name FROM pg_stat_activity | ||
WHERE datname = current_database(); | ||
""" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters