Upgraded postgres from 16 to 17 and now nextcloud won't connect

The basics

Nextcloud version: nextcloud:stable-fpm-alpine@sha256:fd092d936643c2e0c0b80c27d5518c793e5e215d5b5836e5ecdca973395b2c34
Operating system: Truenas scale 2410

The issue

I just upgraded the postgres server for my nextcloud instance. from 16 to 17.
I followed the normal procedure and did a pg_dump and imported that in a fresh postgres 17 server and once everything was running fine again I spun down the container and spun it back up with the rest of the nextcloud container components. (redis, nextcloud, nextcloud_cron)

However once it all started back up I am no longer able to connect the my nextcloud and based on the nextcloud.log it seems that nextcloud is for some reason unable to connect to the postgres database.

Based on what I can understand it seems to be unable to resolve the hostname to the postgres database, which I do not understand.

I can verify that POSTGRES_USER, POSTGRES_HOST, POSTGRES_DB and POSTGRES_PASSWORD are all set correctly and I myself can psql connect to the database from the nextcloud container by using
psql -h $POSTGRES_HOST -p 5432 -U $POSTGRES_USER -d $POSTGRES_DB

I found the following related topic: How to upgrade postgresql from V13 to V14 or V15 - #5 by abinoam
where someone suggested to look in config.php and confirm that the username and password were correct, and there were some issues there, which I fixed. However, the hostname was correct, and it seems to already stumble on that part.

Did I forget to change anything else? Or can anyone else see what I’m missing or messed up?

tail end of the nextcloud.log file:


{"reqId":"wkqWxVSUiI2kaRVvbzqa","level":3,"time":"2025-02-28T13:05:57+00:00","remoteAddr":"127.0.0.1","user":"--","app":"core","method":"GET","url":"/","message":"Exception thrown: Doctrine\\DBAL\\Exception","userAgent":"curl/7.88.1","version":"29.0.8.1","exception":{"Exception":"Doctrine\\DBAL\\Exception","Message":"Failed to connect to the database: An exception occurred in the driver: SQLSTATE[08006] [7] could not translate host name \"postgres\" to address: No address associated with hostname","Code":7,"Trace":[{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Connection.php","line":453,"function":"connect","class":"OC\\DB\\Connection","type":"->","args":[]},{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Connection.php","line":411,"function":"getDatabasePlatformVersion","class":"Doctrine\\DBAL\\Connection","type":"->","args":[]},{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Connection.php","line":318,"function":"detectDatabasePlatform","class":"Doctrine\\DBAL\\Connection","type":"->","args":[]},{"file":"/var/www/html/lib/private/DB/ConnectionAdapter.php","line":200,"function":"getDatabasePlatform","class":"Doctrine\\DBAL\\Connection","type":"->","args":[]},{"file":"/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php","line":121,"function":"getDatabasePlatform","class":"OC\\DB\\ConnectionAdapter","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppConfig.php","line":1239,"function":"expr","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppConfig.php","line":264,"function":"loadConfig","class":"OC\\AppConfig","type":"->","args":[false]},{"file":"/var/www/html/lib/private/legacy/OC_App.php","line":736,"function":"searchValues","class":"OC\\AppConfig","type":"->","args":["installed_version"]},{"file":"/var/www/html/lib/private/TemplateLayout.php","line":237,"function":"getAppVersions","class":"OC_App","type":"::","args":[]},{"file":"/var/www/html/lib/private/legacy/OC_Template.php","line":145,"function":"__construct","class":"OC\\TemplateLayout","type":"->","args":["error",""]},{"file":"/var/www/html/lib/private/Template/Base.php","line":132,"function":"fetchPage","class":"OC_Template","type":"->","args":[]},{"file":"/var/www/html/lib/private/legacy/OC_Template.php","line":320,"function":"printPage","class":"OC\\Template\\Base","type":"->","args":[]},{"file":"/var/www/html/index.php","line":114,"function":"printExceptionErrorPage","class":"OC_Template","type":"::","args":[["Doctrine\\DBAL\\Exception"],500]}],"File":"/var/www/html/lib/private/DB/Connection.php","Line":167,"CustomMessage":"Exception thrown: Doctrine\\DBAL\\Exception"}}

With the exactly same credentials from your config.php ?

I ran into a similar issue and missed a setting in PostgreSQL: Documentation: 17: 20.1. The pg_hba.conf File

Yeah I typed psql -h $POSTGRES_HOST -p 5432 -U $POSTGRES_USER -d $POSTGRES_DB inside my nextcloud container and entered the password from $POSTGRES_PASSWORD and it connected successfully.

The settings inside config.php were different, but I changed them to match the ones in the environment variables, and restarted the container, but with the exact same result.

regarding the pg_hba.conf file, as far as I can see this should not affect my case since I can manually connect from the nextcloud container to the postgres container, unless I’m missing something?

One more thing to note is that I had to install postgres manually in the nextcloud container to connect to the postgres database using psql, since I’m using the alpine image for nextcloud. How does nextcloud normally connect to the postgres database? or are there any special issues with the alpine container that I should be aware of?

I am not using docker.

Nextcloud is using the php-postgresql package to connect to an db server.

That was just a hint/ideal to fix your issue.

You can fine-tune the access there and there are also the db permissions within the db itself.

p.s. next time please use the support template to provide all information to help you.

1 Like

SQLSTATE[08006] [7] could not translate host name \"postgres\" to address: No address associated with hostname"

Yeah I typed psql -h $POSTGRES_HOST -p 5432 -U $POSTGRES_USER -d $POSTGRES_DB inside my nextcloud container and entered the password from $POSTGRES_PASSWORD and it connected successfully

To confirm, $POSTGRES_HOST is postgres, correct? Since that’s what Nextcloud appears to be using.

The settings inside config.php were different, but I changed them to match the ones in the environment variables, and restarted the container, but with the exact same result.

Note that the image uses multiple config files. You can’t just look at config/config.php. Your real config is a merged config. Use occ config:list system to see the real config. Reference

One more thing to note is that I had to install postgres manually in the nextcloud container to connect to the postgres database using psql, since I’m using the alpine image for nextcloud. How does nextcloud normally connect to the postgres database? or are there any special issues with the alpine container that I should be aware of?

Nextcloud uses PHP’s pdo_pgsql module.

1 Like

Sorry I only saw the template in the small window I was typing in and tried to answer the questions I saw in it but it was a bit messy and I likely missed some things. But I will copy it out and have it open next to my question next time so I can follow it better.

Thank you for you answer.

To confirm, $POSTGRES_HOST is postgres, correct? Since that’s what Nextcloud appears to be using.

Yes $POSTGRES_HOST is indeed just postgres.

Note that the image uses multiple config files. You can’t just look at config/config.php. Your real config is a merged config. Use occ config:list system to see the real config. Reference

Thank you, I will try and take a look at that and see whether that can help me resolve the issue.