Failing to connect Commento with PostgreSQL

Hello, I’m trying to connect Commento to PostgreSQL. Hopefully someone who’s reading this is familiar with what Commento is, but if not I’ll briefly explain. I’ve been transferring a blog over onto Hugo, which took a bit of learning, but is well worth the effort. I now have my own personal theme, which is nice. The only downside is that because it’s a static site generator there’s no straightforward way to integrate blog comments. Commento is one of the apps that gets you there. There is the option of connecting your site to Commento’s online database, but honestly I can’t afford to be paying a monthly fee for that as long as it’s only a small-scale enterprise, and so I’m trying to install Commento myself (and anyway I like working things out by myself).

The idea is that you create a database with PostgreSQL (which I haven’t used before, but I have used MySQL, so there’s no mystery), and then you install Commento, which is supposed to interact between the db and the website. The online instructions for installing Commento don’t say anything in particular about any required settings for the db, so I just created something completely blank:

CREATE DATABASE "commento";
CREATE USER commento-user WITH PASSWORD 'blablablapassword';
GRANT ALL PRIVILEGES ON DATABASE "commento" TO commento-user;

Then I’ve added a reverse proxy redirect from NGinX to the Commento instance, using this block of code:

location /commento {
   proxy_pass http://localhost:34567; 
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Forwarded-Proto $scheme;
}

(Insert any port there - just picking random ports for security reasons)

OK, and then I tried to follow these instructions, using Docker Compose to install the application. Before starting the installation, I configured the docker-compose.yml file. This is where I’m really not sure that I’ve got it right (I can’t see what would be wrong with the previous two settings):

version: '3'
services:
  server:
    image: registry.gitlab.com/commento/commento:latest
    ports:
      - 34567:8080
    environment:
      COMMENTO_ORIGIN: https://hugoblogtest.local/commento
      COMMENTO_PORT: 8080
      COMMENTO_POSTGRES: postgres://commento-user:blablablapassword@db:5432/commento?sslmode=disable
    depends_on:
      - db
  db:
    image: postgres
    environment:
      POSTGRES_DB: commento
      POSTGRES_USER: commento-user
      POSTGRES_PASSWORD: blablablapassword
    volumes:
      - ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
volumes:
  postgres_data_volume:

OK, and then when I run the docker-compose command:

sudo docker-compose -f docker-compose.yml up

…this happens :point_down:t3: :point_down:t3: :point_down:t3:.

sudo docker-compose -f docker-compose.yml up                                                                                                       !10187
Starting commento_db_1 ... done
Starting commento_server_1 ... done
Attaching to commento_db_1, commento_server_1
db_1      |
db_1      | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1      |
db_1      | 2024-10-01 21:39:02.998 UTC [1] LOG:  starting PostgreSQL 17.0 (Debian 17.0-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
db_1      | 2024-10-01 21:39:02.998 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1      | 2024-10-01 21:39:02.998 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1      | 2024-10-01 21:39:03.004 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1      | 2024-10-01 21:39:03.018 UTC [28] LOG:  database system was shut down at 2024-10-01 21:31:49 UTC
db_1      | 2024-10-01 21:39:03.033 UTC [1] LOG:  database system is ready to accept connections
server_1  | 2024/10/01 21:39:03 [INFO] version.go:13 versionPrint(): starting Commento
server_1  | 2024/10/01 21:39:03 [INFO] database_connect.go:20 dbConnect(): opening connection to postgres: postgres://commento-user:redacted@db:5432/commento?sslmode=disable
server_1  | 2024/10/01 21:39:03 [ERROR] database_connect.go:31 dbConnect(): cannot talk to postgres, retrying in 10 seconds (4 attempts left): pq: unknown authentication response: 10
server_1  | 2024/10/01 21:39:13 [INFO] database_connect.go:20 dbConnect(): opening connection to postgres: postgres://commento-user:redacted@db:5432/commento?sslmode=disable
server_1  | 2024/10/01 21:39:13 [ERROR] database_connect.go:31 dbConnect(): cannot talk to postgres, retrying in 10 seconds (3 attempts left): pq: unknown authentication response: 10
server_1  | 2024/10/01 21:39:23 [INFO] database_connect.go:20 dbConnect(): opening connection to postgres: postgres://commento-user:redacted@db:5432/commento?sslmode=disable
server_1  | 2024/10/01 21:39:23 [ERROR] database_connect.go:31 dbConnect(): cannot talk to postgres, retrying in 10 seconds (2 attempts left): pq: unknown authentication response: 10

Clearly failing every time. I spent a whole evening going crazy with it, going round and round in circles asking ChatGPT what was going on, but in my experience going round and round in circles with AI is worse than going round in circles by yourself! And so here I am now.

Any ideas here? I also tried deleting the database, and changing the user to the postgres superuser, with the notion that maybe Commento needs to create the database “in its own image”, but that didn’t work either.

Probably you are using latest version of Postgres wich uses scram-sha-256 for autthentication by default, but the driver Commento uses to connect to Postgres may be older.

Follow the steps in the link below to change your Postgres to use md5 instead.

https://stackoverflow.com/questions/64210167/unable-to-connect-to-postgres-db-due-to-the-authentication-type-10-is-not-suppor

1 Like

i cannot help you with the connectivity issue, but that dash in the user name makes me nervous

if you really want to use a dash, you’ll have to enclose the name in doublequotes, every time you use it, and be aware it’s case sensitive (unquoted identifiers are not)

i suggest using an underscore instead

2 Likes

Hi, and thanks. I tried following all of that, and it’s no good. After trying to change those authentication settings in the config files, and failing, I actually went back to an older VM, with an older version, where everything is done by md5, so there shouldn’t be any authentification problem. But there still is, so… I don’t know, honestly.

The thing is (and maybe I should have mentioned this previously), that this application is installed within Docker, which i didn’t know anything about before. At the moment it’s driving me nuts, and I can only assume that it’s Docker which is the problem here. The vapour trail of logs and failed connections is too long and confusing perhaps to be of any use, unless someone here really knows a lot about Docker??? Honestly, I’m just lost here!!!

Yes, unfortunately that’s not the issue here, but thanks for the warning anyway :+1:t4: :smiley: :

Analysing logs sounds like a good job for AI. You could sign up for a ChatGPT account (it’s free) then copy/paste the logs into the chat and see if it can spot anything. It doesn’t always work, but oftentimes it’ll spot something you’ve missed, or will at least be able to point you in the right direction.

With this setup Postgres should create the user itself on the first startup. There is no reason to do that manually.

I would try completely resetting the container, wiping all data, and then start it again to see if that works

docker compose down -v db
docker compose up -d

I’ve been doing that! As I said in the first post, gonig round and round and round in circles with ChatGPT. Yes, it’s great when it sees the problem nice and quickly, but actually it can be damaging when it sends you round the houses tinkering with a million things that turn out to be irrelevant :melting_face: Sometimes it does more harm than good, but anyway that’s also our responsibility as the human in the room to keep it from going off on tangents.

1 Like

So you’re saying to delete the database on Postgresql, and try creating it from Docker? I have actually tried that . I tried creating it as the postgres superuser, as I assumed that it wouldn’t give permissions to the specifically created user. Anyway, that also didn’t work. But I suppose maybe I’ll try it again at some point. I need a day or two off this anyway. My eyes are boggling!

As far as I know you don’t need to manually create any users. The Postgres docker container creates one on startup, based on the environment variables it’s passed in the compose file. That’s enough. No need to manually do anything more.