Sub topic 11
Registering a server in pgAdmin
pgAdmin 4 does not connect to a database. It connects to a server, and a registration is the saved record of how to reach it. This chapter covers the registration dialog, how its fields map to the psql flags you already know, and how to diagnose a failed connection.
This chapter assumes you have read the chapter on how a PostgreSQL server is organized. It also assumes that pgAdmin 4 is installed or reachable in a browser, and that you can run psql in a terminal to cross-check settings.
What a registration stores
A registration is a saved set of connection settings. It holds the host, port, maintenance database, user and optional extras such as SSL and SSH tunnel settings. pgAdmin does not store your data or a copy of the schema. Each time you connect, it reads the catalogs live, so the object tree always reflects the server's current state.
Registrations live under server groups in the Object Explorer tree. The default group is called Servers. Groups are only labels for organizing registrations, for example Local, Staging and Production.
The fields map directly onto the psql command from earlier chapters:
| pgAdmin field | psql equivalent | Notes |
|---|---|---|
| Host name/address | `-h` | A name, an IP address, or a Unix socket directory |
| Port | `-p` | Defaults to 5432 |
| Maintenance database | `-d` | The database pgAdmin connects to first |
| Username | `-U` | A role that can log in |
| Password | prompt or `PGPASSWORD` | Only saved if you tick Save password |
| SSL mode | `sslmode=` in a connection string | `prefer` by default |
Registering a server step by step
- In the Object Explorer, right-click
Servers, then choose Register, then Server. - On the General tab, enter a Name. This label is only for display and has no effect on the connection. Choose a server group if you use more than one.
- Open the Connection tab and fill in Host name/address, Port, Maintenance database, Username and Password.
- Tick Save password only if you accept the storage trade-off described below.
- Click Save.
The dialog runs the connection attempt when you save, and the server appears in the tree. If the attempt fails, pgAdmin shows the server's error message. Read it closely, because it usually names the cause.
For a local server, these values match the first psql example in this tutorial:
psql -h localhost -p 5432 -U postgres -d mydbIn pgAdmin, that means Host localhost, Port 5432, Username postgres. You can use mydb as the maintenance database. The next section explains why that field exists.
The maintenance database
The Maintenance database field often confuses people. PostgreSQL requires every connection to target one database, and pgAdmin needs a connection before it can list the other databases. The maintenance database is the one it connects to first. The default is postgres.
You can set it to any database the role may connect to. This helps when the postgres database was dropped, or when your role is only allowed into one database.
After you connect, pgAdmin opens a separate connection to each database as you expand it in the tree. Because of this, one registered server can hold several open sessions at once. The Dashboard and pg_stat_activity show these sessions with the application name pgAdmin 4 - DB:<name>.
Optional tabs
The dialog has more tabs than most users need. These matter in practice:
- SSL. Chooses the SSL mode (
disable,allow,prefer,require,verify-ca,verify-full) and the paths to certificate files. Useverify-fullfor any server across an untrusted network, becauserequireencrypts the traffic but does not check who answers. - SSH Tunnel. Reaches a database that is only exposed inside a private network. pgAdmin opens an SSH connection to a bastion host and forwards the PostgreSQL port through it. Then you set Host and Port in the Connection tab as seen from the bastion host.
- Advanced. Holds the DB restriction field, which limits the tree to the databases you list, and the connection timeout. Restricting the tree is useful on a server with hundreds of databases.
The Connection tab also has a Role field. If you set it, pgAdmin runs SET ROLE after login, so your session acts with that role's privileges.
Where the password goes
If you tick Save password, pgAdmin stores the password in its own configuration database, encrypted. Desktop mode uses a key derived from an optional master password. If you set no master password, the key is not protected by anything you type. In server mode, where pgAdmin is hosted for several users, the key is derived from each user's pgAdmin login password.
Verifying what you connected to
After you connect, open the Query Tool on any database and confirm the connection details. Never assume that a server named prod in your tree is the server you think it is. The registration name is only a label.
SELECT current_user,
current_database(),
inet_server_addr() AS server_ip,
inet_server_port() AS server_port,
version();For a Unix socket connection, inet_server_addr() returns NULL. That is expected, and it does not indicate an error.
Diagnosing connection failures
Most failures fall into three groups: the network layer, the server's listening configuration, and authentication. The error text tells you which group.
Connection refused and timeouts
"Connection refused" means a machine answered, but nothing listens on that port. Check that the server is running, that the port is right, and that the server listens on the address you used. Run this through any working connection, such as psql on the server itself:
SHOW listen_addresses;
SHOW port;The default listen_addresses is localhost, which accepts only local connections. To accept remote ones, change it in postgresql.conf, for example to '*'. This setting requires a server restart, not just a reload.
A timeout usually means a firewall silently drops the packets, or the host is not routable from your machine. Try psql from the same machine that runs pgAdmin. If psql fails the same way, the problem is not pgAdmin.
no pg_hba.conf entry
PostgreSQL decides who may connect from which address in pg_hba.conf. If no line matches the client address, database, user and SSL state, the server rejects the connection. A line that allows one user from one subnet with password authentication looks like this:
# TYPE DATABASE USER ADDRESS METHOD
host mydb app_user 192.168.1.0/24 scram-sha-256After editing the file, reload the configuration without restarting. A restart is not needed for this file.
SELECT pg_reload_conf();Lines are matched in order and the first match wins. A broad reject or md5 line above your new line can shadow it.
Password authentication failed
This error means the server found a matching rule and then rejected the credentials. Check the Username in the dialog, because postgres and Postgres differ when the name is quoted. Also confirm that the role has the LOGIN attribute. A role created with CREATE ROLE has NOLOGIN by default, so CREATE USER is the usual choice for a person or an application.
pgAdmin in Docker
When pgAdmin runs in a container, localhost means the container itself, not your computer. A PostgreSQL server on the host machine is not reachable at localhost. Use the host's address, or on Docker Desktop the name host.docker.internal. When both run as containers on one Docker network, use the database container's service name as the host.
Editing and removing registrations
To change a registration, disconnect the server first, then right-click it and choose Properties. Most fields are locked while a connection is open. Removing a registration only deletes the saved settings in pgAdmin. It never touches the server or its data.
Exercise
You register a server with Host db.example.com, Port 5432 and Username app_user. pgAdmin reports "no pghba.conf entry for host ... user appuser, database mydb". Is the password the problem? What do you check and change?
Show answer
No. The error means the server found no pghba.conf line matching the client address, user, database and SSL state, so it rejected the connection before checking any password. Add a line such as `host mydb appuser <client-subnet> scram-sha-256 to pg_hba.conf, put it above any broader rule that would match first, and run SELECT pgreloadconf();`. A reload is enough, and no restart is needed.