To access a PostgreSQL database installed on an Ubuntu WSL2 machine from pgAdmin on Windows 11, follow these steps:
-
Install the PostgreSQL ODBC Driver on Windows:
- Download the PostgreSQL ODBC Driver from the official PostgreSQL website (https://www.postgresql.org/download/windows/)
- Install the driver on your Windows machine
-
Configure the ODBC Data Source:
- Open the ODBC Data Source Administrator by searching for "ODBC Data Source Administrator" in the Windows search bar
- Click on the "System DSN" tab
- Click on "Add" to create a new data source
- Select "PostgreSQL" as the driver, and click "Finish"
- Fill in the connection details:
- Data Source Name: Enter a name for your data source
- Hostname: Enter the IP address or hostname of your WSL2 machine
- Port: Enter the PostgreSQL port number (default is 5432)
- Database: Enter the name of the database you want to connect to
- Username: Enter your PostgreSQL username
- Password: Enter your PostgreSQL password
- Click "Test" to test the connection, and if successful, click "Finish"
-
Connect to the Database in pgAdmin:
- Open pgAdmin
- In the "Servers" section, right-click "Server Groups" and select "New Server Group"
- Enter a name for the server group, and click "Add"
- In the "Servers" section, right-click the new server group, and select "New Server"
- Select "PostgreSQL" as the server type, and click "Next"
- Fill in the connection details:
- Name: Enter a name for the server
- Hostname: Enter the IP address or hostname of your WSL2 machine
- Port: Enter the PostgreSQL port number (default is 5432)
- Maintenance database: Leave this blank if you don't have a separate maintenance database
- Login timeout: Enter the desired login timeout in seconds
- Click "Options" and fill in the following:
- ODBC Data Source: Select the data source you created earlier
- Username: Enter your PostgreSQL username
- Password: Enter your PostgreSQL password
- Click "Connect" to connect to the database
Now you should be able to access your PostgreSQL database installed on your Ubuntu WSL2 machine from pgAdmin on Windows 11.
References:
- PostgreSQL ODBC Driver for Windows (https://www.postgresql.org/download/windows/)
- pgAdmin (https://www.pgadmin.org/)