apt install sudo postgresql -y
sudo -u postgres psql
CREATE DATABASE mattermost;
CREATE USER mmuser WITH PASSWORD 'mmuser-password';
GRANT ALL PRIVILEGES ON DATABASE mattermost to mmuser;
ALTER DATABASE mattermost OWNER TO mmuser;
GRANT USAGE, CREATE ON SCHEMA PUBLIC TO mmuser;
\q
sudo systemctl restart postgresql
nano /etc/postgresql/{version}/main/pg_hba.conf
Find the following lines:

local   all             all                        peer
 
host    all             all         ::1/128        ident

3. Change `peer` and `ident` to `trust`:

local   all             all                        trust
 
host    all             all         ::1/128        trust
sudo systemctl reload postgresql
psql --dbname=mattermost --username=mmuser --password