0

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?

2 Answers 2

1

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',
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, changing 'localhost' in the settings with IP address is breaking the system (Internal Server Error 500)
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.