R
RailwayNahasco

Postgres Database private url, is it faster and how to use it?

I have a Django rest framework setup with postgress db and it seems the connection is slow. I noticed there is a database private url and i wonder if this is a faster connection. If it is how can I configure it in my project? I read the doc article about private networking but I am new here and couldnt really understand how to do it. Any help is greatly appreciated. Thanks.
Solution:
can you add a 3 second sleep to your start command
P
Percy44d ago
Project ID: 643c9962-5fa0-449c-82e0-67b30f66c552
N
Nahasco44d ago
643c9962-5fa0-449c-82e0-67b30f66c552
B
Brody43d ago
what environment variables do you currently use in your database configuration in the settings.py file?
N
Nahasco43d ago
I previously used to parse the DATABASE URL thats in my env variables. But I tried today to specify the fields such as PG_HOST, user, password, etc.. but I received the same results. DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql", "NAME": os.environ["PGDATABASE"], "USER": os.environ["PGUSER"], "HOST": os.environ["PGHOST"], "PASSWORD": os.environ["PGPASSWORD"], "PORT": os.environ["PGPORT"], } }
B
Brody43d ago
can you show me the code you used to parse those options from the url environment variable, if we can get that method working I think it would be the easiest
N
Nahasco43d ago
Sure
db_url = os.environ["DATABASE_URL"]
DATABASES = {"default": dj_database_url.parse(f"{db_url}")}
db_url = os.environ["DATABASE_URL"]
DATABASES = {"default": dj_database_url.parse(f"{db_url}")}
B
Brody43d ago
why not just
db_url = os.environ["DATABASE_URL"]
DATABASES = {"default": dj_database_url.parse(db_url)}
db_url = os.environ["DATABASE_URL"]
DATABASES = {"default": dj_database_url.parse(db_url)}
N
Nahasco43d ago
Right, no idea why I did it they way I did
B
Brody43d ago
and what is the DATABASE_URL set to?
N
Nahasco43d ago
The postgres DATABASE_URL variable from postgres
B
Brody42d ago
it should be set to ${{Postgres.DATABASE_PRIVATE_URL}}
N
Nahasco42d ago
i tried that but it caused connection issues django.db.utils.OperationalError: could not translate host name "postgres-9l4v.railway.internal" to address: Name or service not known
B
Brody42d ago
okay is this a nixpacks or a dockerfile deployment
N
Nahasco41d ago
nixpacks
Solution
B
Brody41d ago
can you add a 3 second sleep to your start command
N
Nahasco41d ago
how can i do that?
B
Brody41d ago
what's your current start command and where is it defined?
N
Nahasco41d ago
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "python manage.py migrate && python manage.py collectstatic --noinput && gunicorn --timeout 500 tibian_backend.wsgi",
"restartPolicyType": "NEVER",
"restartPolicyMaxRetries": 10
}
}
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "python manage.py migrate && python manage.py collectstatic --noinput && gunicorn --timeout 500 tibian_backend.wsgi",
"restartPolicyType": "NEVER",
"restartPolicyMaxRetries": 10
}
}
railway.json at home dir
B
Brody41d ago
change to
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "sleep 3 && python manage.py migrate && python manage.py collectstatic --noinput && gunicorn --timeout 500 tibian_backend.wsgi",
"restartPolicyType": "NEVER",
"restartPolicyMaxRetries": 10
}
}
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "sleep 3 && python manage.py migrate && python manage.py collectstatic --noinput && gunicorn --timeout 500 tibian_backend.wsgi",
"restartPolicyType": "NEVER",
"restartPolicyMaxRetries": 10
}
}
N
Nahasco41d ago
ok ill test that thanks for helping so far.. ok this error is weird django.core.exceptions.ImproperlyConfigured: The database name 'railwaypostgresql://postgres:FB-2C-FgdaFF21FGDa5fEBFE43-ecC-D@postgres-9l4v.railway.internal:5432/railway' (105 characters) is longer than PostgreSQL's limit of 63 characters. Supply a shorter NAME in settings.DATABASES. I think the env var arent correct ill fix that ok it seems to be working well
B
Brody41d ago
awesome
N
Nahasco41d ago
why is that, may you explain?
B
Brody41d ago
why the 3 second sleep is needed?
N
Nahasco41d ago
yes, and why is it not needed in the normal db url
B
Brody41d ago
the private network's dns resolver is not available for the first 3 or so seconds
N
Nahasco41d ago
Oh would have never figured that on my own thank you! i really appreciate your help
B
Brody41d ago
happy to help!
Want results from more Discord servers?
Add your server
More Posts
umami deployment fails since migration of railwayHi there, I hope you can help me. I am not too well with backend (database, docker, etc) programminIs Go 1.22 supported yet?I remember getting deployment issues when trying to support Go 1.22 in the past. I assume it's a matIs Go 1.22 supported yet?I remember getting deployment issues when trying to support Go 1.22 in the past. I assume it's a matmy plan is 5$My plan is 5$ why I pay now 51$. ?? Please deactivate my account I don't need this server in which eFile too large on Gitlab CI/CDHi, i'm trying to add a CI/CD to my project but the deploy part always fail saying ```File too largeCan't find my repo on railwayIt was recently migrated to be a organization repo that I have admin access to. How do I deploy baseDeploying to Railway from Gitlab CI/CDwhere to get project token from project serviceApp Crashed - Resource temporarily unavailableMy backend nodejs app crashed multiple times today. could not find the root cause. this has not hapDatabase server does not connectGood afternoon, I have already made all the connections with the postgreSQL database server but whenDeploy logs stopped appearing after a manual redeployHi, I have a project running several services. Deploy logs for one of the services randomly stopped ENOTFOUND redis.railway.internalFirst time using railway. I'm on team plan which says it supports private networking. I have a simplError: libuuid.so.1: cannot open shared object file: No such file or directoryGetting this error with puppeteer on Railway. ``` node:internal/modules/cjs/loader:1239 return pro"Error: connection already closed."I keep getting this error message when I attempt to update a user in my PostgreSQL database. I do noUnable to update Variables in App. (First Update after Migration)Hey Guys, my App tries to connect to the old containers of my postgres and redis. I checked the variImage Storagehello everyone, can I use Postgresql to store the images which my users upload in django-project?Setup Cloudflare Proxy1. Clicked "custom domain". 2. Railway pops up a CNAME for me to add to Cloudflare. 3. Add CNAME recDirectus: impossible to update or to run the old versionProject ID : 9be34f5b-fa35-49c1-83c5-f0fbd245db9b Template : https://github.com/kadumedim/directus-sCSV files in storage/app/data/csv not accessible?Hello, I've setup a laravel api on railway. I have a seeder that tries to load csv files from the I have not touched my project in several weeks but at midnight railway reverted to a very old versioI'm very confused it looks like my project was deployed last night, although I have not touched it iI can't add DNS from GoDaddy to RailwayThey recommend me to change the server name...