Can't attach volume to postgres db

6 months ago

I want to use postgres 17 from ghcr.io/railwayapp-templates/postgres-ssl:17
I added a new service from Docker Image

attached a volume set it to /var/lib/postgresql/data and added the required env vars

something like

PGHOST=${{RAILWAY_PRIVATE_DOMAIN}}
PGPORT=5432
PGUSER=${{POSTGRES_USER}}
PGPASSWORD=${{POSTGRES_PASSWORD}}
PGDATABASE=railway
DATABASE_URL=postgresql://${{PGUSER}}:${{POSTGRES_PASSWORD}}@${{RAILWAY_PRIVATE_DOMAIN}}:5432/${{PGDATABASE}}

and I got this issue

initdb: error: directory "/var/lib/postgresql/data" exists but is not empty initdb: detail: It contains a lost+found directory, perhaps due to it being a mount point. initdb: hint: Using a mount point directly as the data directory is not recommended. Create a subdirectory under the mount point.

Solved

5 Replies

6 months ago

Hello,

Perhaps you have forgot the PGDATA=/var/lib/postgresql/data/pgdata variable?

Best,
Brody


Status changed to Awaiting User Response Railway 6 months ago


6 months ago

Thanks, ok, now it builds, but I still can’t connect.
It shows as deployed successfully, in the Data tab, “Database Connection” keeps loading indefinitely, and when I try to use the public database URL, it also doesn’t connect.


Status changed to Awaiting Railway Response Railway 6 months ago


6 months ago

You likely have a few other misconfigurations, please link to the deployment in question.


Status changed to Awaiting User Response Railway 6 months ago


6 months ago

Per your new thread, the service link is -

https://railway.com/project/9acf2f18-e37c-4318-bd58-2cd8ccdd46c7/service/24ca2776-d752-47bc-a316-73642bb10a68/data

Please note, these UUIDs are in no way sensitive.


6 months ago

All your variables are fine, but your service was missing a TCP Proxy domain, once I added that I redeployed your Database as to have it become accessible via the newly added Proxy.

You can now access the Data tab!


Railway
BOT

a month ago

This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!

Status changed to Solved Railway 26 days ago


Can't attach volume to postgres db - Railway Help Station