Reputation: 1029
I am using Postgres for a production system, and I would like to be able to connect to this database remotely to integrate the information with other systems.
My configuration looks classic like follows :
ALLOWED_HOSTS = ['myipgoeshere', 'mydomainnamegoeshere']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'dbname',
'USER': 'dbuser',
'PASSWORD': 'dbpassword',
'HOST': 'localhost'
}
}
Now, if I want to connect to this database from another machine what should I use as hostname on that machine ?
I need to provide information about
Host
Database
Port
User
Password
In my config, host is localhost, but I cannot use this as remote hostname, should we use the IP address instead ? Also will the port be the default postgres one?
Upvotes: 0
Views: 1585
Reputation: 1029
I fixed the issues by adding the IP in the postgress config file which has localhost by default, and after I started using IP in the django config
Upvotes: 0
Reputation: 15652
You can make the "HOST"
like the usual host in a URL, for example a domain name or IP address.
To specify the port, you can add a field called "PORT"
to your database config. The default port for Postgres is 5432
, but can be any valid port.
For example:
DATABASES = {
'default': {
# ...
'HOST': 'mydatabasehost.com', # e.g. or 192.168.0.10
'PORT': '5432',
}
}
Upvotes: 1