Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict user privileges to one particular database only

PostgreSQL Version 9.1,

i am logging into database with default user: "postgres" and my database contains default role "public"

list of database i have,

1.database1

2.database2

3.database3

now, i need to create a user "newuser" which will have only privilege to "database2", it should not login into other databases.

i tried using this syntax

create role newuser with login nosuperuser nocreatedb nocreaterole noinherit password 'newpassword';
revoke all privileges on database database1, database3 from newuser;

but still the "newuser" can login into other database(database1/database3) and it can select tables from other schema's. (tables in public schema is not listed)

please, anyone explain me the correct procedure to create a user and grant privileges to them.

i need a user who can have all privileges on a particular database only, he should not login to other database :)

like image 886
MAHI Avatar asked Jun 13 '12 09:06

MAHI


People also ask

How do I restrict access to SQL database?

You can restrict access to data at the following levels: You can use the GRANT and REVOKE statements to give or deny access to the database or to specific tables, and you can control the kinds of uses that people can make of the database.

How do I restrict someone from seeing available database in SQL Server?

1) Login to SQL Management studio and connect to your SQL instance. 2) Expand Servers and select your SQL instance. Then tick the box Deny for "View any database" Please note that there are other ways of doing this, or by just setting a deny view permission on specific databases.


1 Answers

You can remove privileges from users on the database by running:

REVOKE ALL PRIVILEGES ON DATABASE database_name FROM username;
like image 80
Jonathan Haar Avatar answered Sep 20 '22 21:09

Jonathan Haar