Nextcloud unable to create tables with PostgreSQL 14

Hello,

I’ve succesfully installed Nextcloud using setup-nextcloud.php script but I can’t make it work with PostgreSQL 14.
After I set up DB information in index.php and click “Install” Nextcloud shows an error:

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

It seems that Nextcloud can’t create tables because the DB is empty.
I’m pretty sure I set up PostgreSQL correctly because I can connect to the DB manually as Nextcloud user and creating/removing tables works fine.

Here’s pg_hba.conf:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

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

And config.php:

<?php
$CONFIG = array (
  'instanceid' => '***',
  'passwordsalt' => '***',
  'secret' => '***',
  'trusted_domains' => 
  array (
    0 => '***',
  ),
  'datadirectory' => '/var/www/html/nextcloud/data',
  'dbtype' => 'pgsql',
  'version' => '28.0.3.2',
  'overwrite.cli.url' => 'http://***/nextcloud',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nextcloud',
  'dbpassword' => '***',
  'installed' => true,
);

Also there’s an error in nextcloud.log after installation: Could not decrypt or decode encrypted session data - but I’m not sure if it’s related to the problem.

I don’t think it’s necessarily a problem with PostgreSQL. If you can just reinstall it, you could try installing it with SQLite. Does the Nextcloud then work? If so, it will be due to the database. If not, then the problem lies elsewhere. Maybe you are missing some PHP library, for example.

SQLite is more for tests. It is not recommended to use it for productive Nextclouds. I use it for my Nextcloud 29 Beta installation. It is very easy to use it to restore a backup. It also excludes errors with the MariaDB and PostgreSQL databases. Test installation with one user, 1000 files and 200 MB of data.

1 Like

I tried SQLite and it works fine.

What PHP libs could I miss? I installed php8.2-pgsql and php8.2-pdo_pgsql.

Sorry i do not use PostgreSQL. But please read here. Which operating system and version do you use?

OS: Alt Linux p10
PostgreSQL: 14.10
Apache: 2.4.58
PHP: 8.2.15

From Postgres logs I see that Nextcloud is able to connect to the DB, it tries to run SELECT and Postgres shows errors because the tables don’t exist. But somehow Nextcloud unable to create these tables during installation.

How precisely did you create the PostgreSQL credentials?[1]

IIRC there are some differences depending on whether Nextcloud is creating the actual dbuser (if you provide db admin credentials) versus if you are specifying non-admin db credentials. There’s also the public schema stuff, which is PostgreSQL specific.

I don’t recall all the specifics offhand.

[1] Database configuration — Nextcloud latest Administration Manual latest documentation

I don’t know what was the cause, I purged everything (including Linux) and installed again and now it works.

1 Like