Postgres#

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

加载模块#

main{} 上下文中连接模块:

load_module modules/ngx_postgres_module.so;

配置示例#

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";
        }
    }
}

附加信息#

详细文档和源代码可在以下地址获取: FRiCKLE/ngx_postgres