/
How to change the domain in the database

How to change the domain in the database

If your database contains the wrong domain, the Application will produce a 400 error on every call (“Invalid Host“)

There are multiple methods to change the domain name in the database to fix the problem.

1. Using DB management tools like:

PgAdmin or DBeaver

 

Once connected to the Database find and open the table django_site . Edit the domain field and set the domain name.

 

2. Using the command line:

Connect to the DB server via SSH. Connect to the psql CLI utility by running the following command:
$ psql
Once connected list the available Schemes
postgres-# \l

To establish a connection to the Schema
\c kurl

To check the domain and its ID in the database run this query:

select * from django_site;

To update the domain name(myDomain.xxx) run this query:

UPDATE public.django_site SET "domain"='my-new-domain.xxx' WHERE id=2;

 

3. Using the application to connect to the database and change the domain name

You can change the domain name by establishing a connection from the button3D pod(container) to the database. To achieve that you would need to do the following:

  1. SSH to the server where the application is running

  2. To find the pod(container) name of button3d you need to do the following
    For Kurl.sh deployments:
    run kubectl get pods and copy the name of button3d pod

  • execute kubectl exec -i -t $(kubectl get pods | grep "button3d" | cut -d" " -f1) -- sh and you should see something like this:

    user@hostname:~$ kubectl exec -i -t $(kubectl get pods | grep "button3d" | cut -d" " -f1) -- sh /var/www/django $
  • To connect to the database run /bin/entry ./manage.py dbshell

    hgr@kurl:~$ kubectl exec -i -t $(kubectl get pods | grep "button3d" | cut -d" " -f1) -- sh /var/www/django $ /bin/entry.sh ./manage.py dbshell psql (11.9, server 12.4 (Ubuntu 12.4-1.pgdg18.04+1)) WARNING: psql major version 11, server major version 12. Some psql features might not work. Type "help" for help. 3yourmind=#
  • To find the domains in the DB run the following query: select * from django_site;

    3yourmind=# select * from django_site; id | domain | name ----+-------------+------------- 1 | example.com | example.com 2 | myDomain.xxx | My Domain (2 rows) 3yourmind=#
  • To change the domain run the following:

    UPDATE public.django_site SET "domain"='my-new-domain.xxx' WHERE id=2;
  • You should see the new domain now:

    3yourmind=# UPDATE public.django_site SET "domain"='my-new-domain.xxx' WHERE id=2; UPDATE 1 3yourmind=# select * from django_site; id | domain | name ----+-------------------+------------- 1 | example.com | example.com 2 | my-new-domain.xxx | My Domain (2 rows) 3yourmind=#

Related content