This project is archived and is in readonly mode.

#54 ✓resolved

[Feature Request] Add support for a pgpass connect parameter

Reported by fpoirotte | May 11th, 2011 @ 03:57 PM


To the best of my knowledge, there is currently no way in psycopg2 to make it use a specific pgpass file instead of the default one, when using keywords with the connect method.

What I'd like to be able to do is:
conn = psycopg2.connect(database="test", user="postgres", pgpass="/etc/testapp/.pgpass")

PostgreSQL accepts that kind of usage (see src/interfaces/libpq/fe-connect.c) since a very long time it seems and so I think it's only natural that psycopg2 accepts it too.

Also, I haven't tried it yet, but I think passing the path to the pgpass file in a conninfo string currently works (ie. psycopg2.connect("dbname=test user=postgres pgpass=/etc/testapp/.pgpass")). However, in my case this is not enough because I use some ORM wrapper which passes those information to psycopg2 as separate keyword arguments (and not as a single conninfo string).


Comments and changes to this ticket

  • Daniele Varrazzo

    Daniele Varrazzo May 13th, 2011 @ 11:27 AM

    • State changed from “new” to “invalid”

    I actually don't see the pgpass parameter listed here: If it is not documented anywhere I don't think we should add it: it may be an implementation detail. Do you have further info?

    I see at least two different way to work around the issue:

    • write your own wrapper around psycopg2.connect() taking an arbitrary list of keywords and converting them into a connection string, and tell your ORM to use it (or monkeypatch the psycopg2 module if it doesn't)
    • use the PGPASSFILE env var that I see used in src/interfaces/libpq/fe-connect.c: it seems doing what you need

    I'm not eager to add all the dozens keywords the libpq supports: passing a connection string seems a good enough solution. You may open a discussion to the mailing list if you think the feature is really useful and check what the other think.

  • Joshua D. Drake

    Joshua D. Drake October 27th, 2012 @ 03:52 AM

    This is in no way an invalid ticket. The use of PGPASS is quite documented:

    And it is the standard way to use stored password and connection string options. This is something that should definitely be added. In fact I thought it already worked (because all my other programs can use it) until I started updating PITRTools which is written in Python.

  • Joshua D. Drake

    Joshua D. Drake October 27th, 2012 @ 03:57 AM

    And now I see that I was cracked and didn't read your ticket properly. Sorry about that Daniele. I know understand what you mean there and that does make sense.

  • Daniele Varrazzo

    Daniele Varrazzo October 27th, 2012 @ 12:30 PM

    • State changed from “invalid” to “resolved”

    By the way sometimes after this ticket was closed we have added libpq arguments pass-through (see so, even if not specifically dealt with, psycopg now does what requested in this ticket (provided that the libpq can handle the 'pgpass' argument in the conninfo string, as it seems the case).

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

<b>WARNING:</b> the informations in this tracker are archived. Please submit new tickets or comments to <a href="">the new tracker</a>.
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.

Shared Ticket Bins

People watching this ticket