Discussion:
.pgpass being ignored
Stephen Rasku
2013-06-21 22:25:46 UTC
Permalink
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
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Raymond O'Donnell
2013-06-21 22:33:30 UTC
Permalink
Post by Stephen Rasku
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
$ ls -l $PGPASSFILE
-rw------- 1 Stephen staff 43 21 Jun 14:48 /Users/Stephen/.pgpass
$ createdb -h 192.168.1.4 -U postgres --no-password JobSearch
createdb: could not connect to database postgres: fe_sendauth: no
password supplied
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
***@iol.ie
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Stephen Rasku
2013-06-21 23:03:21 UTC
Permalink
Post by Raymond O'Donnell
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
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Adrian Klaver
2013-06-21 22:41:28 UTC
Permalink
Post by Stephen Rasku
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
$ ls -l $PGPASSFILE
-rw------- 1 Stephen staff 43 21 Jun 14:48 /Users/Stephen/.pgpass
$ createdb -h 192.168.1.4 -U postgres --no-password JobSearch
createdb: could not connect to database postgres: fe_sendauth: no
password supplied
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.
Post by Stephen Rasku
...Stephen
--
Adrian Klaver
***@gmail.com
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Stephen Rasku
2013-06-21 23:29:22 UTC
Permalink
Post by Adrian Klaver
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.
Post by Adrian Klaver
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
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Adrian Klaver
2013-06-21 23:35:15 UTC
Permalink
Post by Stephen Rasku
Post by Adrian Klaver
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.
Post by Adrian Klaver
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.
Post by Stephen Rasku
I took your advice anyways and it fixes the problem. Thanks!
...Stephen
--
Adrian Klaver
***@gmail.com
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Stephen Rasku
2013-06-21 22:19:16 UTC
Permalink
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
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Ziggy Skalski
2013-06-24 14:17:21 UTC
Permalink
Post by Stephen Rasku
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
$ ls -l $PGPASSFILE
-rw------- 1 Stephen staff 43 21 Jun 14:48 /Users/Stephen/.pgpass
$ createdb -h 192.168.1.4 -U postgres --no-password JobSearch
createdb: could not connect to database postgres: fe_sendauth: no
password supplied
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
Hi,

Just going from a personal experience, have you tried to open the
.pgpass file in vi and made sure there's no trailing spaces in your
pgpass entry? That bit me once before :)

Ziggy
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Rebecca Clarke
2013-06-24 14:24:55 UTC
Permalink
I could be wrong, but shouldn't the owner of .pgpass be postgres?
Post by Stephen Rasku
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
$ ls -l $PGPASSFILE
-rw------- 1 Stephen staff 43 21 Jun 14:48 /Users/Stephen/.pgpass
$ createdb -h 192.168.1.4 -U postgres --no-password JobSearch
createdb: could not connect to database postgres: fe_sendauth: no
password supplied
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
Hi,
Just going from a personal experience, have you tried to open the .pgpass
file in vi and made sure there's no trailing spaces in your pgpass entry?
That bit me once before :)
Ziggy
--
http://www.postgresql.org/**mailpref/pgsql-general<http://www.postgresql.org/mailpref/pgsql-general>
Jan Wieck
2013-06-24 15:03:02 UTC
Permalink
Post by Rebecca Clarke
I could be wrong, but shouldn't the owner of .pgpass be postgres?
The owner of ~/.pgpass is whoever owns ~ (the home directory of that user).

And ~/.pgpass must have permissions 0600 in order for libpq to actually
use it.


Jan
Post by Rebecca Clarke
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
$ ls -l $PGPASSFILE
-rw------- 1 Stephen staff 43 21 Jun 14:48
/Users/Stephen/.pgpass
$ createdb -h 192.168.1.4 -U postgres --no-password JobSearch
fe_sendauth: no
password supplied
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
Hi,
Just going from a personal experience, have you tried to open the
.pgpass file in vi and made sure there's no trailing spaces in your
pgpass entry? That bit me once before :)
Ziggy
--
http://www.postgresql.org/__mailpref/pgsql-general
<http://www.postgresql.org/mailpref/pgsql-general>
--
Anyone who trades liberty for security deserves neither
liberty nor security. -- Benjamin Franklin
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Frank Broniewski
2013-06-25 06:36:55 UTC
Permalink
Post by Stephen Rasku
$ createdb -h 192.168.1.4 -U postgres --no-password JobSearch
createdb: could not connect to database postgres: fe_sendauth: no
password supplied
Hi,

isn't your --no-password switch preventing this? I never use this switch
and my .pgpass is used by shell scripts and other programs ...


Frank
--
Frank BRONIEWSKI

METRICO s.à r.l.
géomètres
technologies d'information géographique
rue des Romains 36
L-5433 NIEDERDONVEN

tél.: +352 26 74 94 - 28
fax.: +352 26 74 94 99
http://www.metrico.lu
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Adrian Klaver
2013-06-25 13:37:54 UTC
Permalink
Post by Frank Broniewski
Post by Stephen Rasku
$ createdb -h 192.168.1.4 -U postgres --no-password JobSearch
fe_sendauth: no
password supplied
Hi,
isn't your --no-password switch preventing this? I never use this switch
and my .pgpass is used by shell scripts and other programs ...
http://www.postgresql.org/docs/9.2/interactive/app-createdb.html

-w
--no-password
Never issue a password prompt. If the server requires password
authentication and a password is not available by other means such as a
.pgpass file, the connection attempt will fail. This option can be
useful in batch jobs and scripts where no user is present to enter a
password.
Post by Frank Broniewski
Frank
--
Adrian Klaver
***@gmail.com
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Magnus Hagander
2013-06-25 14:13:56 UTC
Permalink
Post by Stephen Rasku
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
$ ls -l $PGPASSFILE
-rw------- 1 Stephen staff 43 21 Jun 14:48 /Users/Stephen/.pgpass
$ createdb -h 192.168.1.4 -U postgres --no-password JobSearch
createdb: could not connect to database postgres: fe_sendauth: no
password supplied
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?
From the error message, the failure is to connect to the database
"postgres". Your .pgpass only has an entry for database
"DatabaseName".

createdb will connect to "postgres" and issue the CREATE DATABASE
command there. You can change tihs with the parameter
--maintenance-db, but tat was added in 9.2 only. But even so, createdb
must connect to an *existing* database in order to issue the CREATE
DATABASE command, so you need a line in .pgpass for whichever
maintenance db you're using.

(also, you should really upgrade to 9.0.13, though that won't change
this specific case)

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Granthana
2014-08-18 16:49:07 UTC
Permalink
In case someone is facing the same problem again, solution is to add * in
.pgpass in place of ip address.





--
View this message in context: http://postgresql.1045698.n5.nabble.com/pgpass-being-ignored-tp5760421p5815268.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Loading...