[Solved] MySQL to postgres migration problems with modules

For feature requests, please see: https://mattermost.com/suggestions/.

For troubleshooting questions, please post in the following format:

Summary
Failed to migrate modules

Steps to reproduce
Follow step 6 from:
https://docs.mattermost.com/deploy/postgres-migration-assist-tool.html

Expected behavior
Create tables and migrate data

Observed behavior
Migration failed with:

[root@mattermost mattermost-migration-assist]# pgloader boards.load > boards_migration.log
KABOOM!
FATAL error: Database error 3F000: schema "public" does not exist
QUERY: ALTER SCHEMA public RENAME TO mattermostdb;
An unhandled error condition has been signalled:
   Database error 3F000: schema "public" does not exist
QUERY: ALTER SCHEMA public RENAME TO mattermostdb;




What I am doing here?

Database error 3F000: schema "public" does not exist
QUERY: ALTER SCHEMA public RENAME TO mattermostdb;

I checked the logs from the earlier steps and found that normally you do an rename of public to mattermostdb and at the end you rename the schema back to public.

This seems to fail but I can see no error in my logfile.
Now I’m not sure if this is the only problem with the migration and i do not know how to check if everything is correct.
My migration.log ends with:

       mattermostdb.usertermsofservice          0          0                     0.006s
--------------------------------------  ---------  ---------  ---------  --------------
               COPY Threads Completion          0          8                     2.018s
                       Reset Sequences          0          0                     0.015s
                   Create Foreign Keys          0          2                     0.003s
                       Set Search Path          0          1                     0.000s
                      Install Comments          0          0                     0.000s
                            after load          0          4                     0.010s
--------------------------------------  ---------  ---------  ---------  --------------
                     Total import time          âś“     126913    51.5 MB          2.046s

I try to migrate a 9.11 LTS version and we never used postgres before so it is a “little bit” frustrating to change a good working system to something you do not know.
Another point in you documentation, we set the rights like you showed at:
Prepare your Mattermost database - Mattermost documentation
for RedHat systems and we failed to connect to localhost.
We had to add:
host all all 127.0.0.1/32 trust
because localhost will be resolved as 127.0.0.1 and not ::1.

At the end this migration is a little bit annoying because of all the around problems (like MySQL 8 native_password problems).

Best

Silvio

Started from zero today to check everything.
Deleted and reinstalled postgres to make sure everything is brand new.

Followed the instructions at:
https://docs.mattermost.com/install/prepare-mattermost-database.html
to prepare the server.

First step after db creations and rights settings:
Schema creation:

[root@mattermost mattermost-migration-assist]# ./migration-assist postgres "postgres://mmuser:my_secret_password@localhost:5432/mattermost?sslmode=disable" --run-migrations --mattermost-version="v9.11.4"
2024-12-02 11:09:03 pinging postgres...
2024-12-02 11:09:03 connected to postgres successfully.
An Error Occurred: could not check schema owner: the user "mmuser" is not owner of the "public" schema

The only owner change in the documention is:

ALTER DATABASE mattermost OWNER TO mmuser;

for the public schema only:

GRANT USAGE, CREATE ON SCHEMA PUBLIC TO mmuser;

is required.

Best

Silvio

Hi Silvio! Thank you for your detailed feedback and for walking through the steps so thoroughly. It sounds like there may be an issue with ownership and permissions for the public schema. You can try explicitly changing the schema ownership with this command: ALTER SCHEMA public OWNER TO mmuser; as outlined in our Postgres Migration Assist Tool documentation. If the issue persists, double-check that all prerequisites are met, including PostgreSQL configuration settings mentioned in the database preparation guide. Let us know how it goes or if additional questions arise! :blush:

Hi John,

thanks for the answer.
As I wrote, I startet again and followed the steps.
I ignored the ownership message with the “–check-schema-owner=false” option and it was possible to create the schema.

After that, the import was working and also the module import was possible.

The next step was to change the settings in the config.json.

I would be nice if you add the infos how you have to change to postgres.
Yes you can find the info in the documentation that you have to set it to postgres and not postgresql and also you have to change to postgres://user:pass … but it would be easier if you add a link to this part of the docu.

At the end the server did not start with:

Dec  3 17:42:48 mattermost mattermost[2007440]: info  [2024-12-03 17:42:48.260 Z] Server is initializing...                     caller="platform/service.go:175" go_version=go1.21.8
Dec  3 17:42:48 mattermost mattermost[2007440]: info  [2024-12-03 17:42:48.261 Z] Pinging SQL                                   caller="sql/sql_utils.go:67" database=master dataSource="postgres://%2A%2A%2A%2A:%2A%2A%2A%2A@localhost:5432/m
attermost?connect_timeout=10&sslmode=disable"
Dec  3 17:42:48 mattermost mattermost[2007440]: Error: failed to initialize platform: cannot create store: failed to apply database migrations: driver: postgres, message: failed to fetch current schema, command: current_schema, originalEr
ror: sql: Scan error on column index 0, name "current_schema": converting NULL to string is unsupported, query:
Dec  3 17:42:48 mattermost mattermost[2007440]: SELECT CURRENT_SCHEMA()
Dec  3 17:42:48 mattermost mattermost[2007440]: error [2024-12-03 17:42:48.266 Z] failed to initialize platform: cannot create store: failed to apply database migrations: driver: postgres, message: failed to fetch current schema, command:
 current_schema, originalError: sql: Scan error on column index 0, name "current_schema": converting NULL to string is unsupported, query:

and I was not really irritated by this.
Fortunately I found:

and that solved the problem.

Now I have to run backup and recovery checks and all the stuff around.

Best

Silvio

1 Like

Hi Silvio! Thanks so much for following up and sharing your progress. You’ve made great strides in overcoming those roadblocks. I’m glad you found a solution to the schema ownership issue, and I appreciate your thoughtful suggestion about including more explicit details in the documentation, especially regarding config.json changes and database connection strings.

I’ll pass along your feedback to the documentation and migration tool teams to consider these improvements. Good luck with your backup and recovery checks, and feel free to let us know if you run into any further issues or have additional insights to share! :blush: