Usually you want to start the Postgres database server in the background as a service (except e.g. in a container). It seems like you are trying to start it in the foreground instead.
You can do that using the following command.
sudo systemctl start postgresql
You may check if it is running using this:
sudo systemctl status postgresql
If it is running you should see something like this.
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Tue 2022-03-15 16:57:15 CET; 4min 34s ago
Process: 205678 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 205678 (code=exited, status=0/SUCCESS)
Then you will still not be able to connect via psql
as by default configuration Postgres won't successfully authenticate you as it is using Peer Authentication
and your username is likely not postgres
which is the default user and database psql
uses.
The error message will be something like this psql: error: FATAL: Peer authentication failed for user "postgres"
.
There is a guide on how to change the configuration in this answer so you will be able to successfully authenticate.
Whether you're using psql
, pgAdmin
or another client should not matter as long as you have authentication configured correctly and are connecting with the right username
, database name
, host
and port
. You can see the defaults and how you can specify your own values using psql --help
.
PS: You might also wanna consider using the official Postgres container instead of installing Postgres on your system. There is a description on how to get that up and running on DockerHub as well.