#32292: Allow postgresql database connections to use postgres services
-------------------------------------+-------------------------------------
               Reporter:  levihb     |          Owner:  nobody
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Database   |        Version:  3.1
  layer (models, ORM)                |       Keywords:  database postgresql
               Severity:  Normal     |  postgres service pg_service config
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Postgres offers a way to make database connections through the use of
 services, which are basically equivalent to MySQL's options files.

 Server, database, username, etc information is stored by default in
 `~/.pg_service.confg` and takes a very similar format to MySQL cnf files:

 ```
 [my_alias]
 host=10.0.19.10
 user=postgres
 dbname=postgres
 port=5432
 ```

 And password can be stored in `~/.pgpass` under a different format.

 I think being able to just add them to the DATABASES config would be
 useful, similar to how you can add MySQL cnf files. psycopg2 supports it
 just fine through the service argument/string `connect(service='my_alias')
 connect('service=my_alias')`.

 At the moment it can be added like this:

 ```
 DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.postgresql',
         'NAME': 'postgres',
         'OPTIONS': {'service': 'my_alias'}
     }
 }
 ```

 Which works, however it involves repeating the database name. I don't
 think the database name should be repeated twice because it couples the
 config and the service file together, and makes it harder to just move it
 between different environments. I think ideally you would just specify the
 service, either like this:

 ```
 DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.postgresql',
         'OPTIONS': {'service': 'my_alias'}
     }
 }
 ```

 Or maybe a better way would be?:

 ```
 DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.postgresql',
         'SERVICE': 'my_alias
     }
 }
 ```

 It seems like something that would be super easy to add. I don't mind
 creating a pull request for it, but would like  to know why it hasn't been
 added, and how it would be recommended to add it.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32292>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.57a2c80a6b025a3e44bdb54e3871ad24%40djangoproject.com.

Reply via email to