Logging into PostgreSQL on Linux

Viewed 18

I have installed Postgre SQL on my local Ubuntu 20.04 as described here:

https://computingforgeeks.com/how-to-install-postgresql-13-on-ubuntu/

In order to log in to Postge SQL I have to switch to user postgres first

(base) irbis@irbis-System-Product-Name:~$ sudo su - postgres
[sudo] password for irbis: 
postgres@irbis-System-Product-Name:~$ psql
psql (13.8 (Ubuntu 13.8-1.pgdg20.04+1))
Type "help" for help.

postgres=# 

Without switching to postgres there is an error:

(base) irbis@irbis-System-Product-Name:~$ psql
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  role "irbis" does not exist

So the question is - what I have to do in order to

  1. Start Console by default (with user irbis)
  2. Type psql (not psql -U or any other)
  3. Postgres started

Maybe create role etc. Please provide me with code snippet. I am a newbie to Postgres and don't want to break anything.

1 Answers

If you want to keep using the current authentication method (presumably 'peer', you should create a user and database named "irbis".

Log into postgresql using the currently functional sudo method, then

create user irbis;
create database irbis owner irbis;

If you never want to use the sudo method again, then you should create the user 'irbis' as a superuser. But that will make it more likely that you will accidentally break things in the future. Your 'daily' user account should probably not be a database superuser.

Related