How to upgrade postgresql from V13 to V14 or V15

permission denied for schema public

In regard to this specific insufficient privilege error reported…

I’ve had the same issue when trying to install an app (preview_generator).

I ended up spinning up a fresh docker-compose based to use it for comparisons with my actual sever.

My exact error messages at the logs were:

[settings] Erro: Doctrine\DBAL\Exception\DriverException: An exception occurred while executing a query: SQLSTATE[42501]: Insufficient privilege: 7 ERROR:  permission denied for schema public
LINE 1: CREATE TABLE oc_calendar_appt_configs (id BIGSERIAL NOT NULL...
                     ^ at <<closure>>

 0. /var/www/html/3rdparty/doctrine/dbal/src/Connection.php line 1814
    Doctrine\DBAL\Driver\API\PostgreSQL\ExceptionConverter->convert(["Doctrine\\DBAL ... "], ["Doctrine\\DBAL\\Query"])

I then used psql on the new container to check schema permissions.

16:03 $ docker-compose exec db psql -U nextcloud
psql (15.3)
Type "help" for help.

nextcloud=# \dnS+
                                                  List of schemas
        Name        |       Owner       |           Access privileges            |           Description            
--------------------+-------------------+----------------------------------------+----------------------------------
 information_schema | nextcloud         | nextcloud=UC/nextcloud                +| 
                    |                   | =U/nextcloud                           | 
 pg_catalog         | nextcloud         | nextcloud=UC/nextcloud                +| system catalog schema
                    |                   | =U/nextcloud                           | 
 pg_toast           | nextcloud         |                                        | reserved schema for TOAST tables
 public             | pg_database_owner | pg_database_owner=UC/pg_database_owner+| standard public schema
                    |                   | =U/pg_database_owner                  +| 
                    |                   | oc_abinoam=C/pg_database_owner         | 
(4 rows)

nextcloud=# exit

When comparing to my actual server the line oc_abinoam=C/pg_database_owner at public schema was missing.

Then I granted the permissions with:

echo "GRANT ALL PRIVILEGES ON SCHEMA public TO oc_abinoam;" | sudo docker-compose exec -T db psql -U nextcloud

I’m not sure, but I’d be probably fine issuing only a GRANT CREATE.

Then I was able to install apps like preview_generator and calendar.

I hope this help anybody with the same issue.