Search code examples
postgresqlpublic

PostgreSQL public access to database


I recently created a test database but I would like it to be accessible to all users.

I created the database as user postgres then use the command

GRANT ALL ON DATABASE dbname TO public;

But when I log out and try to connect to it with a different user I get this error

psql -d dbname
psql: FATAL:  role "username" does not exist

I don't want to have to create a user for each person who will be accessing the database which is the reason i wanted to make it public. Is there a permission that I am still missing?


Solution

  • Although access to everybody (public) is granted, the user you connect with has to exist. The default for psql is the username of your system account. You can, of course, create a passwordless anonymous user everybody can use to connect:

    psql -U anonymous dbname