server icon indicating copy to clipboard operation
server copied to clipboard

Unable to reach Postgresql socket while not on default 5432 port

Open rbonnefoi opened this issue 1 year ago • 5 comments
trafficstars

⚠️ This issue respects the following points: ⚠️

Bug description

Nextcloud doesn't take into account the port setup when constructing the full full postgresql socket path. It always uses 5432, whatever the dbport setup is in config.php. Thus it is not possible to connect through socket way when Postgresql is not running on the default 5432 port.

Steps to reproduce

  1. in config.php set 'dbhost' to '/var/run/postgresql' (which is the debian root path of postgresql socket)
  2. and set 'dbport' to '1234' for instance
  3. try to load any nextcloud page
  4. check into the log for the error and the socket path shown

Expected behavior

Normally, the connection socket should be /var/run/postgresql/.s.PSQL.1234, while it is stuck to /var/run/postgresql/s.PSQL.5432

I think a better way for setup would be to fill the full socket path into dbhost parameter (eg /var/run/postgresql/.s.PSQL.1234) rather than splitting the socket config, as the postgresql config could even use another schema and/or path for the socket full path (for instance in the case when several parallel sockets are used for isolation).

Installation method

Community Web installer on a VPS or web space

Nextcloud Server version

29

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.2

Web server

Apache (supported)

Database engine version

PostgreSQL

Is this bug present after an update or on a fresh install?

Fresh Nextcloud Server install

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?

  • [X] Default user-backend (database)
  • [ ] LDAP/ Active Directory
  • [ ] SSO - SAML
  • [ ] Other

Configuration report

{
    "system": {
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "***REMOVED SENSITIVE VALUE***"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "pgsql",
        "version": "29.0.0.19",
        "overwrite.cli.url": "***REMOVED SENSITIVE VALUE***",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true
    }
}

List of activated Apps

Enabled:
  - activity: 2.21.1
  - calendar: 4.7.4
  - circles: 29.0.0-dev
  - cloud_federation_api: 1.12.0
  - comments: 1.19.0
  - contacts: 6.0.0
  - contactsinteraction: 1.10.0
  - dashboard: 7.9.0
  - dav: 1.30.1
  - federatedfilesharing: 1.19.0
  - federation: 1.19.0
  - files: 2.1.0
  - files_downloadlimit: 2.0.0
  - files_pdfviewer: 2.10.0
  - files_reminders: 1.2.0
  - files_sharing: 1.21.0
  - files_trashbin: 1.19.0
  - files_versions: 1.22.0
  - firstrunwizard: 2.18.0
  - logreader: 2.14.0
  - lookup_server_connector: 1.17.0
  - mail: 3.6.1
  - nextcloud_announcements: 1.18.0
  - notes: 4.10.0
  - notifications: 2.17.0
  - oauth2: 1.17.0
  - password_policy: 1.19.0
  - photos: 2.5.0
  - privacy: 1.13.0
  - provisioning_api: 1.19.0
  - recommendations: 2.1.0
  - related_resources: 1.4.0
  - richdocuments: 8.4.2
  - serverinfo: 1.19.0
  - settings: 1.12.0
  - sharebymail: 1.19.0
  - spreed: 19.0.1
  - support: 1.12.0
  - survey_client: 1.17.0
  - systemtags: 1.19.0
  - text: 3.10.0
  - theming: 2.4.0
  - twofactor_backupcodes: 1.18.0
  - updatenotification: 1.19.1
  - user_status: 1.9.0
  - viewer: 2.3.0
  - weather_status: 1.9.0
  - workflowengine: 2.11.0
Disabled:
  - admin_audit: 1.19.0
  - bruteforcesettings: 2.9.0
  - encryption: 2.17.0
  - files_external: 1.21.0
  - suspicious_login: 7.0.0
  - twofactor_totp: 11.0.0-dev
  - user_ldap: 1.20.0

Nextcloud Signing status

No response

Nextcloud Logs

No response

Additional info

No response

rbonnefoi avatar May 24 '24 12:05 rbonnefoi

dbport isn't a valid directive. The port gets specified as part of dbhost:

https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#dbhost

Since UNIX sockets don't have a concept of a port, it's a little weird how PostgreSQL includes the TCP port number in a the UNIX socket file name. If you really are running multiple instances/sockets on the same host, maybe use a dedicated path for each one?

https://www.postgresql.org/docs/current/runtime-config-connection.html#GUC-UNIX-SOCKET-DIRECTORIES

joshtrichards avatar May 24 '24 16:05 joshtrichards

Thanks for answering so rapidly.

I still have two questions :

  • I used the web installer, and the config.php was automatically created, embedding a dbport directive (which is set to empty string) 'dbport' => '', which is confusing,
  • if I try to fill the full socket path (eg 'dbhost' => '/var/run/postgresql/.s.PGSQL.1234',), I can't connect and I can see in the log that Nextcloud is trying to connect to /var/run/postgresql/.s.PGSQL.1234/.s.PGSQL.5432

I thing this setup behaviour for socket is not coherent with the ip one, and prevents people from using a non standard port, which is not so unusual.

But I may miss something.

Anyway, thanks for the help, and any further information will be welcome.

Regards.

rbonnefoi avatar May 24 '24 20:05 rbonnefoi

This issue has been automatically marked as stale because it has not had recent activity and seems to be missing some essential information. It will be closed if no further activity occurs. Thank you for your contributions.

nextcloud-command avatar Jun 30 '24 00:06 nextcloud-command

I used the web installer, and the config.php was automatically created, embedding a dbport directive (which is set to empty string) 'dbport' => '', which is confusing,

That's fair. It's a historic relic of the installer (well, there's more to it than that, but yes)..

in config.php set 'dbhost' to '/var/run/postgresql' (which is the debian root path of postgresql socket) and set 'dbport' to '1234' for instance

When I suggested a different path, when using multiple parallel db instances, I was saying that:

  • use /var/run/postgres1 as the db host for the first instance; /var/run/postgres2 for the second, and so on
  • then keep the default "port" (which is, in the case of a socket, not really a port at all and just a filename)

joshtrichards avatar Jun 30 '24 02:06 joshtrichards