Reputation: 61
How to connect live Heroku postgress with my local server. Is there is any way to back up the Heroku database?
How is a database connection in Heroku production done?
Here's is my local.py
import dj_database_url
from .base import *
ROOT_URL = 'http://localhost:8000'
ALLOWED_HOSTS = ['localhost:8000']
SECURE_SSL_REDIRECT = False
# SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
DEBUG = True
INSTALLED_APPS.extend([
'collectfast',
])
INSTALLED_APPS.extend([
'django.contrib.staticfiles',
# 'djcelery',
])
DATABASES = {
'default': dj_database_url.config()
}
print(DATABASE_URL)
# AWS and S3 settings
AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY = ''
AWS_STORAGE_BUCKET_NAME = 'jagah-production'
AWS_QUERYSTRING_AUTH = False
AWS_PRELOAD_METADATA = True
# Static files settings
#STATICFILES_STORAGE = ''
#STATIC_S3_PATH = 'static'
#STATIC_ROOT = '/%s/' % STATIC_S3_PATH
#STATIC_URL = '' % AWS_STORAGE_BUCKET_NAME
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
Upvotes: 1
Views: 235
Reputation: 29977
From Heroku's documentation:
In addition to being available to the Heroku runtime, Heroku Postgres databases can be accessed directly by clients running on your local computer or elsewhere.
All connections require SSL: sslmode=require.
You can retrieve the PG connection string in one of two ways. heroku pg:credentials is discussed above:
$ heroku pg:credentials DATABASE Connection info string: "dbname=dee932clc3mg8h host=ec2-123-73-145-214.compute-1.amazonaws.com port=6212 user=user3121 password=98kd8a9 sslmode=require" Also, the
connection string is exposed as a config var for your app:
$ heroku config | grep HEROKU_POSTGRESQL HEROKU_POSTGRESQL_YELLOW_URL: postgres://user3123:[email protected]:6212/db982398
Upvotes: 1