Question

Nextcloud cannot connect to Digital Ocean Postgresql

Hi,

I’ve been trying to migrate a Nextcloud db instance running as a pod in Digital Ocean Kubernetes to Digital Ocean’s managed database service unsuccessfully. I’ve been able to communicate and migrate the data from the db to the managed postgres using the connection string provided from the portal. I also, ensured the db can only communicate through certain endpoints like the managed k8s. However, I’m just not being able to switch the database in the nextcloud instance.

The instance is in maintenance mode.

...
'dbtype' => 'pgsql',
'dbname' => '[my_database]',
'dbhost' => '[postgres_do_db_host_from_portal];sslmode=require',
'dbport' => '[postgres_do_db_port_from_portal]',
'dbtableprefix' => 'oc_',
'dbuser' => '[postgres_do_db_user_from_portal]',
'dbpassword' => '[unsalted_unencrypted_password_from_do_portal]',
...

Connection error:

root@nextcloud-pod:/var/www/html# sudo -u www-data php occ config:list
An unhandled exception has been thrown:
Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[08006] [7] timeout expired in /var/www/html/lib/private/DB/Connection.php:68
Stack trace:
#0 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(420): OC\DB\Connection->connect()
#1 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(380): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(324): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(683): Doctrine\DBAL\Connection->getDatabasePlatform()
#4 /var/www/html/lib/private/DB/Connection.php(155): Doctrine\DBAL\Connection->setTransactionIsolation(2)
#5 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(195): OC\DB\Connection->__construct(Array, Object(Doctrine\DBAL\Driver\PDOPgSql\Driver), Object(Doctrine\DBAL\Configuration), Object(Doctrine\Common\EventManager))
#6 /var/www/html/lib/private/DB/ConnectionFactory.php(157): Doctrine\DBAL\DriverManager::getConnection(Array, Object(Doctrine\DBAL\Configuration), Object(Doctrine\Common\EventManager))
#7 /var/www/html/lib/private/Server.php(748): OC\DB\ConnectionFactory->getConnection('pgsql', Array)
#8 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC\{closure}(Object(OC\Server))
#9 /var/www/html/lib/private/ServerContainer.php(125): Pimple\Container->offsetGet('OCP\\IDBConnecti...')
#10 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\ServerContainer->query('OCP\\IDBConnecti...')
#11 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(114): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(OC\Server))
#12 /var/www/html/lib/private/ServerContainer.php(125): Pimple\Container->offsetGet('DatabaseConnect...')
#13 /var/www/html/lib/private/Server.php(1664): OC\ServerContainer->query('DatabaseConnect...')
#14 /var/www/html/lib/private/Server.php(421): OC\Server->getDatabaseConnection()
#15 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC\{closure}(Object(OC\Server))
#16 /var/www/html/lib/private/ServerContainer.php(125): Pimple\Container->offsetGet('OC\\Authenticati...')
#17 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(70): OC\ServerContainer->query('OC\\Authenticati...', true)
#18 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(100): OC\AppFramework\Utility\SimpleContainer->buildClass(Object(ReflectionClass))
#19 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(115): OC\AppFramework\Utility\SimpleContainer->resolve('OC\\Authenticati...')
#20 /var/www/html/lib/private/ServerContainer.php(150): OC\AppFramework\Utility\SimpleContainer->query('OC\\Authenticati...', true)
#21 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(70): OC\ServerContainer->query('OC\\Authenticati...', true)
#22 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(100): OC\AppFramework\Utility\SimpleContainer->buildClass(Object(ReflectionClass))
#23 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(115): OC\AppFramework\Utility\SimpleContainer->resolve('OC\\Authenticati...')
#24 /var/www/html/lib/private/ServerContainer.php(150): OC\AppFramework\Utility\SimpleContainer->query('OC\\Authenticati...', true)
#25 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\ServerContainer->query('OC\\Authenticati...')
#26 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(114): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(OC\Server))
#27 /var/www/html/lib/private/ServerContainer.php(125): Pimple\Container->offsetGet('OC\\Authenticati...')
#28 /var/www/html/lib/private/Server.php(433): OC\ServerContainer->query('OC\\Authenticati...')
#29 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC\{closure}(Object(OC\Server))
#30 /var/www/html/lib/private/ServerContainer.php(125): Pimple\Container->offsetGet('OC\\User\\Session')
#31 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\ServerContainer->query('OC\\User\\Session')
#32 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(114): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(OC\Server))
#33 /var/www/html/lib/private/ServerContainer.php(125): Pimple\Container->offsetGet('UserSession')
#34 /var/www/html/lib/private/Server.php(1547): OC\ServerContainer->query('UserSession')
#35 /var/www/html/lib/private/Server.php(1143): OC\Server->getSession()
#36 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC\{closure}(Object(OC\Server))
#37 /var/www/html/lib/private/ServerContainer.php(125): Pimple\Container->offsetGet('OC\\Security\\CSR...')
#38 /var/www/html/lib/private/Server.php(1138): OC\ServerContainer->query('OC\\Security\\CSR...')
#39 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC\{closure}(Object(OC\Server))
#40 /var/www/html/lib/private/ServerContainer.php(125): Pimple\Container->offsetGet('OC\\Security\\CSR...')
#41 /var/www/html/lib/private/Server.php(2011): OC\ServerContainer->query('OC\\Security\\CSR...')
#42 /var/www/html/lib/private/Server.php(937): OC\Server->getCsrfTokenManager()
#43 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC\{closure}(Object(OC\Server))
#44 /var/www/html/lib/private/ServerContainer.php(125): Pimple\Container->offsetGet('OCP\\IRequest')
#45 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\ServerContainer->query('OCP\\IRequest')
#46 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(114): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(OC\Server))
#47 /var/www/html/lib/private/ServerContainer.php(125): Pimple\Container->offsetGet('Request')
#48 /var/www/html/lib/private/Server.php(1414): OC\ServerContainer->query('Request')
#49 /var/www/html/lib/private/Server.php(579): OC\Server->getRequest()
#50 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC\{closure}(Object(OC\Server))
#51 /var/www/html/lib/private/ServerContainer.php(125): Pimple\Container->offsetGet('OCP\\L10N\\IFacto...')
#52 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\ServerContainer->query('OCP\\L10N\\IFacto...')
#53 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(114): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(OC\Server))
#54 /var/www/html/lib/private/ServerContainer.php(125): Pimple\Container->offsetGet('L10NFactory')
#55 /var/www/html/lib/private/Server.php(1600): OC\ServerContainer->query('L10NFactory')
#56 /var/www/html/lib/private/Server.php(1611): OC\Server->getL10NFactory()
#57 /var/www/html/lib/base.php(239): OC\Server->getL10N('lib')
#58 /var/www/html/lib/base.php(650): OC::checkConfig()
#59 /var/www/html/lib/base.php(1089): OC::init()
#60 /var/www/html/console.php(48): require_once('/var/www/html/l...')
#61 /var/www/html/occ(11): require_once('/var/www/html/c...')
Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

In my case, it was for postgres. Here it is:

‘dbtype’ => ‘pgsql’, ‘dbname’ => ‘your_database_name’, ‘dbhost’ => ‘digitalocean_manage_db_server_hostname:digitalocean_manage_db_server_port’, ‘dbuser’ => ‘your_database_user’, ‘dbpassword’ => ‘your_database_password’