Skip to main content
added 96 characters in body
Source Link

I have two devices:

  • HOST: a Windows device, on which I have installed a Windows Subsystem for Linux.
  • CLIENT: a Linux device.

I have then taken the following steps.

  1. I have installed Postgres within the HOST subsystem.
  2. I have created a database on HOST, with some test data.
  3. I have made this database remotely accessible with a script. (See below.)
  4. I have installed PG Admin 4 on CLIENT.
  5. I have attempted to connect to the database on CLIENT, using PG Admin and the usual IP address of the HOST device. This gives me the error: failed: FATAL: role "postgis_user" does not exist. (The string postgis_user is the username corresponding to the database in question.)
  6. I have also tried connecting with some other IP addresses, such as the one which HOST spits out in response to the command wsl hostname -i. For each address I've tried, PG Admin gives me a timeout error.

Some other things to note:

  • If I try the steps 1-5, but with two Linux devices, I can connect.
  • I have made sure that the PostgreSQL service is up on the HOST subsystem by running sudo service postgresql start.
  • I'm running WSL2, and my Linux distribution is Ubuntu (on both the subsystem and on CLIENT).

Any ideas as to where I'm going wrong?


The script I used for making my database remotely accessible:

PG_HBA_CONF_STRING_TO_ADD="host all all 0.0.0.0/0 md5"
PG_CONF_STRING_TO_ADD="# Allow remote connections.\n listen_addresses = '*'"

path_to_pg_hba_conf="/etc/postgresql/$pgres_version/main/pg_hba.conf"
path_to_pg_conf="/etc/postgresql/$pgres_version/main/postgresql.conf"

if ! sudo grep -q "$PG_HBA_CONF_STRING_TO_ADD" $path_to_pg_hba_conf; then
    echo $PG_HBA_CONF_STRING_TO_ADD | sudo tee -a $path_to_pg_hba_conf
fi
if ! sudo grep -q "$PG_CONF_STRING_TO_ADD" $path_to_pg_conf; then
    echo $PG_CONF_STRING_TO_ADD | sudo tee -a $path_to_pg_conf
fi

I have two devices:

  • HOST: a Windows device, on which I have installed a Windows Subsystem for Linux.
  • CLIENT: a Linux device.

I have then taken the following steps.

  1. I have installed Postgres within the HOST subsystem.
  2. I have created a database on HOST, with some test data.
  3. I have made this database remotely accessible with a script. (See below.)
  4. I have installed PG Admin 4 on CLIENT.
  5. I have attempted to connect to the database on CLIENT, using PG Admin and the usual IP address of the HOST device. This gives me the error: failed: FATAL: role "postgis_user" does not exist. (The string postgis_user is the username corresponding to the database in question.)
  6. I have also tried connecting with some other IP addresses, such as the one which HOST spits out in response to the command wsl hostname -i. For each address I've tried, PG Admin gives me a timeout error.

Some other things to note:

  • If I try the steps 1-5, but with two Linux devices, I can connect.
  • I have made sure that the PostgreSQL service is up on the HOST subsystem by running sudo service postgresql start.

Any ideas as to where I'm going wrong?


The script I used for making my database remotely accessible:

PG_HBA_CONF_STRING_TO_ADD="host all all 0.0.0.0/0 md5"
PG_CONF_STRING_TO_ADD="# Allow remote connections.\n listen_addresses = '*'"

path_to_pg_hba_conf="/etc/postgresql/$pgres_version/main/pg_hba.conf"
path_to_pg_conf="/etc/postgresql/$pgres_version/main/postgresql.conf"

if ! sudo grep -q "$PG_HBA_CONF_STRING_TO_ADD" $path_to_pg_hba_conf; then
    echo $PG_HBA_CONF_STRING_TO_ADD | sudo tee -a $path_to_pg_hba_conf
fi
if ! sudo grep -q "$PG_CONF_STRING_TO_ADD" $path_to_pg_conf; then
    echo $PG_CONF_STRING_TO_ADD | sudo tee -a $path_to_pg_conf
fi

