Railway - problems with connecting to postgres in production
1
vote
0
answers
608
views
**Django worked perfectly locally, but had errors in production (I was using the same postgres DB and configuration).**
**Django server, hosted on Railway gave me this:**
**Newtorking tab in Postgres settings on Railway:**
**Postgres logs locally:**
**Settings:** (WORKED PERFECTLY ON A LOCAL MACHINE WITH THIS IN-PROD DATABASE AND SAVED DATA)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', //tried django.db.backends.postgresql, not working
'NAME': os.getenv('DB_NAME'),
'USER': os.getenv('DB_USER'),
'PASSWORD': os.getenv('DB_PASSWORD'),
'HOST': os.getenv('DB_HOST'),
'PORT': os.getenv('DB_PORT'),
}
}
DATABASE_URL = os.getenv('DATABASE_URL')
**.env:** (everything in {{}} is a variable)
DATABASE_PRIVATE_URL={{DATABASE_PRIVATE_URL}} //not using this
DATABASE_URL={{DATABASE_URL}}
DB_HOST=viaduct.proxy.rlwy.net
DB_NAME=railway
DB_PASSWORD={{DB_PASSWORD}}
DB_PORT=19232
DB_USER=postgres
SECRET_KEY={{SECRET_KEY}}
**So I did:**
@my-MBP django_project % psql -h localhost -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-----------------+----------+---------+-------+-----------------------
postgres | | UTF8 | C | C |
template0 | | UTF8 | C | C | =c/ +
| | | | | =CTc/
template1 | | UTF8 | C | C | =c/ +
| | | | | =CTc/
(3 rows)
@my-MBP django_project % psql -h localhost -d postgres
psql (14.11 (Homebrew))
Type "help" for help.
postgres=#
**And got (On Railway):**
***Django server:***
***Postgres Database:***
**Doing this locally gives me the same error that was given in production**
@my-MBP django_project % psql -h /var/run/postgresql -d postgres
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
Again, before I ran





psql -h localhost -d postgres
everything was working perfectly on a LOCAL Django server. But in production, with the same configuration and database (hosted) it was not working.
Asked by Mikheil
(11 rep)
May 8, 2024, 04:40 AM
Last activity: May 8, 2024, 01:52 PM
Last activity: May 8, 2024, 01:52 PM