pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: nageswara Bandla <nag.bandla@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: Pgagent is not reading pgpass file either in Windows or Linux.
Date: Tue, 29 May 2018 13:32:46 -0700
Message-ID: <5595335e-32e8-80da-9c65-8d79fce554a7@aklaver.com> (raw)
In-Reply-To: <CADJadRDCoHALsJQv8ySQiO2QdgWnfqVL+iX-v72QxA6pFtgYtg@mail.gmail.com>
References: <CADJadRDCoHALsJQv8ySQiO2QdgWnfqVL+iX-v72QxA6pFtgYtg@mail.gmail.com>

On 05/29/2018 12:14 PM, nageswara Bandla wrote:
> The intention of this post is to find out ways to run pgagent without 
> passing password in its connection string.
> 
> *Windows:*
> 
> I have installed pgagent on windows and configured to run under Local 
> System account.
> 
> Command:-
> 
> C:\PostgreSQL\bigsql\pgagent\bin\pgagent.exeINSTALL pgagent -l 2 -u 
> LocalSystem hostaddr=127.0.0.1 dbname=postgresdb user=postgres
> 
> I have logged into my windows account; where my profile has pgpass.conf 
> in %APPDATA%/postgresql/pgpass.conf file.
> 
> 127.0.0.1:5432:*:postgres:postgres1
> 
> Pgagent is not started and throws error –“The pgagent service on Local 
> Computer started and then stopped. Some services stop automatically if 
> they are not in use by other services or programs”.
> 
> Eventvwr log messages have these error messages - “Couldn't create the 
> primary connection (attempt 10): fe_sendauth: no password supplied”
> 
> *PGPASSFILE env variable:*
> 
> As per the link- 
> (https://www.postgresql.org/docs/9.6/static/libpq-pgpass.html) I set 
> PGPASSFILE environment variable to point to pgpass.conf location. Even 
> then, it’s throwing same above error message. I have found out that 
> pgagent is not reading pgpass.conf file when configured under 
> LocalSystem account.
> 
> When I change the properties of the pgagent service to run under my 
> login user account. Then, it’s reading pgpass.conf file under 
> %APPDATA%/postgresql/pgpass.conf.
> 
> I am clueless, why pgagent is not honoring PGPASSFILE env variable.

My guess because the LocalSystem user does not have permissions on your:

%APPDATA%/postgresql/pgpass.conf

file. This seems to be confirmed by it working when you run pgagent as 
the login user.

Also:

passfile

     Specifies the name of the file used to store passwords (see Section 
33.15). Defaults to ~/.pgpass, or %APPDATA%\postgresql\pgpass.conf on 
Microsoft Windows. (No error is reported if this file does not exist.)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



> 
> *Linux:*
> 
> In Linux, I have installed pgagent_96 using yum command. And tried to 
> run pgagent using command /etc/init.d/pgagent_96 from postgres user account.

This is going to depend on what pgagent_96 is doing?

> 
> It fails with error message – “WARNING: Couldn't create the primary 
> connection (attempt 2): fe_sendauth: no password supplied”

What happens if from the terminal as the postgres user you do?:

/path/to/pgagent 'connection string'

> 
> I made sure that I have .pgpass configuration file with 0600 permissions 
> in postgres user home directory.
> 
> I have tried by defining PGPASSFILE env variable in postgres user 
> account. But it’s not working.
> 
> Pgagent is starting only when we pass password in it’s connection 
> string. But which is not a good practice at all.
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (20+ messages)  latest in thread

Message-ID: <5595335e-32e8-80da-9c65-8d79fce554a7@aklaver.com>
Permalink:  ../5595335e-32e8-80da-9c65-8d79fce554a7@aklaver.com/
Also on:    postgresql.org/message-id/5595335e-32e8-80da-9c65-8d79fce554a7@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, nag.bandla@gmail.com
  Subject: Re: Pgagent is not reading pgpass file either in Windows or Linux.
  In-Reply-To: <5595335e-32e8-80da-9c65-8d79fce554a7@aklaver.com>
  References: <CADJadRDCoHALsJQv8ySQiO2QdgWnfqVL+iX-v72QxA6pFtgYtg@mail.gmail.com> <5595335e-32e8-80da-9c65-8d79fce554a7@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox