At this time of writing, pgAdmin4 is not available for installation on Ubuntu 20.04, due to an unresolved Python dependency. Until this is solved, or in case you want to run pgAdmin from a Docker container, here’s what worked for me. This assumes you already have Docker installed in your Ubuntu.
docker pull dpage/pgadmin4 to pull the image on your computer.
Next, I added the following command to my
~/.bash_aliases so I can quickly run the container:
alias pgadmin-boot='docker run --add-host=database:YOUR_LOCAL_IPV4_ADDRESS -p 5050:80 -e "PGADMIN_DEFAULT_EMAIL=YOUR_PGADMIN_LOGIN_EMAIL" -e "PGADMIN_DEFAULT_PASSWORD=YOUR_PGADMIN_LOGIN_PASS" -d dpage/pgadmin4'
YOUR_LOCAL_IPV4_ADDRESS is the IP address of your computer on the local area network, assuming Postgres is running from your local machine.
Next, start pgAdmin by running
pgadmin-boot or the command above. You may need to restart your terminal so that the alias is loaded.
If everything went well until this point, you should be able to access pgAdmin4 at
http://localhost:5050/browser/ and log in with the email and password you specified in the command above.
Next, from the ‘Quick Links’ section on the pgAdmin dashboard, you can add a new server. For the hostname use
database since we defined that earlier in the command above. The port is most likely
5432. The username is most likely
postgres. The password is something you should know, otherwise see this comment on StackOverflow how to reset your postgres password. If you try to add the new server, you will most likely get an error notice about Postgres complaining about an IP not having access. That is the IP of your running pgAdmin docker container. Copy that IP, in my case it was
172.17.0.2. Next, find your
pg_hba.conf file. To do that, you can run the following commands:
dragos@dragos-pc:~$ sudo -u postgres psql
[sudo] password for dragos:
psql (12.2 (Ubuntu 12.2-4))
Type "help" for help.
postgres=# SHOW hba_file;
You will need to edit the configuration file to add the docker IP address as trusted:
sudo nano /etc/postgresql/12/main/pg_hba.conf and add this line
host all all 172.17.0.2/24 trust to the ‘# IPv4 local connections:’ block. Restart postgres
sudo service postgres restart.
Now if you try to add the server in pgAdmin, it should succeed.
If you still can’t connect to the Postgres server, you may need to let Postgres know that it can accept connections from address other than ‘localhost’. To do that,
sudo nano /etc/postgresql/12/main/postgresql.conf and then find and uncomment the config for
listen_addresses amd add your
YOUR_LOCAL_IPV4_ADDRESS from earlier. It should look like this:
listen_addresses = 'localhost,192.168.0.11'.
Hope this helps!