Connect to an external database server¶
-
On the existing database server, create a new database for Mathesar to store its metadata.
-
Configure the
DJANGO_DATABASE_URL
environment variable to point to the database you just created. -
(Optional) For Docker Compose related installations, you may disable Mathesar’s default database server if you like.
Connect to a database server running on the host¶
This content is related to Mathesar running in Docker related environments. This is applicable for the Guided installation method, Docker Compose installation method, and Docker installation method.
If you’re running Mathesar in a Docker related environment, and your database server runs on the host machine, you will not be able to connect to it using localhost:<db_port>
, since localhost
would refer to the Docker environment and not to the host.
You can try using host.docker.internal
instead of localhost
. Below are detailed instructions to expose the database on your host to the Docker instance.
Prerequisites¶
-
Locate
postgresql.conf
&pg_hba.conf
file on the host machine. This can be located usingpsql
shell by executing the following respectively.and
1. Create the necessary network bridges using docker-compose -
Find the appropriate IP addresses of the
docker0
interface and themathesar_default
interface. This can be found by exectuting the following in the host’s terminal. -
Stop Mathesar if it’s already running.
Steps¶
-
Edit the
postgresql.conf
file and add the IP ofdocker0
interface in thelisten_addresses
setting. Uncomment this line if it’s conmmented out. -
Modify the
pg_hba.conf
file and grant access to themathesar_default
interface. Add the following line at the bottom of the file: -
Restart postgres:
-
Set the value of
MATHESAR_DATABASES
environment variable to the following: -
If your Mathesar installation is Docker Compose based, add an extra host for the prod container in the
docker-compose.yml
file: -
Start Mathesar.
You should have a successful connection to the host database now!