FRiCKLE / ngx_postgres

upstream module that allows nginx to communicate directly with PostgreSQL database.
http://labs.frickle.com/nginx_ngx_postgres/
BSD 2-Clause "Simplified" License
545 stars 122 forks source link

Ability to build as dynamic module #47

Closed cryptofuture closed 7 years ago

cryptofuture commented 8 years ago

I wanted to convert module myself, but I can miss something (config with too many sections). Currently this is only one non dynamic module I currently use.

agentzh commented 8 years ago

@cryptofuture Patches welcome :)

cryptofuture commented 8 years ago

Tried today:
/etc/nginx/modules/ngx_postgres.so: undefined symbol: ngx_postgres Seems like changing ngx_module_type makes no difference in end .so file. (tried HTTP and CORE too) config I used and changes. Any ideas? Should I write to nginx mailing list?

agentzh commented 8 years ago

@cryptofuture The value of ngx_module_name variable in your config is wrong. Should be something like ngx_postgres_module instead to be consistent with the definition in the C code base. Maybe we should change it to ngx_http_postgres_module to be consistent with other nginx http C modules further. @PiotrSikora ?

cryptofuture commented 8 years ago

Thanks, will try build tomorrow. ngx_http_postgres_module makes more sense.

cryptofuture commented 8 years ago

Tried build today as dynamic, now undefined symbol: PQsendQuery from ngx_http_postgres_processor.c source:

ngx_postgres_upstream_send_query(ngx_http_request_t *r, ngx_connection_t *pgxc,
    ngx_postgres_upstream_peer_data_t *pgdt)
{
    ngx_postgres_loc_conf_t  *pglcf;
    ngx_int_t                 pgrc;
    u_char                   *query;

    dd("entering");

    pglcf = ngx_http_get_module_loc_conf(r, ngx_postgres_module);

    query = ngx_pnalloc(r->pool, pgdt->query.len + 1);
    if (query == NULL) {
        dd("returning NGX_ERROR");
        return NGX_ERROR;
    }

    (void) ngx_cpystrn(query, pgdt->query.data, pgdt->query.len + 1);

    dd("sending query: %s", query);
    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pgxc->log, 0,
                   "postgres: sending query: \"%s\"", query);

    if (pglcf->output_binary) {
        pgrc = PQsendQueryParams(pgdt->pgconn, (const char *) query,
                                 0, NULL, NULL, NULL, NULL, /* binary */ 1);
    } else {
        pgrc = PQsendQuery(pgdt->pgconn, (const char *) query);
    }

    if (pgrc == 0) {
        dd("sending query failed");
        ngx_log_error(NGX_LOG_ERR, pgxc->log, 0,
                      "postgres: sending query failed: %s",
                      PQerrorMessage(pgdt->pgconn));

        dd("returning NGX_ERROR");
        return NGX_ERROR;
    }

    /* set result timeout */
    ngx_add_timer(pgxc->read, r->upstream->conf->read_timeout);

    dd("query sent successfully");
    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pgxc->log, 0,
                   "postgres: query sent successfully");

    pgxc->log->action = "waiting for result from PostgreSQL database";
    pgdt->state = state_db_get_result;

    dd("returning NGX_DONE");
    return NGX_DONE;
}

BTW moved all ngx_postgres reference to ngx_http_postgres locally (a lot changes), was hope I made some error, but ether way undefined symbol: PQsendQuery on module loading.

agentzh commented 8 years ago

@cryptofuture You failed to link libpq against your own ngx_http_postgres_module.so, I guess.

cryptofuture commented 7 years ago

Covered in #54