Configuring Database Server for non-local connections

The default configuration of PostgreSQL only allows you to connect from the same machine that the server is running on. To configure the database allowing you to connect from other computers, you will need to add the IP addresses of such computers to the configuration file and then restart the database server.

  1. Go to PostgreSQL 8.2→Configuration files→Edit pg_hba.conf
  2. At the bottom of the file, add line
    host       phms        all        IPaddress/mask        md5
    replacing IPaddress/mask with a CIDR notation IP addresses that will be connection to the database. You may add more than one line, if required.
  3. Save changes and exit notepad
  4. Go to PostgreSQL 8.2→Configuration files→Edit  postgresql.conf from the Start menu.
  5. Under "Connection Settings" make sure that the listen_addresses line reads
    listen_addresses = '*'
    and is not commented out (no # at beginning of the line). The default setting is to listen on the 127.0.0.1 socket.
  6. Save changes and exit notepad
  7. Go to PostgreSQL 8.2 group from the Start menu and restart the PostgreSQL service.

You should now be able to connect to the PostgreSQL database from all IP addresses you have added to the pg_hba.conf file. You may add more than one line in Step 3, as needed. The IPaddress/mask format is a normal CIDR notation. For example,

  • 123.123.123.123/32 - will add 123.123.123.123 IP address only
  • 123.123.123.123/24 - will add 123.123.123.0-123.123.123.255 addresses

You will only be able to connect from the added IP addresses (or networks) only.

[table of contents]