---
title: "打开postgresql的远程访问权限"
author: "夜鸣猪"
date: "2012-09-04T21:30:31Z"
tags: []
categories: ["编程语言"]
slug: "postgresql"
draft: false
lastmod: "2012-09-04T21:30:31Z"
id: 1671474
url: "https://hlee.iteye.com/blog/1671474"
---

External PostgreSQL connections

1. To be able to reach the server remotely you have to add the following line into the file: /var/lib/pgsql/data/postgresql.conf:


```java
listen_addresses = '*'
```

2. PostgreSQL, by default, refuses all connections it receives from any remote address. You have to relax these rules by adding this line to /var/lib/pgsql/data/pg_hba.conf:


```java
host all all  0.0.0.0/0 md5
```

This is an access control rule that lets anyone login from any address if a valid password is provided (the md5 keyword). You can use your network/mask instead of 0.0.0.0/0 to only allow access from certain IP addresses.

3. When you have applied these modifications to your configuration files, you will need to restart the PostgreSQL server.


```java
/etc/init.d/postgresql start
```

Now, you will be able to login to your server remotely.