Sometimes, it's useful to execute commands as another user. For instance, management commands for some services are, by default, accessible to the system user associated with the service. You may also wish to test whether a user account is configured correctly and execute a command as another user to check if it will work as expected.
In this recipe, we will create a new PostgreSQL database named testdb
by issuing the createdb
command that is available to the postgres
user. If you do not have PostgreSQL installed yet, you may refer to Chapter 10, Running a PostgreSQL Database Server, for information about installing and running this database system.