To access your PostgreSQL server database using pgAdmin, follow these steps:
By default, PostgreSQL might only be configured to accept connections from localhost
. To connect remotely using pgAdmin, you'll need to adjust some configuration files.
postgresql.conf
FileSSH into your VPS where PostgreSQL is installed.
ssh username@your_vps_ip
Open the postgresql.conf
file in a text editor (like nano
or vim
).
sudo nano /etc/postgresql/14/main/postgresql.conf
Look for the listen_addresses
setting and change it to accept connections from any IP address:
listen_addresses = '*'
localhost
. Change it to *
to allow all incoming connections, or specify a particular IP address to restrict access.Save and exit the file (in nano
, you can press CTRL + X
, then Y
, and then Enter
).
pg_hba.conf
FileOpen the pg_hba.conf
file:
sudo nano /etc/postgresql/14/main/pg_hba.conf
Add a new line to allow remote connections. Add this line at the end of the file:
host all all 0.0.0.0/0 md5
0.0.0.0/0
) to connect to the database using a password (md5
).0.0.0.0/0
with the desired IP address or range.Save and exit the file.
After making changes to the configuration files, restart PostgreSQL to apply them:
sudo systemctl restart postgresql
Ensure your VPS firewall allows incoming connections on the PostgreSQL port (default is 5432).
Allow PostgreSQL through the firewall:
sudo ufw allow 5432/tcp
Check the firewall status:
sudo ufw status
Ensure that the PostgreSQL port is open.
If you don't have pgAdmin installed, download and install it from the official website:
Open pgAdmin.
Create a new server connection:
Configure the connection:
5432
(or another port if you've configured PostgreSQL to use a different one).postgres
(or another database if you prefer).postgres
).Test the connection:
Access the Databases:
If you encounter any issues:
listen_addresses
is set correctly and that the pg_hba.conf
file has the appropriate entries.This setup should allow you to manage your PostgreSQL databases on your VPS using pgAdmin from your local machine.