Skip to content

[bug] Unable to upgrade to v3 #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gaeljw opened this issue Apr 4, 2025 · 7 comments
Open

[bug] Unable to upgrade to v3 #263

gaeljw opened this issue Apr 4, 2025 · 7 comments
Labels
bug Something isn't working triage needed

Comments

@gaeljw
Copy link

gaeljw commented Apr 4, 2025

Describe the bug

Hello folks,

I just tried to upgrade to v3 (from 2.8.4) following https://docs.sourcebot.dev/self-hosting/upgrade/v2-to-v3-guide but upon startup of the v3, I've got errors related to Postgres.

I haven't had time to investigate yet, this may be a permission issue on our end.

In doubt, I thought I'd share it :)

Logs during startup:

[Info] Waiting for the database to be ready...
postgres: could not access the server configuration file "/data/.sourcebot/db/postgresql.conf": No such file or directory
localhost:5432 - no response
[Info] Waiting for the database to be ready...
localhost:5432 - no response
[Info] Waiting for the database to be ready...
localhost:5432 - no response
[Info] Waiting for the database to be ready...
localhost:5432 - no response
[Info] Waiting for the database to be ready...
localhost:5432 - no response

To reproduce

N/A

Sourcebot deployment information

Sourcebot version (e.g. v3.0.1): v3.0.2

Additional information

No response

@gaeljw gaeljw added bug Something isn't working triage needed labels Apr 4, 2025
@msukkari
Copy link
Contributor

msukkari commented Apr 4, 2025

The one time I've seen this happen is when postgres is unable to initialize on the initial startup. What is the setup you have with mounting the disk to the container?

@gaeljw
Copy link
Author

gaeljw commented Apr 7, 2025

What is the setup you have with mounting the disk to the container?

It's a regular volume mount through Kubernetes. Volume is NFS though. I've had issues in the past with NFS volumes and Postgres, so that could be it. But there's not much logs for me to investigate.

I'll give it locally on my laptop to troubleshoot

@gaeljw
Copy link
Author

gaeljw commented Apr 7, 2025

This definitely look's like a permission issue.

On my laptop, I'm able to make it work but I see that the postgres folder is owned by another user:

ll .sourcebot   
total 16K
drwx------. 19   100069   100069 4,0K  7 avril 13:06 db
drwxr-xr-x.  2 gael gael 4,0K  7 avril 13:06 index
drwxr-xr-x.  2 gael gael 4,0K  7 avril 13:07 redis
drwxr-xr-x.  3 gael gael 4,0K  7 avril 13:06 repos

I know NFS is a bit crappy for such things. I've had a look at another setup where we have a NFS volume mount for a Postgres container and we've had to add a couple of configurations to make it work (runAsUser and runAsGroup on the postgres container with same uid than the owner of NFS files).

Thus I guess it's something related to our infra rather than an issue with Sourcebot.

But I would expect Sourcebot to raise a more explicit error that it's an issue with permissions.

That being said, for now, I don't have a workaround on my end to make it work. I'll probably switch to another type of volume anyway.

@gaeljw
Copy link
Author

gaeljw commented Apr 7, 2025

It's the following line that raises the error https://github.com/sourcebot-dev/sourcebot/blob/bf8b28252d1aacdf9d54e0f5feb8f8994ecb9006/entrypoint.sh#L133C5-L133C52

Even after giving all possible rights to the folder. From inside the container:

/app # su postgres -c "postgres -D $DATABASE_DATA_DIR"
postgres: could not access the server configuration file "/data/.sourcebot/db/postgresql.conf": No such file or directory
/app # ls -al /data/.sourcebot/db/
total 8
drwxrwxrwx    2 postgres postgres      4096 Apr  7 11:15 .
drwxr-xr-x    4 nobody   nobody        4096 Apr  7 11:15 ..

@msukkari
Copy link
Contributor

Thanks for investigating! Yeah seems like the internal postgres deployment doesn't like certain volumes. I don't have too much experience with postgres, so not exactly sure why without further investiagation

We should definitely add a better error message when this happens. In the meantime, could you try a different mount? Alternatively, you could spin up an external postgres server and connect sourcebot to it using DATABASE_URL

@belaw
Copy link

belaw commented Apr 14, 2025

I've had this issue as well and have found a workaround.
The issue is that Sourcebot can't chown the DB directory:

[Info] Initializing database at /data/.sourcebot/db...
chown: /data/.sourcebot/db: Operation not permitted

This might be related to NFS root squashing? No idea.
This message will only be logged in the first container Kubernetes creates, which immediately crashes and gets replaced. If you don't have a log aggregation system, it is very easy to miss

Workaround

  1. Connect to your NFS server and navigate to the .sourcebot directory of the container and chown the db directory:
chown 70:70 $path_to_db_directory # 70 = postgres
  1. Open a shell inside the Sourcebot container and execute the following command:
su postgres -c "initdb -D $DATABASE_DATA_DIR"
  1. Restart the deployment and it should work.

The line su postgres -c "initdb -D $DATABASE_DATA_DIR" is taken directly from the entrypoint.sh script, it just gets skipped if the db directory already exists.

@msukkari
Copy link
Contributor

Thanks for finding a workaround @belaw ! We'll try to get this logic backed into the script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage needed
Projects
None yet
Development

No branches or pull requests

3 participants