With pgAdmin you can manage PostgreSQL database servers, from version 9.2 using an intuitive and powerful web interface.
Having completed installation of PostgreSQL database server on Ubuntu, proceed to install and initiate pgAdmin4 on the system.
Step 1: Add pgAdmin4 repository toUbuntu 22.04|20.04|18.04
E: Package 'pgadmin4' has no installation candidate
E: Unable to locate package pgadmin4-apache2
The issue arises because the repository for pgadmin has not been added to your local machine. To solve the issue, do the following below;
Note: This should work in Ubuntu 16.04 (Xenial), Ubuntu 18.04 (Bionic), Ubuntu 19.10 (Eoan), Ubuntu 20.04 (Focal), Debian 9 (Stretch) and Debian 10 (Buster)
Install the public key for the repository (if not done previously):$ curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add$ sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
Create the repository configuration file:
Install pgAdmin (for both desktop and web modes):
$ sudo apt install pgadmin4
Install pgAdmin (for desktop mode only):
$ sudo apt install pgadmin4-desktop
Install pgAdmin (for web mode only):
$ sudo apt install pgadmin4-web
You can configure the webserver, if you installed pgadmin for web mode:
$ sudo /usr/pgadmin4/bin/setup-web.sh
Open your browser and http://[ServerIP_or_domain]/pgadmin4.In this step, we will look at how to configure Postgres to accept external connections. To begin, open the configuration file with your preferred editor:
# nano /etc/postgresql/10/main/postgresql.conf
Look for this line in the file:
#listen_addresses = 'localhost'
Uncomment, and change the value to '*'
, this will allow Postgres connections from anyone.
listen_addresses = '*'
Save and exit the file. Next, modify pg_hba.conf
to also allow connections from everyone. Open the file with your preferred editor:
# nano /etc/postgresql/10/main/pg_hba.conf
Modify this section:
# IPv4 local connections:
host all all 127.0.0.1/32 md5
To this:
# IPv4 local connections:
host all all 0.0.0.0/0 md5
This file stores the client authentication, each record specifies an IP address range, database name, username, and authentication method. In our case, we are granting all database users access to all databases with any IP address range, thus, letting any IP address connect. Save and exit the file. Next, allow port 5432
through the firewall by executing:
# sudo ufw allow 5432/tcp
Finally, restart Postgres to apply all the changes you have made to its configuration by running:
$ sudo systemctl restart postgresql
Connect to Postgres remotely
In this step, you will be connecting to your server from an external machine. Connect to the remote Postgres database by running:
$ psql -h {server_ip} -d usersDB -U Sammy
Where {server_ip}
is your server IP address, you will get a prompt to type your user password, if the credentials match you’ll be logged into the Postgres shell for cleopatra
and database egypt
.
Note: If you still cannot connect, you can reset your postgres user's password NOT linux default user
$ sudo -u postgres psql postgres
postgress# \password postgres
Enter new password
Then use this new password to connect your pgAdmin4 using
postgres as Maintenance database
postgres as username
then new password
No comments:
Post a Comment