pgAdmin 4 - LucianCumpata/DevOps GitHub Wiki
- How to connect to a postgresql database in linux through pgAdmin 4?
We assume that pgAdmin is installed on a Windows 10 host and postgresql db on a linux/ubuntu VM.
We also assume that the postgresql is installed with default settings from the Vagrant file with some of the settings defined below.
In vagrant file I configured an IP address for the VM:
config.vm.network :private_network, ip: "192.168.68.8"
and also forwarded port 5432:
config.vm.network :forwarded_port, guest:5432, host:5432
We'll reach the VM on 192.168.68.8
Edit the pg_hba.conf file located in /etc/postgresql/<version_number>/main directory
(example: /etc/postgresql/9.5/main/pg_hba.conf)
and add the following line (number of spaces doesn't matter)
host all all 192.168.68.8/24 md5
AND UNCOMMENT the last 3 lines beginning with local replication postgres peer
Then we'll edit the postgresql.conf file located in /etc/postgresql/<version_number>/main directory
and change the following line under the "# - Connection Settings -"
to
listen_addresses = '*'
Don't forget to delete the '#' at the beginning if it exists!
Also don't forget to set a password to the postgres user!
After the file changes, you must restart postgresql by typing $ sudo service postgresql restart, (Make sure to logout from postgres user by using Ctrl + d before restarting).
Now launch pgAdmin 4 from your host machine (eg. Windows 10). It will open in a browser. Click on Add New Server
Type the name, doesn't matter. Then in Connection tab, enter the VM IP address defined earlier: 192.168.68.8
Port: 5432 (it's the default one). Leave the username and password (if you didn't add a password) and click save. It should automatically connect to the database.