Opened 4 years ago

Last modified 4 years ago

#32292 closed New feature

Allow postgresql database connections to use postgres services — at Initial Version

Reported by: levihb Owned by: nobody
Component: Database layer (models, ORM) Version: 4.0
Severity: Release blocker Keywords: database postgresql postgres service pg_service config
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top