changeset 753:5295d495a114

PG: added ApplicationName
author Alain Mazy <am@orthanc.team>
date Wed, 15 Oct 2025 09:27:59 +0200
parents 176e5dfbad43
children 0f893b49ca18
files Framework/PostgreSQL/PostgreSQLParameters.cpp Framework/PostgreSQL/PostgreSQLParameters.h PostgreSQL/NEWS
diffstat 3 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/PostgreSQL/PostgreSQLParameters.cpp	Wed Oct 08 14:47:15 2025 +0200
+++ b/Framework/PostgreSQL/PostgreSQLParameters.cpp	Wed Oct 15 09:27:59 2025 +0200
@@ -39,6 +39,7 @@
     username_ = "";
     password_ = "";
     database_.clear();
+    schema_ = "public";
     uri_.clear();
     ssl_ = false;
     lock_ = true;
@@ -100,6 +101,7 @@
     lock_ = configuration.GetBooleanValue("Lock", true);  // Use locking by default
 
     SetSchema(configuration.GetStringValue("Schema", "public"));
+    SetApplicationName(configuration.GetStringValue("ApplicationName", ""));
 
     isVerboseEnabled_ = configuration.GetBooleanValue("EnableVerboseLogs", false);
     allowInconsistentChildCounts_ = configuration.GetBooleanValue("AllowInconsistentChildCounts", false);
@@ -210,6 +212,11 @@
     Orthanc::Toolbox::ToLowerCase(schema_, schema);
   }
 
+  void PostgreSQLParameters::SetApplicationName(const std::string& applicationName)
+  {
+    applicationName_ = applicationName;
+  }
+
   const std::string PostgreSQLParameters::GetReadWriteTransactionStatement() const
   {
     switch (isolationMode_)
@@ -258,10 +265,15 @@
         target += " password=" + password_;
       }
 
-      if (database_.size() > 0)
+      if (!database_.empty())
       {
         target += " dbname=" + database_;
       }
+
+      if (!applicationName_.empty())
+      {
+        target += " application_name=" + applicationName_;
+      }
     }
     else
     {
--- a/Framework/PostgreSQL/PostgreSQLParameters.h	Wed Oct 08 14:47:15 2025 +0200
+++ b/Framework/PostgreSQL/PostgreSQLParameters.h	Wed Oct 15 09:27:59 2025 +0200
@@ -46,6 +46,7 @@
     std::string  password_;
     std::string  database_;
     std::string  schema_;
+    std::string  applicationName_;
     std::string  uri_;
     bool         ssl_;
     bool         lock_;
@@ -112,6 +113,13 @@
       return schema_;
     }
 
+    void SetApplicationName(const std::string& applicationName);
+
+    const std::string& GetApplicationName() const
+    {
+      return applicationName_;
+    }
+
     void SetSsl(bool ssl)
     {
       ssl_ = ssl;
--- a/PostgreSQL/NEWS	Wed Oct 08 14:47:15 2025 +0200
+++ b/PostgreSQL/NEWS	Wed Oct 15 09:27:59 2025 +0200
@@ -20,6 +20,10 @@
   schema or that you install the pg_trgm extension manually in the public schema.
   The plugin now calls 'SET search_path TO $schema' when opening a new connection
   to the DB.
+* New configuration "ApplicationName" (default value is empty) that is copied in 
+  the application_name argument in the connection string.  This name is used to
+  identify the origin of queries in statistics and logs in the PostgreSQL server.
+
 
 Maintenance:
 * Now verifying the DatabasePatchLevel (revision) in another transaction than