FlowiseAI / Flowise

Drag & drop UI to build your customized LLM flow
https://flowiseai.com
Apache License 2.0
31.31k stars 16.3k forks source link

Cannot connect to Postgres database when deployed, but works on the local machine #3177

Open transcendr opened 1 month ago

transcendr commented 1 month ago

Describe the bug Since upgrading to version 2.0.7 in order to get a fix for a bug related to credentials resetting, I've not been able to connect to my Postgres database when FlowWise is deployed to GCP. The environment variables are set. There's a .env file in both the docker folder and the server folder, just to be sure. This setup with these particular environment variables was working before when I had version 1.7.2 installed, deployed originally. But now after version 2.0.7, when I redeploy to GCP, there are no errors but my chat flows, credentials, etc. that are stored in the database are not retrieved (at least it appears so). They're not available and not visible in the UI.

Here are the variables that I have set associated with the database. Obviously, I've replaced the actual values with zeros. But you can see here what I actually have set:

image

Again, I want to stress that I don't see anything in the logs indicating that there's an error or issue establishing a connection with the database. So I'm not really sure what's going on. Also, if I run Flowise locally and access it on localhost, the connection appears to be established correctly because all of my chat flows and everything else that I've saved in Flow are available and can be edited. Could it be that GCP is for some reason not picking up the environment variables, or something else?

To Reproduce Clone the latest version of Flowise version 2.0.7 and add the.env file with the above structured environment variables for the database. Follow the documentation for deploying to GCP on Kubernetes. Access the application via its external IP. Create a new chat flow, and you will see that the chat flow is indeed saved. I suspect it is saved to some local database or file system, Or do any other action that would typically update the database. You should see that the connection is not established.

Expected behavior Flowise is connected to the Postgres database.

Screenshots none

Flow n/a

Setup n/a

Additional context none


transcendr commented 1 month ago

I just confirmed by rolling back to 1.7.2 it is working again with the same config vars.

HenryHengZJ commented 1 month ago

how are you installing Flowise? Docker, npx, or git?

transcendr commented 1 month ago

git clone, checking out the version tag, but deployment to GCP is via Docker.

HenryHengZJ commented 1 month ago

does it work when setting up locally? we havnet changed anything on the backend database side, so it should still be the same as before

transcendr commented 1 month ago

@HenryHengZJ yes when building and running locally there is no issue. It's only when it's deployed to GCP that it doesn't seem to connect. I have a suspicion that it has something to do with the environment variables not being picked up for it, but there are no errors in the logs related to failed db connection, etc. There's also at least some db connected (sqlite?) because I can create new entities and they persist for a little while (eventually they get cleared, probably because of the ephemeral state of the container, but it's not clear to me when GCP clears it).

HenryHengZJ commented 1 month ago

So it might be related to how GCP is picking up those env variables from Docker. Does your docker-compose.yml has the correct env variables passed in? image

transcendr commented 1 month ago

@HenryHengZJ yep, here's my docker-compose.yml

image

Yes, these were passed into my Docker Compose, but I also noticed that that particular variable is not included in my .env file. However, it has never been included in my .env file, and version 1.7.1 works without it, which when deployed to GCP does connect correctly to the database. As a note, that database path variable seems to be taken into account in the newer version because I do have persistence, but I think it's the sqlite db persisting data because it's obviously not data from my Postgres database.

Additionally, I noticed that where that database_path environment variable is referenced, in Datasource.ts, it's only referenced for SQLite and not for Postgres.

transcendr commented 3 weeks ago

Did try deploying the latest version again and am now getting connection refused error for the postgres connection now: image This error never appeared in my previous attempts, and now clearly GCP is recognizing the env variables, so that's good. Given our config, can you spot any potential issue, @HenryHengZJ ?

image