When installing PostgreSQL on MacOS you need to create a data folder where it will store details about users, dbs and privileges, but this data is globally available.
Is there a way to separate this based on Mac users?
This way:
- When logging in with UserA, PostgreSQL will only instantiate/see DB_A1 and DB_A2 and PostgreSQL users defined only for UserA’s PostgreSQL instance.
- When logging in with UserB, PostgreSQL will only instantiate/see DB_B1 and DB_B2 and PostgreSQL users defined only for UserB’s PostgreSQL instance.
according to my somewhat rusty knowledge about PostgreSQL your intention would lead to start a postmaster process for every user on his/her own reserved port. Although this is possible, it smells like smoke from administration hell (not counting the overhead of a fat RDBMS process reserved for a single user spending most of the time waiting). Positively expressed I propose considering one of the following options:
Add a line to
pg_hba.conflikelocal all sameuser all md5to allow all local users to only access their personal databaase (named like the user). Access to system data may be further restricted depending on the actual PostgreSQL version you’re using (it’s best to consult the documentation in this case).Depending on the amount of data if concurrent access was not a critical must-have (which seems to be the case here) switch to sqlite3; it’s performant, data sits in a single file, access is provided by a library instead of a full fledged RDBMS background process armada, and it comes ready to use with every Mac OS X.