Follow dba-ninja.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

dba-ninja.com Links

Dba_db2_button

Sqlserver_dba_button

How to create a PostgreSQL user for CRUD

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


Author: Rambler (http://www.dba-ninja.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

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.

Working...

Post a comment on How to create a PostgreSQL user for CRUD


dba-ninja.com