Unable to upsert materialized public channel

The missing indexes /should/ be normal – I believe that code path is triggered during upgrade when they are created if they don’t already exist. I admin I’m not sure where fce_fileid_idx comes from. Is this database used exclusively by Mattermost?

I remain mystified by the original error, however. The upsert code is designed to try to update if the row already exists, and only then will it insert. Does this happen for every public channel you attempt to create? Do you have a master/replica database setup, or just a single database node?

You can rebuild the PublicChannels table from scratch. I always recommend making a backup first!

        TRUNCATE PublicChannels;

		INSERT INTO PublicChannels
		    (Id, DeleteAt, TeamId, DisplayName, Name, Header, Purpose)
		SELECT
		    c.Id, c.DeleteAt, c.TeamId, c.DisplayName, c.Name, c.Header, c.Purpose
		FROM
		    Channels c
		LEFT JOIN
		    PublicChannels pc ON (pc.Id = c.Id)
		WHERE
		    c.Type = 'O'
		AND pc.Id IS NULL