DEV Community

Cover image for How to setup PostgreSQL and DBeaver on WSL.
Maneesha Walisundera
Maneesha Walisundera

Posted on

How to setup PostgreSQL and DBeaver on WSL.

Spent a few hours trying to configure PotgreSQL and DBeaver on wsl. Hope this helps.

Installing postgresql on wsl terminal

$ sudo apt update
$ sudo apt install postgresql postgresql-contrib
$ psql --version
Enter fullscreen mode Exit fullscreen mode
  • Give it a password that we will use in Dbeaver when testing connection.

$ sudo passwd postgres

  • Restart Terminal.

  • Check status and start PostgreSQL service.

$ sudo service postgresql status
$ sudo service postgresql start
Enter fullscreen mode Exit fullscreen mode
  • You should get a prompt asking for your password.

If you didn't, then type :

$ su - postgres
$ psql
Enter fullscreen mode Exit fullscreen mode
  • After entering your password you should see this

postgres=#

  • Keep terminal open

DBeaver Setup

  • Open DBeaver after installing from here

  • Ctrl - Shift - N to make a new connection and select PostgreSQL.

  • Fill your password you entered earlier and click test connection.

DBeaver postgres pop up

  • It should ask you to download some drivers. After downloading it should be working.

Test Success

If you get an error, lets try reseting password and creating dummydb.

  • go back to your terminal \q out and
$ sudo -u postgres createuser <username>
$ sudo -u postgres createdb <dummydbname>
$ sudo -u postgres psql
Enter fullscreen mode Exit fullscreen mode
psql=# alter user postgres with encrypted password '<password>'
psql=# grant all privileges on database <dbname> to postgres 
Enter fullscreen mode Exit fullscreen mode
  • Close DBeaver and retry testing your connection.

  • If you get an connection error

sudo ufw allow 5432/tcp
# You should see "Rules updated" and/or "Rules updated (v6)"
sudo service postgresql restart
Enter fullscreen mode Exit fullscreen mode
  • Open powershell as admin wsl --shutdown

Start postgresql service and Retry connection.

Top comments (0)