Question

I am trying to set my local postgresql so it does not have a password. I understand that this has to be done in the pg_hba.conf file and to acceess that file I have to be a postgres user. But to be a postgres user, I have to login with su postgres and enter the password that I don't have.

Any solution to this (I am on OSX)?

Was it helpful?

Solution

You're confusing several different concepts about the security model.

There is a postgres operating system user, which the PostgreSQL server runs as in order to isolate its data files and to limit damage in case of a security breach or application bug. PostgreSQL won't run as root for security. This user doesn't generally have a password, but you can change to it via the root account using sudo - you can sudo to this user with something like sudo -i -u postgres.

There is also a postgres database user, the default database superuser. This user doesn't generally have a password by default, but pg_hba.conf allows the postgres operating system user to connect as the postgres PostgreSQL user using peer authentication.

If you want you can change the configuration so that you use a password for the postgres database user, so you can psql -U postgres from any system user account:

  • ALTER USER postgres WITH ENCRYPTED PASSWORD 'blahblah';
  • Edit pg_hba.conf ("hba" is "host-based authentication") to use md5 authentication for local and host connections.
  • Re-start or re-load PostgreSQL

Similarly, if you want to allow any system user to connect as any database user without a password, you must modify pg_hba.conf and set trust as the authentication mode for local and host connection types. Please only use trust authentication for testing.

To learn more, see the client authentication chapter in the PostgreSQL documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top