Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am completely new to the game but need the following:

I Create a new role with login. Let's say: User1

I then create a Database 'User1Database' and set User1 as the owner.

User1 has no rights to do anything except for access.

Now when I connect using User1 it somehow has access to all databases. I then learned I neeed to write something in here.

User1 should have global access to User1Database and absolutely no access to anything else.

What lines do I need to add to my pg_hba file?

Currently it looks like this:

# IPv4 local connections:
host    all         all          md5
# IPv6 local connections:
host    all         all         ::1/128               md5
host    all             all        md5

Hope someone can write me the exact lines and explain them to me.

share|improve this question

you will want to add two lines like:

local   User1Database     User1                        password
host    User1Database     User1         password

to allow local filesystem access and connecting to the service on localhost...

share|improve this answer
Thanks for that :) However, I need this user to have global access. Can you rewrite it for that? – Mathias May 16 '10 at 19:47
Not always a good idea to allow global access – aduljr May 16 '10 at 20:52
like aduljr posted and commented, opening up for global access is not a recommended route. if the user is going to be accessing from a few remote locations, or going to be using the db server as a backend for some website, you would want to put in place of in his example, where is the ip of the web-server/etc that needs to connect to your database server. usual access to a pgsql db is by shell or via local/remote webserver. just randomly connecting from unknown IPs is /pretty/ rare. – cpbills May 17 '10 at 6:47

If you want to allow everyone and their mother to have access use this. Though I would suggest limiting it to a private network if you can.

host    User1Database     User1         password
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.