The following script creates a new user named user002. The user will have all rights on a particular database named Tex01. The script will include the public schema and the tex002 schema.

-- Step 1: Create the User
CREATE USER user002 WITH PASSWORD 'your_password';

-- Step 2: Grant Privileges in the Tex01 Database
\c Tex01

-- Grant all privileges on the public schema
GRANT ALL PRIVILEGES ON SCHEMA public TO user002;

-- Grant all privileges on the tex002 schema
GRANT ALL PRIVILEGES ON SCHEMA tex002 TO user002;

-- Grant all privileges on all tables in the public schema
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO user002;

-- Grant all privileges on all sequences in the public schema
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO user002;

-- Grant all privileges on all functions in the public schema
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO user002;

-- Similarly, grant privileges on all objects in the tex002 schema
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA tex002 TO user002;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA tex002 TO user002;
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA tex002 TO user002;

-- Optional: Grant connect privilege to the Tex01 database
GRANT CONNECT ON DATABASE Tex01 TO user002;

By Rudy