2

I am trying to create a database with a role, that can connect to and view that database only.

How I went about it:

_, err = db.Exec("CREATE DATABASE " + database.Name + " ENCODING 'utf8' LC_COLLATE 'en_US.UTF-8'")
_, err = db.Exec("CREATE ROLE " + database.User + " WITH LOGIN PASSWORD '" + database.Password + "'")
_, err = db.Exec("REVOKE ALL PRIVILEGES ON DATABASE " + database.Name + " FROM PUBLIC")
_, err = db.Exec("GRANT ALL PRIVILEGES ON DATABASE " + database.Name + " TO " + database.User)

The problem is that my role can connect to postgres via:

psql -U haruki -W -h localhost

Which is okay, but it can list all databases with its corresponding permissions, even though it cannot connect to them.

Is there any way I can prevent the user from listing all databases? Or perhaps allow logging in only with the -d flag?

1 Answer 1

1

There's no way restricting this in pgsql. The pg_catalog holds the names of the databases.

Either you have to add a custom layer to do this in between in any language you use or you can follow this by editing the postgresql config and using DDL statements.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.