Proposal for a new key in settings.DATABASE dict

184 views
Skip to first unread message

rodolphe.q...@people-doc.com

unread,
Jun 22, 2015, 10:56:16 AM6/22/15
to django-d...@googlegroups.com
Hi,

Be aware I will never speak about Django application as often used in Django developpement, here the string **application_name** is not the name of a Django'app.
PostgreSQL permits on connection to specify a string that represent the name of application that connect, useful to identify human tools like psql or automated tools like slony, this optionnal parameter is called application_name. This is very useful to debugging purpose, postgresql prints this information in logs or internal view liek pg_stat_activity, for example

gatling=# select * from pg_stat_activity  limit 1 ;
-[ RECORD 1 ]----+------------------------------
datid            
| 318636
datname          
| lolyx
pid              
| 8436
usesysid        
| 16384
usename          
| rodo
application_name
| slon.local_listen
client_addr      
| ::1
client_hostname  
|
client_port      
| 42918
backend_start    
| 2015-06-16 20:31:50.177957+02
xact_start      
|
query_start      
| 2015-06-22 16:25:57.494463+02
state_change    
| 2015-06-22 16:25:57.494564+02
waiting          
| f
state            
| idle
backend_xid      
|
backend_xmin    
|
query            
| rollback transaction;

Ref : http://www.postgresql.org/docs/current/static/runtime-config-logging.html#GUC-APPLICATION-NAME
 http://www.postgresql.org/docs/9.4/static/libpq-connect.html#LIBPQ-CONNSTRING


The welll known python driver for postgresql psycopg2 permots to use this functionnnality by using kwargs when openning connection as :

conn
= connect(database='foo', port='5435',
               host='127.0.0.1', user='rodo',password='rodo',
               application_name
='foobar')
le code ici

Ref : http://initd.org/psycopg/docs/module.html

But, actually Django doesn't permit to use this option, before proposing a patch to implement this in future version of Django I would like to receive your comments and idea about this feature.
My first idea is to add an optionnal entry in settings.DATABASE as is :

DATABASES
 
This new key in DATABASE dict will not use by all backends, not only PostgreSQL has this functionnality, AFAIK SQL Server permits this too.

I'll read your comments with interest, this will be my first patch to Django and I'll be happy to discuss things like what is an acceptable name for this new entry ?
And of course I'll read the Contritbuting to Django before make my PR.

Is this feature is accepted, the next step will be to automatically set this settiings when using the **shell**, **dbshell** or **shell_plus** command to help identify human action on production systems !

Regards,

Andriy Sokolovskiy (coldmind)

unread,
Jun 22, 2015, 11:06:46 AM6/22/15
to django-d...@googlegroups.com
I think due to https://github.com/django/django/blob/8047e3666b0b50bb04e6f16c2a4fb21ddfd5713f/django/db/backends/postgresql_psycopg2/base.py#L162 you can set application_name as the part of OPTIONS while configuration of your database, so it will be passed to psycopg2.connect.


понедельник, 22 июня 2015 г., 17:56:16 UTC+3 пользователь rodolphe.q...@people-doc.com написал:

rodolphe.q...@people-doc.com

unread,
Jun 22, 2015, 11:41:13 AM6/22/15
to django-d...@googlegroups.com
Thanks Andriy, I missed that, is this new in 1.8 ?

Andriy Sokolovskiy (coldmind)

unread,
Jun 22, 2015, 11:49:52 AM6/22/15
to django-d...@googlegroups.com
Nope, OPTIONS is not new configuration tool
You can find more info https://docs.djangoproject.com/en/1.8/ref/settings/#std:setting-OPTIONS
If you will have usage problems, please create new message in django-users IRC or mailing list, this mailing list is for
development django itself.

понедельник, 22 июня 2015 г., 18:41:13 UTC+3 пользователь rodolphe.q...@people-doc.com написал:
Reply all
Reply to author
Forward
0 new messages