Thread: .pgpass being ignored
I am trying to write a script that will create and populate a database. I don't want to enter a password every time so I want to use a .pgpass file. It has the correct permissions: $ ls -l $PGPASSFILE -rw------- 1 Stephen staff 43 21 Jun 14:48 /Users/Stephen/.pgpass However, when I call createdb, it fails: $ createdb -h 192.168.1.4 -U postgres --no-password JobSearch createdb: could not connect to database postgres: fe_sendauth: no password supplied This is the contents of my .pgpass file: 192.168.1.4:5432:DatabaseName:postgres:thisIsTheCorrectPassword If I omit the --no-password option it will prompt me for a password and the command will succeed. I am using 9.0.10 from MacPorts. What am I doing wrong? ...Stephen
On 21/06/2013 23:25, Stephen Rasku wrote: > I am trying to write a script that will create and populate a > database. I don't want to enter a password every time so I want to > use a .pgpass file. It has the correct permissions: > > $ ls -l $PGPASSFILE > -rw------- 1 Stephen staff 43 21 Jun 14:48 /Users/Stephen/.pgpass > > However, when I call createdb, it fails: > > $ createdb -h 192.168.1.4 -U postgres --no-password JobSearch > createdb: could not connect to database postgres: fe_sendauth: no > password supplied > > This is the contents of my .pgpass file: > > 192.168.1.4:5432:DatabaseName:postgres:thisIsTheCorrectPassword > > If I omit the --no-password option it will prompt me for a password > and the command will succeed. I am using 9.0.10 from MacPorts. > > What am I doing wrong? What's in your server's pg_hba.conf file? Ray. -- Raymond O'Donnell :: Galway :: Ireland rod@iol.ie
On 06/21/2013 03:25 PM, Stephen Rasku wrote: > I am trying to write a script that will create and populate a > database. I don't want to enter a password every time so I want to > use a .pgpass file. It has the correct permissions: > > $ ls -l $PGPASSFILE > -rw------- 1 Stephen staff 43 21 Jun 14:48 /Users/Stephen/.pgpass > > However, when I call createdb, it fails: > > $ createdb -h 192.168.1.4 -U postgres --no-password JobSearch > createdb: could not connect to database postgres: fe_sendauth: no > password supplied > > This is the contents of my .pgpass file: > > 192.168.1.4:5432:DatabaseName:postgres:thisIsTheCorrectPassword > > If I omit the --no-password option it will prompt me for a password > and the command will succeed. I am using 9.0.10 from MacPorts. > > What am I doing wrong? First are you running the script from the location with .pgpass? Second you are doing a createdb, not sure how Postgres handles using .pgpass with database that does not exist yet? Might want to try a '*' in the database name field or since it looks like it is trying to connect to the postgres database, use that as the database name. > > ...Stephen > > -- Adrian Klaver adrian.klaver@gmail.com
On Fri, Jun 21, 2013 at 3:33 PM, Raymond O'Donnell <rod@iol.ie> wrote: > > What's in your server's pg_hba.conf file? # TYPE DATABASE USER CIDR-ADDRESS METHOD #@remove-line-for-nolocal@# "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 md5 host all all 192.168.1.3/32 md5
On Fri, Jun 21, 2013 at 3:41 PM, Adrian Klaver <adrian.klaver@gmail.com> wrote: > > First are you running the script from the location with .pgpass? I wasn't but I copied the .pgpass into the local directory and I get the same results. The correct location is actually in the home directory. > Second you are doing a createdb, not sure how Postgres handles using .pgpass > with database that does not exist yet? Might want to try a '*' in the database name > field or since it looks like it is trying to connect to the postgres database, use that > as the database name. The database actually exists, so createdb should fail with a "database exists" error. However, it didn't get there. I took your advice anyways and it fixes the problem. Thanks! ...Stephen
On 06/21/2013 04:29 PM, Stephen Rasku wrote: > On Fri, Jun 21, 2013 at 3:41 PM, Adrian Klaver <adrian.klaver@gmail.com> wrote: >> >> First are you running the script from the location with .pgpass? > > I wasn't but I copied the .pgpass into the local directory and I get > the same results. The correct location is actually in the home > directory. > >> Second you are doing a createdb, not sure how Postgres handles using .pgpass >> with database that does not exist yet? Might want to try a '*' in the database name >> field or since it looks like it is trying to connect to the postgres database, use that >> as the database name. > > The database actually exists, so createdb should fail with a "database > exists" error. However, it didn't get there. Well the issue is that createdb needs to connect to another database first in order to create the new database. The default order is shown below, though it can be overriden: http://www.postgresql.org/docs/9.2/interactive/app-createdb.html --maintenance-db=dbname Specifies the name of the database to connect to when creating the new database. If not specified, the postgres database will be used; if that does not exist (or if it is the name of the new database being created), template1 will be used. > > I took your advice anyways and it fixes the problem. Thanks! > > ...Stephen > > -- Adrian Klaver adrian.klaver@gmail.com