0

I'm using Mac OSX 10.15.4 (the very latest version). Postgres is installed (v12) and has so far worked fine for what I've needed to do with it.

Start up the Postgres application and there are four databases listed: Andy (which is my locally logged in OSX username), postgres, template1 and test (which is a db I set up myself). If I click on test right from there I can play around with psql to my hearts content, so no problems there. After reading around I understand why Andy and postgres are listed and that template1 is vital to things working properly.

When I \du from within psql logged into my test database I get the following:

Andy     | Superuser, Create role, Create DB                          | {}
postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

And if I `\conninfo' I get:

You are connected to database "test" as user "AndyP" via socket in "/tmp" at port "5433".

So up until now I've been playing around with postgres by opening psql and it's been adequate. However now I'm looking to build an app around postgres and I've hit a wall just in terms of getting access to psql via a simple Terminal window.

I've searched around and found that there are lots of answers on here to similar problems but most have either made little sense, involved throwing in commands that have made me nervous about breaking something or just simply failed to solve my problem.

Which is...

When I open a plain Terminal window and type psql into Terminal, no matter what, I get asked for my password. My understanding (again, from what I've read) is that being logged in to OSX as Andy I'd have expected my login password to work, but it doesn't. Next step, I tried switching to logging in or setting up a password for postgres but alas, it wouldn't let me.

The contents of my pg_ident.conf and pg_hba.conf files are as follows:

pg_ident.conf

# MAPNAME       SYSTEM-USERNAME         PG-USERNAME

but there are no entries after those headers.

pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust

And from what I've also read, the trust means that as a local user I should be able to log in without any issues.

Obviously I'm missing something so any help would be welcome.

Additionally:

After reading this (https://www.liquidweb.com/kb/change-a-password-for-postgresql-on-linux-via-command-line/) I was able to \password and change my password from within the open psql window but as soon as I tried to access psql from a brand new terminal window and it asked for my password it still blocked me

psql: error: could not connect to server: FATAL: password authentication failed for user "Andy"

Even though I'd just changed it.

2
  • 1
    Try psql -p 5433. Your conninfo output lists port 5433, but 5432 is the default; my guess is you have more than one version of postgres installed, and the pg_hba.conf you posted is for the version running on port 5433. I'm not familiar with OSX so I can't speak to figuring out where the 5432 config files live. Commented Jun 15, 2020 at 15:57
  • Holy cow... that worked!! Straight in... but two installations of postgres?? Commented Jun 15, 2020 at 16:01

1 Answer 1

1

What is sure that you have 2 different PostgreSQL database instances: one using default port 5432 and the other one port 5433.

It is not sure that you have 2 different PostgreSQL versions installed because you can have this situation only with 1 PostgreSQL installed version: 2 instances can use the same PG version on the same machine, they just need to use different port numbers and different PGDATA directories.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, when I switched my code to use port 5433 it connected as expected. When I tried to update this installation of Postgres to use 5432 it warned me that there was another version of Postgres running. I need to investigate it a bit more and find out what's going on.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.