2

I'm setting application_name in my connection string like so:

DB = Sequel.connect(:adapter=>'postgres', :host=> 'localhost',
:database=>'blah', :user=>'gator',
:application_name => 'blahwebapp')

However, when I view the pg_stat_activity or any other metric to filter down by application_name I'm not seeing it assigned properly.

My Pg gem is "pg (0.17.0)" and I believe that since 0.16 it's been able to handle the application name. sequel_pg is (1.6.8) and Sequel is (4.2.0).

An application name is set, but it is path/webserver related rather than what is set in the config:

/Users/gator/.rvm/gems/rub...47@blahwebapp/bin/shotgun

Even when I use a URL-type connection string it still doesn't register the application_name:

DB = Sequel.connect('postgres://gator@localhost/blah?application_name=blahwebapp')

That is the same URL I use in psql to connect and it shows up fine.

In the documentation for Sequel I don't see much about application_name as an option which has me worried:

Any thoughts/ideas on how to get it to respect the application_name?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Gator
  • 720
  • 5
  • 10
  • 1
    I'd recommend taking this to the Sequel-Talk mail list. It's pretty esoteric for Stack Overflow. Jeremy Evans does periodically answer questions here, but he monitors the mail list. – the Tin Man Sep 28 '13 at 15:05
  • 1
    Also, read through the Sequel adapter docs for PostgrSQL: http://sequel.rubyforge.org/rdoc-adapters/index.html. Sequel is pure-Ruby so you should be able to easily read the source if necessary. You can glean some useful insight into what of the drivers features might be missing and patch or override to add what you want. I did that when I was working with a big database and needed schema dumps of tables but couldn't get the info I wanted. – the Tin Man Sep 28 '13 at 17:31

1 Answers1

3

Sequel's PostgreSQL adapter doesn't pass the URL directly to PostgreSQL. It can't really do so and keep backwards compatibility.

It looks like you can just set the application_name at runtime. The best way to do this with Sequel is via after_connect:

DB = Sequel.connect('postgres://gator@localhost/blah', :after_connect=>proc{|c| c.execute("SET application_name TO 'blahwebapp'")})

It is possible to integrate this feature into Sequel so that using it inside the 'postgres://' URL would work correctly. I'm open to that if other people think it would be useful.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Jeremy Evans
  • 11,959
  • 27
  • 26
  • This is what I was looking for! DB = Sequel.connect(:adapter=>'postgres', :host=> 'localhost', :database=>'blah', :user=>'gator', :max_connections => 10, :after_connect=>(proc do |conn| conn.execute("SET application_name TO 'blahwebapp'") end)) – Gator Sep 30 '13 at 15:17