pgadmin4 icon indicating copy to clipboard operation
pgadmin4 copied to clipboard

pgagent.exe "WARNING: Couldn't create the primary connection" PostgreSQL Scheduling Agent not starting

Open infotek opened this issue 1 year ago • 4 comments

We have a Windows Server 2019 Standard that has multiple versions of PostgreSQL installed on it, v13, v14, and v16. Each version is running on a different port. We would increase the older versions port (e.g. 5433) during migration of data to the newer version. Only v16 is actively running and it is running and it is running on tcp/5432.

We recently installed "PostgreSQL Scheduling Agent 4.2.2" and setup some schedules. The schedules would run manually via the pgadmin interface, but would not run as scheduled. We determined the service was not running. After some research we found the pgagent.exe at the command line would not work either.

E:\Program Files\PostgreSQL\16\bin>pgagent.exe DEBUG hostaddr=localhost port=5432 user=postgres dbname=postgres password=password
WARNING: Couldn't create the primary connection [Attempt #1]
WARNING: Couldn't create the primary connection [Attempt #2]
WARNING: Couldn't create the primary connection [Attempt #3]
WARNING: Couldn't create the primary connection [Attempt #4]
WARNING: Couldn't create the primary connection [Attempt #5]
WARNING: Couldn't create the primary connection [Attempt #6]
WARNING: Couldn't create the primary connection [Attempt #7]
WARNING: Couldn't create the primary connection [Attempt #8]
WARNING: Couldn't create the primary connection [Attempt #9]
WARNING: Couldn't create the primary connection [Attempt #10]
ERROR: Stopping pgAgent: Couldn't establish the primary connection with the database server.
E:\Program Files\PostgreSQL\16\bin>psql -h localhost -p 5432 -U postgres
Password for user postgres:
psql (16.1)
WARNING: Console code page (437) differs from Windows code page (1252)
         8-bit characters might not work correctly. See psql reference
         page "Notes for Windows users" for details.
Type "help" for help.

postgres=# select version();
                          version
------------------------------------------------------------
 PostgreSQL 16.1, compiled by Visual C++ build 1937, 64-bit
(1 row)

When trying to start the Windows pgAgent Scheduler service, Windows eventlog logs the following errors:

Couldn't create the primary connection [Attempt #10] Stopping pgAgent: Couldn't establish the primary connection with the database server.

I'm not sure how to proceed with more debug information.

infotek avatar Aug 15 '24 14:08 infotek

what does the [Not Refined] reference indicate?

infotek avatar Aug 26 '24 09:08 infotek

@infotek,

We have weekly backlog refinement, during which we read the issue and take the necessary steps.

akshay-joshi avatar Aug 26 '24 11:08 akshay-joshi

hostaddr=localhost is not valid. You can use hostaddr=127.0.0.1 or host=localhost or something similar. If using hostaddr, the value must be a numeric IPv4 or IPv6 address, not a hostname.

dpage avatar Sep 05 '24 10:09 dpage

hostaddr=localhost is not valid. You can use hostaddr=127.0.0.1 or host=localhost or something similar. If using hostaddr, the value must be a numeric IPv4 or IPv6 address, not a hostname.

E:\Program Files\PostgreSQL\16\bin>pgagent.exe DEBUG hostaddr=127.0.0.1 port=5432 user=postgres dbname=db password=password WARNING: Couldn't create the primary connection [Attempt #1] WARNING: Couldn't create the primary connection [Attempt #2] WARNING: Couldn't create the primary connection [Attempt #3] WARNING: Couldn't create the primary connection [Attempt #4] WARNING: Couldn't create the primary connection [Attempt #5] WARNING: Couldn't create the primary connection [Attempt #6] WARNING: Couldn't create the primary connection [Attempt #7] WARNING: Couldn't create the primary connection [Attempt #8] WARNING: Couldn't create the primary connection [Attempt #9] WARNING: Couldn't create the primary connection [Attempt #10] ERROR: Stopping pgAgent: Couldn't establish the primary connection with the database server.

infotek avatar Sep 05 '24 14:09 infotek

@infotek

Can you please run the following command it will give the exact error: E:\Program Files\PostgreSQL\16\bin>pgagent.exe DEBUG -l2 hostaddr=127.0.0.1 port=5432 user=postgres dbname=db password=password

akshay-joshi avatar Jan 03 '25 07:01 akshay-joshi

@infotek

It is working for me when I set the environment variable PGPASSWORD. I tried passing the password as a parameter and using the pgpass file on Windows; it is not working in both cases.

akshay-joshi avatar Jan 06 '25 08:01 akshay-joshi

No response from the author, hence closing it.

akshay-joshi avatar Jan 23 '25 06:01 akshay-joshi

This is still an issue and only the solution of setting the the password as an environment variable worked.

JulianDietzel avatar Sep 03 '25 15:09 JulianDietzel