14 June,2022 by Rambler
Question: How can I create a PostgreSQL user for CRUD operations in a specific database?
Answer: The CRUD operations need to cover CREATE , READ ,UPDATE and DELETE. This is an example of creating a PostgreSQL user and assigning the SELECT , INSERT,UPDATE,DELETE permissions .
I've also added an extra statement to change the default schema for the user via the search_path parameter. For more details on how to apply search_path read more on : How to change PostgreSQL default schema
CREATE USER myuser WITH ENCRYPTED PASSWORD '77hshsh'; GRANT CONNECT ON DATABASE mydb TO myuser; GRANT USAGE ON SCHEMA myschema TO myuser; GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA myschema TO myuser; ALTER USER myuser SET search_path TO myschema;
If this user gets the permission denied error on attempting to create a table - you'll need to add the CREATE - for more information read - How to fix permission denied for schema in PostgreSQL
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |