6 months ago
Hello Railway Support Team,
I am experiencing an issue where the persistent volume attached to my service is not retaining data across deployments, causing my application's database to be wiped every time I push a change.
Service Details:
Project: oren
Service: oren
Volume Mount Path: /data (also tried /app/data)
Problem Description:
My Python/Flask application is configured to store its SQLite database at /data/collections.db. However, all data (users, collections, etc.) is lost upon redeployment.
Debugging Steps Taken:
We have thoroughly debugged the application code and have confirmed the following:
The application correctly identifies when it's running on Railway and sets the database path to /data/collections.db.
The application has the necessary file system permissions to write to the /data directory.
We deployed a simple test endpoint that writes a text file with a unique ID to /data/volume_test_id.txt.
Crucially, this ID changes after every deployment. This test proves that the contents of the /data volume are being reset and are not persistent.
This behavior seems to indicate an issue with the volume's configuration or lifecycle on the platform. Could you please investigate why the data on my attached volume is not persisting as expected?
Thank you for your help.
5 Replies
6 months ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
6 months ago
Considering you have specified the correct path for you volume i.e. /data there could be couple of reasons for this behavior
1. Your application doesn't have enough permission to write to the volume. Volumes by default is mounted for root user. So go to your service variables add this variable RAILWAY_RUN_UID with the value of 0
2. Your application might me recreating the sqlite file discarding the old one.
6 months ago
Blaketiggy, did you try adding the RAILWAY_RUN_UID variable and setting its value to 0 in your service?
The permissions issue you described can be caused by how Railway mounts persistent volumes, as the root user by default. If your Docker image or runtime uses a non-root user (which is common for many Python, Node, or custom images for security), that user will not have write access to the volume, leading to errors (like you are facing)
6 months ago
@smolpaw @clashing I was really hoping this was a case of me not RTFM but I added that variable and the issue is still happening. Really thinking it might easier to just put my db somewhere else.
blaketiggy
@smolpaw @clashing I was really hoping this was a case of me not RTFM but I added that variable and the issue is still happening. Really thinking it might easier to just put my db somewhere else.
6 months ago
You could host libSQL as a service on railway itself then have your flask app connect to it.
There's a one click deploy available here: https://railway.com/deploy/p121Tx
This is better because you could scale it independently of your application. Your flask app cannot have replicas because it has a volume attached but if you were to use a db service then you can.
You could also configure backups of your sqlite db using Lightstream to incrementally sync WAL pages to an s3 bucket.