Skip to content

Instantly share code, notes, and snippets.

@ismarsantos
Last active April 29, 2024 23:57
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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
@jfeng702
Copy link

awesome thanks

@dotland
Copy link

dotland commented Mar 4, 2022

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

@davik1000
Copy link

davik1000 commented Aug 17, 2023

This worked for me. Thank you.

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

@machiobrian
Copy link

Perfect!

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

@vrrayz
Copy link

vrrayz commented Apr 29, 2024

psql -U yourusername -h 127.0.0.1 postgres

This worked for me. thanks. One quick question. if i am able to do this then i guess i won't be needing pgAdmin?

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