Skip to content

Commit 004992f

Browse files
committed
Postgres, support ApplicationName config to distinguish db connections
in the server we can use queries such as: ``` SELECT * FROM pg_stat_activity WHERE datname = 'dbname'; ```
1 parent 1558caa commit 004992f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/arjdbc/postgresql/adapter_hash_config.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ def build_connection_config(config)
1313
port = (config[:port] ||= ENV["PGPORT"] || 5432)
1414
database = config[:database] || config[:dbname] || ENV["PGDATABASE"]
1515

16-
config[:url] ||= "jdbc:postgresql://#{host}:#{port}/#{database}"
16+
app = config[:application_name] || config[:appname] || config[:application]
17+
18+
config[:url] ||= if app
19+
"jdbc:postgresql://#{host}:#{port}/#{database}?ApplicationName=#{app}"
20+
else
21+
"jdbc:postgresql://#{host}:#{port}/#{database}"
22+
end
1723

1824
config[:url] << config[:pg_params] if config[:pg_params]
1925

0 commit comments

Comments
 (0)