Linux Labs

Web stack / Stage 7 of 9

Connection, role and pg_hba

Not running Starting usually ~20 s
Leave the lesson

Step 1 of 7 · on a machine · 5 min

The application cannot log in

What you will learn

  • Tell from a psql message which check stopped the connection — network, rule or password.
  • Read pg_hba.conf and find the line that decides the fate of a connection.
  • Add a narrow access rule and apply it without restarting the server.

The shop on this server got a PostgreSQL database called shop and an account shop with a password. The shop application connects to the database at 127.0.0.1 and gets refused, although the service is running.

Repeat its attempt from the terminal. The shop password is in your ~/.pgpass file, and psql picks it up by itself. “Start” launches PostgreSQL and creates the databases.

Exercise · look

Repeat the application's login

Check that the service is running and port 5432 is listening, then log in to the shop database as the shop role, the way the application does.

First, predict

What will psql answer?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

The service is active, port 5432 is listening, yet the shop login was refused. Where did the attempt stop?

  • The connection got through: ss showed LISTEN … 127.0.0.1:5432, and the FATAL: no pg_hba.conf entry line came from the server.

  • systemctl is-active postgresql printed active, and the server answered the connection, so the service is fine.

  • The password is in ~/.pgpass, but it never got that far: the refusal says nothing about a password, only no pg_hba.conf entry.

The connection reached PostgreSQL, and the refusal was written by the server itself.

Ubuntu 24.04
Loading…