Super User is a question and answer site for computer enthusiasts and power users. 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've got a Postgres server that's configured to only allow connections from localhost. I like that.

However, I have a situation where I need to run a database that is accessible from something other than localhost.

Is there any way to set this sort of configuration on a per-database level?

share|improve this question
I'm curious why allowing only external connections is preferential. It essentially means you can't properly administer the database from the server it's running on. – MBraedley Mar 17 '14 at 1:57
I guess I wasn't clear - I don't want to disallow localhost, only additionally allow other sources. – Isaac Dontje Lindell Mar 17 '14 at 16:41
Yeah, but that's not what the title says, which is the reason I asked. What you're really asking is "Allow external connections, but only for a specific database". – MBraedley Mar 17 '14 at 17:05
up vote 1 down vote accepted

Yes, this is pretty easy to do.

Just find the pg_hba.conf file your Postgres uses (Mine is in /etc/postgresql/8.4/main but yours may differ, but its the same directory as postgresql.conf is in), and add the appropriate line, for example

host dbname all md5

Will allow any user at to connect to the the database dbname using md5 authentication.

You may need to adjust your firewall rules to allow port 5432 (assuming you run on the default port) through from that machine to your server.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .