Cron App: Error: Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused

Hi,

i recently migrated my nextcloud to another server and i can’t get rid of this error below:

I am able to connect to the database manually via psql -h localhost -U nextcloud.
All services are up. The nextcloud config.php contains the right password and should connect to ‘localhost’
I use ufw but port 5432 is allowed.

 [cron] Error: Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused
	Is the server running on host "localhost" (::1) and accepting
	TCP/IP connections on port 5432?
could not connect to server: Connection refused
	Is the server running on host "localhost" (127.0.0.1) and accepting
	TCP/IP connections on port 5432? at <<closure>>

 0. /srv/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php line 889
    OC\DB\Connection->connect()
 1. /srv/nextcloud/lib/private/DB/Connection.php line 194
    Doctrine\DBAL\Connection->executeQuery("SELECT * FROM \"oc_appconfig\"", [], [], null)
 2. /srv/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php line 200
    OC\DB\Connection->executeQuery("SELECT * FROM \"oc_appconfig\"", [], [])
 3. /srv/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php line 216
    Doctrine\DBAL\Query\QueryBuilder->execute()
 4. /srv/nextcloud/lib/private/AppConfig.php line 331
    OC\DB\QueryBuilder\QueryBuilder->execute()
 5. /srv/nextcloud/lib/private/AppConfig.php line 109
    OC\AppConfig->loadConfigValues()
 6. /srv/nextcloud/lib/private/AppConfig.php line 287
    OC\AppConfig->getApps()
 7. /srv/nextcloud/lib/private/legacy/OC_App.php line 883
    OC\AppConfig->getValues(false, "installed_version")
 8. /srv/nextcloud/lib/private/Server.php line 665
    OC_App::getAppVersions()
 9. /srv/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php line 118
    OC\Server->OC\{closure}("*** sensitive parameters replaced ***")
10. /srv/nextcloud/lib/private/ServerContainer.php line 124
    Pimple\Container->offsetGet("OC\\Memcache\\Factory")
11. /srv/nextcloud/lib/private/Server.php line 1704
    OC\ServerContainer->query("OC\\Memcache\\Factory")
12. /srv/nextcloud/lib/private/Server.php line 856
    OC\Server->getMemCacheFactory()
13. /srv/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php line 118
    OC\Server->OC\{closure}("*** sensitive parameters replaced ***")
14. /srv/nextcloud/lib/private/ServerContainer.php line 124
    Pimple\Container->offsetGet("OC\\App\\AppManager")
15. /srv/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php line 163
    OC\ServerContainer->query("OC\\App\\AppManager")
16. /srv/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php line 114
    OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}("*** sensitive parameters replaced ***")
17. /srv/nextcloud/lib/private/ServerContainer.php line 124
    Pimple\Container->offsetGet("OCP\\App\\IAppManager")
18. /srv/nextcloud/lib/private/Server.php line 1894
    OC\ServerContainer->query("OCP\\App\\IAppManager")
19. /srv/nextcloud/lib/private/legacy/OC_App.php line 347
    OC\Server->getAppManager()
20. /srv/nextcloud/lib/private/legacy/OC_App.php line 114
    OC_App::getEnabledApps()
21. /srv/nextcloud/lib/base.php line 648
    OC_App::loadApps(["session"])
22. /srv/nextcloud/lib/base.php line 1094
    OC::init()
23. /srv/nextcloud/cron.php line 42
    require_once("/srv/nextcloud/lib/base.php")

at 2020-10-19T16:35:01+00:00

pg_hba.conf:

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

local   nextcloud       nextcloud                               peer

postgres.conf:

...
# - Connection Settings -

listen_addresses = '*'          # what IP address(es) to listen on;

...

I’m out of ideas… Thanks for your help :slight_smile: