Failed to connect to the database could not connect to server: Network is unreachable

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version: 20.0.4
Operating system and version: openSUSE Leap 15.2
Apache or nginx version: nginx 1.16.1
PHP version: 7.4.6
Database: Postgresql 10

The issue you are facing:

Is this the first time you’ve seen this error? (Y/N):

Steps to replicate it:

Hello everyone, I need help, there was a problem, NC cannot connect to the database, the log is given below, but I can connect to the database itself from anywhere and using any utilities, the database is working and without errors, there are no errors in the web server logs, I tried to create a new one DB, I get a similar error even with a new database, I tried to update PHP, the result was also not given, why suddenly such an error appeared, even without a clue, it worked, and just stopped, maybe someone will tell you how to fix it

The output of your Nextcloud log in Admin > Logging:

        An unhandled exception has been thrown:
        Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Network is unreachable
                Is the server running on host "example.org" (11.11.11.11) and accepting
                TCP/IP connections on port 5432? in /srv/www/htdocs/nextcloud/lib/private/DB/Connection.php:72
        Stack trace:
        #0 /srv/www/htdocs/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(1449): OC\DB\Connection->connect()
        #1 /srv/www/htdocs/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(892): Doctrine\DBAL\Connection->getWrappedConnection()
        #2 /srv/www/htdocs/nextcloud/lib/private/DB/Connection.php(202): Doctrine\DBAL\Connection->executeQuery('SELECT * FROM "...', Array, Array, NULL)
        #3 /srv/www/htdocs/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php(206): OC\DB\Connection->executeQuery('SELECT * FROM "...', Array, Array)
        #4 /srv/www/htdocs/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(217): Doctrine\DBAL\Query\QueryBuilder->execute()
        #5 /srv/www/htdocs/nextcloud/lib/private/AppConfig.php(345): OC\DB\QueryBuilder\QueryBuilder->execute()
        #6 /srv/www/htdocs/nextcloud/lib/private/AppConfig.php(110): OC\AppConfig->loadConfigValues()
        #7 /srv/www/htdocs/nextcloud/lib/private/AppConfig.php(301): OC\AppConfig->getApps()
        #8 /srv/www/htdocs/nextcloud/lib/private/legacy/OC_App.php(949): OC\AppConfig->getValues(false, 'installed_versi...')
        #9 /srv/www/htdocs/nextcloud/lib/private/Server.php(668): OC_App::getAppVersions()
        #10 /srv/www/htdocs/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(155): OC\Server->OC\{closure}(Object(OC\Server))
        #11 /srv/www/htdocs/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
        #12 /srv/www/htdocs/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(122): Pimple\Container->offsetGet('OC\\Memcache\\Fac...')
        #13 /srv/www/htdocs/nextcloud/lib/private/ServerContainer.php(156): OC\AppFramework\Utility\SimpleContainer->query('OC\\Memcache\\Fac...', true)
        #14 /srv/www/htdocs/nextcloud/lib/private/Server.php(1677): OC\ServerContainer->query('OC\\Memcache\\Fac...')
        #15 /srv/www/htdocs/nextcloud/lib/private/Server.php(1017): OC\Server->getMemCacheFactory()
        #16 /srv/www/htdocs/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(155): OC\Server->OC\{closure}(Object(OC\Server))
        #17 /srv/www/htdocs/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
        #18 /srv/www/htdocs/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(122): Pimple\Container->offsetGet('OCP\\Lock\\ILocki...')
        #19 /srv/www/htdocs/nextcloud/lib/private/ServerContainer.php(156): OC\AppFramework\Utility\SimpleContainer->query('OCP\\Lock\\ILocki...', true)
        #20 /srv/www/htdocs/nextcloud/lib/private/Server.php(1977): OC\ServerContainer->query('OCP\\Lock\\ILocki...')
        #21 /srv/www/htdocs/nextcloud/lib/private/Files/View.php(118): OC\Server->getLockingProvider()
        #22 /srv/www/htdocs/nextcloud/lib/private/Server.php(395): OC\Files\View->__construct()
        #23 /srv/www/htdocs/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(155): OC\Server->OC\{closure}(Object(OC\Server))
        #24 /srv/www/htdocs/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
        #25 /srv/www/htdocs/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(122): Pimple\Container->offsetGet('OC\\Files\\Node\\H...')
        #26 /srv/www/htdocs/nextcloud/lib/private/ServerContainer.php(156): OC\AppFramework\Utility\SimpleContainer->query('OC\\Files\\Node\\H...', true)
        #27 /srv/www/htdocs/nextcloud/lib/private/Server.php(1324): OC\ServerContainer->query('OC\\Files\\Node\\H...')
        #28 /srv/www/htdocs/nextcloud/lib/base.php(595): OC\Server->boot()
        #29 /srv/www/htdocs/nextcloud/lib/base.php(1091): OC::init()
        #30 /srv/www/htdocs/nextcloud/console.php(49): require_once('/srv/www/htdocs...')
        #31 /srv/www/htdocs/nextcloud/occ(11): require_once('/srv/www/htdocs...')

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => 'abc',
  'passwordsalt' => 'abc',
  'secret' => 'abc',
  'trusted_domains' => 
  array (
    0 => 'example.org',
  ),
  'datadirectory' => '/srv/www/htdocs/nextcloud/data',
  'dbtype' => 'pgsql',
  'version' => '20.0.4.0',
  'overwrite.cli.url' => 'https://example.org',
  'dbname' => 'nextcloud',
  'dbhost' => 'example.org',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'cloud',
  'dbpassword' => 'password',
  'installed' => true,
  'trashbin_retention_obligation' => 'disabled',
  'maintenance' => false,
  "log_type" => "file",
  'logfile' => 'nextcloud-error.log',
  'loglevel' => 3,
  'debug' => true,
  'logdateformat" => "F d, Y H:i:s',
  'filelocking.enabled' => true,
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/default.sock',
    'port' => 0,
    'timeout' => 0.0,
  ),
  'mail_from_address' => 'email',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'ya.ru',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'smtp.yandex.com',
  'mail_smtpport' => '465',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpname' => 'user',
  'mail_smtppassword' => 'password',
  'has_rebuilt_cache' => true,
  'theme' => '',
  'mail_smtpsecure' => 'ssl',
  'updater.release.channel' => 'stable',
);

The output of your Apache/nginx/system log in /var/log/____:

No errors

Found an error in the config, sorry

'dbhost' => 'example.org', > 'dbhost' => 'localhost',

I don’t even know why there was a domain name