#32292: Allow postgresql database connections to use postgres services
-------------------------------------+-------------------------------------
Reporter: levihb | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: database postgresql | Triage Stage:
postgres service pg_service | Unreviewed
config |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by levihb:
Old description:
> 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.
New description:
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:
{{{#!python
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:
{{{#!python
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'OPTIONS': {'service': 'my_alias'}
}
}
}}}
Or maybe a better way would be?:
{{{#!python
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#comment:1>
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/064.d541f84acc4e777849878c320bbe2f34%40djangoproject.com.