Skip to content

Instantly share code, notes, and snippets.

@ismarsantos
Last active September 2, 2024 17:37
Show Gist options
  • Save ismarsantos/28b62d8a9be1ce8d21f3bd436abd21bc to your computer and use it in GitHub Desktop.
Save ismarsantos/28b62d8a9be1ce8d21f3bd436abd21bc to your computer and use it in GitHub Desktop.
Connect PgAdmin4 on WSL2 Ubuntu 20.04.3 LTS
sudo -u postgres psql -c 'SHOW config_file'
sudo nano /etc/postgresql/13/main/postgresql.conf
# uncomment line 59:
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
listen_addresses = 'localhost' # what IP address(es) to listen on;
#------------------------------------------------------------------------------
# Save file and restart
sudo service postgresql stop
sudo service postgresql start
# https://www.pgadmin.org/download/pgadmin-4-windows/
# Download it here and install it.
# In the popup Create — Server window:
# General tab: I set Name to test
# Connection tab: I set Host name/address to 127.0.0.1 (Note: some post said you can set it as localhost, but it causes errors for me)
# port:5432
# Leave maintenance database and Username as default postgres
# Password: whatever password you set up earlier for PostgreSQL in WSL 2, click Save password
@abbosjon99
Copy link

It is recommended to create a new superuser aside from postgres. The latter has a peer authentication type, which may cause an error when connecting by pgAdmin.

To create a user, run the following in the terminal.

$ su - postgres
$ createuser --interactive -P yourusername
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) y

Test it by

$ psql -U yourusername -h 127.0.0.1 postgres

THANKS:))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment