Host not exists when trying to use PG to store the chat

Hi!

I was trying to follow this video:

Which runs this repo: GitHub - n8n-io/self-hosted-ai-starter-kit: The Self-hosted AI Starter Kit is an open-source template that quickly sets up a local AI environment. Curated by n8n, it provides essential tools for creating secure, self-hosted AI workflows.

The video shows we only need to perform this change:
ports:
- 5432:5432

To then be able to use the n8n database to store data.

You can use it and load everything, all fine, until you reach the step to configure a PG connection.

The issue is simple, I was not able to connect to any PG from n8n… Just create any piece which need PG and set the connection, the host never exists.

I’m out of ideas, PG works fine, n8n works fine, I tried the next things:

  • Change the ports
  • Set the services to the same docker network
  • Set name to the services to use the name as hostname (which have worked to me in other dockers), no idea why don’t works here
  • Add “host.docker.internal:host-gateway” as extra_hosts

I’m not using SSL nor Tunnel, I have tested this in Linux and Mac…

Any idea what is failing?

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Welcome to the community @latot !

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.

Make sure that you have removed any sensitive information from your workflow and include dummy or pinned data with it!


It all comes down to undestanding how Docker works. For n8n container to be able to connect to the other container (here postgres) both have to be on the same network. If they are (which they should if you used the same docker-compose.yml file) you can connect to Posgres by referencing the host by the container name.

Here’s an example.

I have this set up in the configuration file in relation to postgres

  postgres:
    image: postgres:16-alpine
    networks: ['demo']
    container_name: postgres-ai-kit
    restart: unless-stopped
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
    volumes:
      - postgres_storage:/var/lib/postgresql/data

Note I gave the container a name “postgres-ai-kit”. Also note that connecting to Postgres relies on the variables set already, namely POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB. Make sure those are set (with their values) in .env file in the root folder of the repository.

Now the credentials could be set up like this

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.