I’m trying to connect to my self hosted postgres db for the memory of an AI Agent. I’ve tried all sorts of credentials, but nothing connects to the host.
Supabase is self hosted on the same server as n8n using Coolify. I’m using the postgres password from the .env file as suggested by the Supabase docs. I’ve also tried the docker container and ip address as host - still won’t work.
The n8n and supabase docs aren’t helpful either.
Has anyone successfully managed to add memory to the AI Agent using postgres and self hosted Supabase - if so how? The hosted version of Supabase seems to be reasonably simple, but self hosted isn’t.
Hey @elliott , is you are using Docker containers for both n8n and Postgres you need to make sure they are on the same Docker network. If they are, you need to use the container IP of the Postgres DB to be able to connect n8n workflow to it.
Here’s an example
# list networks
docker network ls
>>>
NETWORK ID NAME DRIVER SCOPE
904240d34e55 bridge bridge local
a91d764483ec host host local
# I would expect the default network called "bridge" unless you created a different one yourself
docker network inspect bridge
>>>
. . .
"Containers": {
"1be555323722fc1d9290e45870f1273ea7c124d874dbb6754ff58a6832b5df75": {
"Name": "n8n",
"EndpointID": "cfc10274b088ecbf4635694565adb82c25827d620f68dcea3f90eb991440b3f3",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
},
"b49ededd3d3e8b562e52bdd2078966ce7a5d68e8609458a8d1757047d481b414": {
"Name": "postgres",
"EndpointID": "906e6c6f7697d9bd11c2f3ffcc1f70afef10e7e49bbf2031ce0af50c830dd339",
"MacAddress": "02:42:ac:11:00:03",
"IPv4Address": "172.17.0.3/16", # Postgres IP address
"IPv6Address": ""
}
},
. . .
# If both on the same network, note the container IP of Postgres
As per above example, both services - n8n and Postgres - run on the same network. The Postgres DB has the IP address 172.17.0.3 use that IP when setting up credentials in n8n.
Surely the things could get complicated. You want to make sure when apps are restarted Postgred still has the same IP address allocated.
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!
I’m not familiar with Coolify and how services are deployed there. However, if we talk about Docker containers, the containers have to be on the same network for the respective services to communicate with each other. That implies having one way or another a network that both containers can connect to.
If it happens the containers are connected to separate networks (and you have no control over it), then you would need to have the 3rd network created and connect the containers to this network (a container can be connected to many networks at the same time).
Another way is to use docker compose. It allows to run the containers in predefined configuration, which simplifies their management and ensures stable communication.