<!-- review: finished -->

<a id="external-postgres"></a>

# Postgres

Postgres 模块提供对 PostgreSQL 数据库的直接支持。

<a id="installation-22"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-postgres`
- Angie PRO:`angie-pro-module-postgres`

<a id="loading-the-module-22"></a>

## 加载模块

在 `main{}` 上下文中加载模块:

```nginx
load_module modules/ngx_postgres_module.so;
```

<a id="configuration-example-96"></a>

## 配置示例

```nginx
http {
    upstream database {
        postgres_server 127.0.0.1 dbname=ang_test
                         user=ang_test password=ang_test;
    }

    server {
        listen 80;
        postgres_output text;

        location /create {
            postgres_pass database;
            postgres_query "CREATE TABLE cats (id integer, name text)";
        }

        location /insert {
            postgres_pass database;
            postgres_query "INSERT INTO cats (id, name) VALUES ($arg_id, '$arg_name')";
        }

        location /select {
            postgres_pass database;
            postgres_query "SELECT name FROM cats WHERE id=$arg_id";
        }
    }
}
```

<a id="additional-information-23"></a>

## 其他信息

详细文档和源代码可在以下位置获取:
[https://github.com/FRiCKLE/ngx_postgres](https://github.com/FRiCKLE/ngx_postgres)
