Adding Warehouse Users
If you have more than one person working with your Segment Warehouse, you might want to create users for your team so that each person can have a discrete login. The three steps in this section will show you how to create a user, grant usage on a schema and then grant the privileges that the user will need to interact with that schema.
Create a new user for your team with the CREATE USER command:
1CREATE USER <name>2[IN GROUP <group>]3WITH PASSWORD <password>4[VALID UNTIL] <abstime>
The code above in [] is optional, you don't need to group your users or give their credentials an expiration date, the code works without it. However, if you do choose to use those parameters, <abstime> should be formatted in the ISO 8601 format, or '2015-09-13', which translates to September 13th, 2015.
For instance, you can create a user named flashthesloth as:
1CREATE USER flashthesloth2WITH PASSWORD 'slow_is_beautiful'
To get a list of users in your destination, you can run the following SQL code:
SELECT * FROM pg_user
Now that we've confirmed that the user has been created, they already have access to the public schema that contains systems-level information about the cluster. To give them access to the specific schemas that they'll be working in, we'll need to run the GRANT USAGE command.
Next, you'd need to GRANT USAGE on the schema to the user we just created:
GRANT USAGE ON SCHEMA <schema_name> TO <user>
The above SQL command grants the user USAGE privileges on a schema. As an example, if you wanted to grant flashthesloth access to your development schema, you'd run the following:
GRANT USAGE ON SCHEMA development TO flashthesloth
Our new user now has usage rights on the development schema. Now, we need to grant the type of SQL commands they'll be able to run against the cluster. For the purposes of this example, we're going to give the user read only privileges.
To grant your user specific privileges, run the GRANT SELECT command so the user can query the tables:
GRANT SELECT ON ALL TABLES IN SCHEMA <schema_name> TO <user>
The above SQL command grants the user SELECT rights on all tables in the chosen schema. For our flashthesloth user and the development schema, it would look like below.
GRANT SELECT ON ALL TABLES IN SCHEMA development TO flashthesloth
Completing these three steps results in a new user that can query all the tables in a given schema. If you want to give your user access to more than one schema, repeat steps 2 and 3 for each additional schema. If you have any questions, or if you're running into any issues getting this set up, contact Segment support.