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 usemd5
authentication forlocal
andhost
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.