Обсуждение: PostgreSQL - How to login with my Linux user account

Поиск
Список
Период
Сортировка

PostgreSQL - How to login with my Linux user account

От
Amn Ojee Uw
Дата:

I'd like to log into my newly installed PostgreSQL [ PostgreSQL 12.15 (Debian 12.15-1.pgdg120+1) ] using my linux account.
In trying to do that this web page suggest that I enter :

psql -d mydb -U myuser -W

However, that command requires a database_name (mydb), and PosgreSQL 12.15 being so freshly installed does not yet 
have any database created by me.

How would you suggest I circumvent this challenge?

Mind you that, using the postgres account I have created other accounts.


Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+----------- chispa    | Superuser                                                  | {} pedro     | Superuser                                                  | {} postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}


Thanks in advance.

Re: PostgreSQL - How to login with my Linux user account

От
"David G. Johnston"
Дата:
On Thu, Jul 27, 2023 at 5:19 PM Amn Ojee Uw <amnojeeuw@gmail.com> wrote:
However, that command requires a database_name (mydb), and PosgreSQL 12.15 being so freshly installed does not yet 
have any database created by me.
So create some.  Otherwise the only useful database name to specify would be "postgres".

David J.

Re: PostgreSQL - How to login with my Linux user account

От
Adrian Klaver
Дата:
On 7/27/23 17:19, Amn Ojee Uw wrote:
> I'd like to log into my newly installed PostgreSQL [ PostgreSQL 12.15 
> (Debian 12.15-1.pgdg120+1) ] using my linux account.
> In trying to do that this web page 
> <https://alvinalexander.com/blog/post/postgresql/log-in-postgresql-database/>suggest that I enter :
> 
> psql -d mydb -U myuser -W
> 
> However, that command requires a database_name (mydb), and PosgreSQL 12.15 being so freshly installed does not yet
> have any database created by me.
> 
> How would you suggest I circumvent this challenge?

The tutorial

https://www.postgresql.org/docs/current/tutorial.html

would be a good place to start.

 From said tutorial:

https://www.postgresql.org/docs/current/tutorial-createdb.html

createdb mydb


Which in turn leads to:

https://www.postgresql.org/docs/current/app-createdb.html

> 
> Mind you that, using the postgres account I have created other accounts.
> 
> 
> Role name |                         Attributes                         | Member of
> -----------+------------------------------------------------------------+-----------
>   chispa    | Superuser                                                  | {}
>   pedro     | Superuser                                                  | {}
>   postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
> 
> 
> Thanks in advance.
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com




Re: PostgreSQL - How to login with my Linux user account

От
Amn Ojee Uw
Дата:

First of all, my gratitude to Adrian and David for taking the time to reply to my call for help; a 1k  thanks to you kids.

Having stated the above, PostgreSQL provides a default database namely 'postgres'. Taking advantage of this service, I have change the 'psql' statement to 'psql -d postgres -U my_linux_user_name -W', I then entered my Linux account login password and got this error messages :
$ psql -d postgres -U my_linux_user_name -W
Password:
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "my_linux_user_name"

I also, using 'postres' account, have created another user account, chispa, who is a superuser; when trying to login as 'chispa' and using the above statement (psql -d postgres -U chispa -W ) PostgreSQL throws the same error message.

What am I doing wrong?
Is there a webpage that explains how to login to PostgreSQL as other than 'postgres'?


Thanks in advance.

On 7/27/23 8:19 p.m., Amn Ojee Uw wrote:
psql -d mydb -U myuser -W

Re: PostgreSQL - How to login with my Linux user account

От
Ron
Дата:
On 7/28/23 09:00, Amn Ojee Uw wrote:

First of all, my gratitude to Adrian and David for taking the time to reply to my call for help; a 1k  thanks to you kids.

Having stated the above, PostgreSQL provides a default database namely 'postgres'. Taking advantage of this service, I have change the 'psql' statement to 'psql -d postgres -U my_linux_user_name -W', I then entered my Linux account login password and got this error messages :
$ psql -d postgres -U my_linux_user_name -W
Password:
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "my_linux_user_name"

I also, using 'postres' account, have created another user account, chispa, who is a superuser; when trying to login as 'chispa' and using the above statement (psql -d postgres -U chispa -W ) PostgreSQL throws the same error message.

What am I doing wrong?
Is there a webpage that explains how to login to PostgreSQL as other than 'postgres'?


https://www.postgresql.org/docs/12/auth-pg-hba-conf.html

You want peer authentication to be able to connect to postgresql as my_linux_username.

--
Born in Arizona, moved to Babylonia.

Re: PostgreSQL - How to login with my Linux user account

От
Adrian Klaver
Дата:
On 7/28/23 07:00, Amn Ojee Uw wrote:
> First of all, my gratitude to Adrian and David for taking the time to 
> reply to my call for help; a 1k  thanks to you kids.
> 
> Having stated the above, PostgreSQL provides a default database namely 
> 'postgres'. Taking advantage of this service, I have change the 'psql' 
> statement to 'psql -d postgres -U my_linux_user_name -W', I then entered 
> my Linux account login password and got this error messages :
> /*$ psql -d postgres -U my_linux_user_name -W *//*
> *//*Password: *//*
> *//*psql: error: connection to server on socket 
> "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication 
> failed for user "my_linux_user_name"*/

1) See

https://www.postgresql.org/docs/current/auth-peer.html

2) What OS are you on and how did you install Postgres?

3) Try

sudo -u postgres psql postgres


4) Provide the content of pg_hba.conf that starts at the line below

# TYPE  DATABASE        USER            ADDRESS                 METHOD

...


> 
> I also, using 'postres' account, have created another user account, 
> chispa, who is a superuser; when trying to login as 'chispa' and using 
> the above statement (/*psql -d postgres -U chispa -W *//*)*/ PostgreSQL 
> throws the same error message.
> /**/
> 
> What am I doing wrong?
> Is there a webpage that explains how to login to PostgreSQL as other 
> than 'postgres'?
> 
> 
> Thanks in advance.
> 
> On 7/27/23 8:19 p.m., Amn Ojee Uw wrote:
>> psql -d mydb -U myuser -W

-- 
Adrian Klaver
adrian.klaver@aklaver.com