From cd32e2c9125d84493b6fe10540ffad52f496ab77 Mon Sep 17 00:00:00 2001 From: Greg Kempe Date: Tue, 22 Aug 2023 16:35:36 +0200 Subject: [PATCH] add app name to database connection string this makes it easier to see where db conns are coming from when viewing psql connections --- peachjam/settings.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/peachjam/settings.py b/peachjam/settings.py index af4cc6720..39e09637c 100644 --- a/peachjam/settings.py +++ b/peachjam/settings.py @@ -182,6 +182,12 @@ "default": default_db_config, "gazettes_africa": gazette_db_config, } +# descriptive name for this application in psql's pg_stat_activity output, to help link connections to apps +db_app_name = "-".join( + [slugify(PEACHJAM["APP_NAME"]), os.environ.get("DYNO", "django")] +) +for cfg in DATABASES.values(): + cfg.setdefault("OPTIONS", {})["options"] = f"-c application_name={db_app_name}" # Password validation