Giving users their own private databases
Again, make sure you've read the Deciding on a design for multitenancy recipe so that you're certain this is the route you wish to take. Other options exist, and they may be preferable in some cases.
How to do it…
Follow these steps to create a database with restricted access for a specific user:
- We can create a database for a specific user with some ease. From the command line, as a superuser, we can do the following:
postgres=# create user fred; CREATE ROLE postgres=# create database fred owner fred; CREATE DATABASE
- As database owners, users have login privileges, so they can connect to any database by default. There is a command named
ALTER DEFAULT PRIVILEGESfor...