I have two devices:

  • HOST: a Windows device, on which I have installed a Windows Subsystem for Linux.
  • CLIENT: a Linux device.

I have then taken the following steps.

  1. I have installed Postgres within the HOST subsystem.
  2. I have created a database on HOST, with some test data.
  3. I have made this database remotely accessible with a script. (See below.)
  4. I have installed PG Admin 4 on CLIENT.
  5. I have attempted to connect to the database on CLIENT, using PG Admin and the usual IP address of the HOST device. This gives me the error: failed: FATAL: role "postgis_user" does not exist. (The string postgis_user is the username corresponding to the database in question.)
  6. I have also tried connecting with some other IP addresses, such as the one which HOST spits out in response to the command wsl hostname -i. For each address I've tried, PG Admin gives me a timeout error.

Some other things to note:

  • If I try the steps 1-5, but with two Linux devices, I can connect.
  • I have made sure that the PostgreSQL service is up on the HOST subsystem by running sudo service postgresql start.
  • I'm running WSL2, and my Linux distribution is Ubuntu (on both the subsystem and on CLIENT).

Any ideas as to where I'm going wrong?


The script I used for making my database remotely accessible:

PG_HBA_CONF_STRING_TO_ADD="host all all 0.0.0.0/0 md5"
PG_CONF_STRING_TO_ADD="# Allow remote connections.\n listen_addresses = '*'"

path_to_pg_hba_conf="/etc/postgresql/$pgres_version/main/pg_hba.conf"
path_to_pg_conf="/etc/postgresql/$pgres_version/main/postgresql.conf"

if ! sudo grep -q "$PG_HBA_CONF_STRING_TO_ADD" $path_to_pg_hba_conf; then
    echo $PG_HBA_CONF_STRING_TO_ADD | sudo tee -a $path_to_pg_hba_conf
fi
if ! sudo grep -q "$PG_CONF_STRING_TO_ADD" $path_to_pg_conf; then
    echo $PG_CONF_STRING_TO_ADD | sudo tee -a $path_to_pg_conf
fi
Source Link

Connecting to a Postgres database, hosted within a Windows Subsystem for Linux, from a separate device

I have two devices:

  • HOST: a Windows device, on which I have installed a Windows Subsystem for Linux.
  • CLIENT: a Linux device.

I have then taken the following steps.

  1. I have installed Postgres within the HOST subsystem.
  2. I have created a database on HOST, with some test data.
  3. I have made this database remotely accessible with a script. (See below.)
  4. I have installed PG Admin 4 on CLIENT.
  5. I have attempted to connect to the database on CLIENT, using PG Admin and the usual IP address of the HOST device. This gives me the error: failed: FATAL: role "postgis_user" does not exist. (The string postgis_user is the username corresponding to the database in question.)
  6. I have also tried connecting with some other IP addresses, such as the one which HOST spits out in response to the command wsl hostname -i. For each address I've tried, PG Admin gives me a timeout error.

Some other things to note:

  • If I try the steps 1-5, but with two Linux devices, I can connect.
  • I have made sure that the PostgreSQL service is up on the HOST subsystem by running sudo service postgresql start.

Any ideas as to where I'm going wrong?


The script I used for making my database remotely accessible:

PG_HBA_CONF_STRING_TO_ADD="host all all 0.0.0.0/0 md5"
PG_CONF_STRING_TO_ADD="# Allow remote connections.\n listen_addresses = '*'"

path_to_pg_hba_conf="/etc/postgresql/$pgres_version/main/pg_hba.conf"
path_to_pg_conf="/etc/postgresql/$pgres_version/main/postgresql.conf"

if ! sudo grep -q "$PG_HBA_CONF_STRING_TO_ADD" $path_to_pg_hba_conf; then
    echo $PG_HBA_CONF_STRING_TO_ADD | sudo tee -a $path_to_pg_hba_conf
fi
if ! sudo grep -q "$PG_CONF_STRING_TO_ADD" $path_to_pg_conf; then
    echo $PG_CONF_STRING_TO_ADD | sudo tee -a $path_to_pg_conf
fi