{"id":22568102,"url":"https://github.com/rekgrpth/ngx_pq_module","last_synced_at":"2026-03-11T04:03:03.461Z","repository":{"id":41161409,"uuid":"494369111","full_name":"RekGRpth/ngx_pq_module","owner":"RekGRpth","description":"Nginx PostgreSQL upstream connection","archived":false,"fork":false,"pushed_at":"2026-01-01T19:10:05.000Z","size":661,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-07T03:10:16.655Z","etag":null,"topics":["connection","nginx","postgresql","upstream"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RekGRpth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-20T07:42:55.000Z","updated_at":"2026-01-01T19:10:08.000Z","dependencies_parsed_at":"2024-01-01T20:26:30.419Z","dependency_job_id":"772c1038-a571-4f2f-9e7b-ed091a9adb69","html_url":"https://github.com/RekGRpth/ngx_pq_module","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/RekGRpth/ngx_pq_module","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RekGRpth%2Fngx_pq_module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RekGRpth%2Fngx_pq_module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RekGRpth%2Fngx_pq_module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RekGRpth%2Fngx_pq_module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RekGRpth","download_url":"https://codeload.github.com/RekGRpth/ngx_pq_module/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RekGRpth%2Fngx_pq_module/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30370278,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T21:41:54.280Z","status":"online","status_checked_at":"2026-03-11T02:00:07.027Z","response_time":84,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["connection","nginx","postgresql","upstream"],"created_at":"2024-12-08T00:11:27.161Z","updated_at":"2026-03-11T04:03:03.456Z","avatar_url":"https://github.com/RekGRpth.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nginx PostgreSQL upstream connection\n\n# Directives\n\npq_empty\n-------------\n* Syntax: **pq_empty** *200* | *204* | *400* | *401* | *403* | *404* | *409*\n* Default: 200\n* Context: main, server, location, if in location\n\nSets HTTP status code for empty response. Status code will be set to given value only if all queries inside location returns nothing.\n```nginx\nlocation =/postgres {\n    pq_empty 404; # returns 404 (not found), when 0 rows\n    pq_query \"SELECT 1 WHERE false\"; # returns 0 rows\n}\n```\npq_execute\n-------------\n* Syntax: **pq_execute** *$query_name* [ *$argument_value* ] [ output=*csv* | output=*plain* | output=*value* | output=*binary* | output=*$variable* ]\n* Default: --\n* Context: location, if in location, upstream\n\nSets $query_name (nginx variables allowed), optional (several) $argument_value (nginx variables allowed) and output csv/plain/value/binary (location only, no nginx variables allowed) or $variable (upstream only, create nginx variable) for execute:\n```nginx\nlocation =/postgres {\n    pq_execute $query string $argument output=plain; # execute query with name $query and two arguments (first argument is string and second argument is taken from $argument variable) and plain output type\n    pq_execute $query string $argument output=value; # execute query with name $query and two arguments (first argument is string and second argument is taken from $argument variable) and value output type\n    pq_option user=user dbname=dbname application_name=application_name; # set user, dbname and application_name\n    pq_pass postgres; # upstream is postgres\n}\n# or\nupstream postgres {\n    pq_option user=user dbname=dbname application_name=application_name; # set user, dbname and application_name\n    pq_execute $query string $argument output=$variable; # execute query with name $query and two arguments (first argument is string and second argument is taken from $argument variable) and output to $variable variable\n    pq_execute $query string $argument; # execute query with name $query and two arguments (first argument is string and second argument is taken from $argument variable)\n    server postgres:5432; # host is postgres and port is 5432\n}\n```\npq_level\n-------------\n* Syntax: **pq_level** *level* \"*message*\"\n* Default: --\n* Context: upstream\n\nSets logging level for connection error:\n```nginx\nupstream postgres {\n    pq_level info \"session is read-only\\n\";\n}\n```\npq_log\n-------------\n* Syntax: **pq_log** *file* [ *level* ]\n* Default: error_log logs/error.log error;\n* Context: upstream\n\nSets logging (used when keepalive):\n```nginx\nupstream postgres {\n    keepalive 8;\n    pq_log /var/log/nginx/pg.err info; # set log level\n}\n```\npq_option\n-------------\n* Syntax: **pq_option** *name*=*value*\n* Default: --\n* Context: location, if in location, upstream\n\nSets connection options with name (no nginx variables allowed) and value (no nginx variables allowed):\n```nginx\nupstream postgres {\n    pq_option user=user dbname=dbname application_name=application_name; # set user, dbname and application_name\n    server postgres:5432; # host is postgres and port is 5432\n}\n# or\nupstream postgres {\n    pq_option user=user dbname=dbname application_name=application_name; # set user, dbname and application_name\n    server unix:/run/postgresql:5432; # unix socket is in /run/postgresql directory and port is 5432\n}\n# or\nlocation =/postgres {\n    pq_option user=user dbname=dbname application_name=application_name; # set user, dbname and application_name\n    pq_pass postgres:5432; # host is postgres and port is 5432\n}\n# or\nlocation =/postgres {\n    pq_option user=user dbname=dbname application_name=application_name; # set user, dbname and application_name\n    pq_pass unix:/run/postgresql:5432; # unix socket is in /run/postgresql directory and port is 5432\n}\n```\nIn upstream also may use nginx keepalive module:\n```nginx\nupstream postgres {\n    keepalive 8;\n    pq_option user=user dbname=dbname application_name=application_name; # set user, dbname and application_name\n    server postgres:5432; # host is postgres and port is 5432\n}\n# or\nupstream postgres {\n    keepalive 8;\n    pq_option user=user dbname=dbname application_name=application_name; # set user, dbname and application_name\n    server unix:/run/postgresql:5432; # unix socket is in /run/postgresql directory and port is 5432\n}\n```\npq_prepare\n-------------\n* Syntax: **pq_prepare** *$query_name* *sql* [ *$argument_oid* ]\n* Default: --\n* Context: location, if in location, upstream\n\nSets $query_name (nginx variables allowed), sql (named only nginx variables allowed as identifier only) and optional (several) $argument_oid (nginx variables allowed) for prepare:\n```nginx\nlocation =/postgres {\n    pq_pass postgres; # upstream is postgres\n    pq_prepare $query \"SELECT $1, $2::text\" 25 \"\"; # prepare query with name $query and two arguments (first query argument oid is 25 (TEXTOID) and second query argument is auto oid)\n}\n# or\nupstream postgres {\n    pq_option user=user dbname=dbname application_name=application_name; # set user, dbname and application_name\n    pq_prepare $query \"SELECT $1, $2::text\" 25 \"\"; # prepare query with name $query and two arguments (first query argument oid is 25 (TEXTOID) and second query argument is auto oid)\n    server postgres:5432; # host is postgres and port is 5432\n}\n```\npq_pass\n-------------\n* Syntax: **pq_pass** *host*:*port* | unix:/*socket*:*port* | *$upstream*\n* Default: --\n* Context: location, if in location\n\nSets host (no nginx variables allowed) and port (no nginx variables allowed) or unix socket (no nginx variables allowed) and port (no nginx variables allowed) or upstream (nginx variables allowed):\n```nginx\nlocation =/postgres {\n    pq_pass postgres:5432; # host is postgres and port is 5432\n}\n# or\nlocation =/postgres {\n    pq_pass unix:/run/postgresql:5432; # unix socket is in /run/postgresql directory and port is 5432\n}\n# or\nlocation =/postgres {\n    pq_pass postgres; # upstream is postgres\n}\n# or\nlocation =/postgres {\n    pq_pass $postgres; # upstream is taken from $postgres variable\n}\n```\npq_query\n-------------\n* Syntax: **pq_query** *sql* [ *$argument_value* | *$argument_value*::*$argument_oid* ] [ output=*csv* | output=*plain* | output=*value* | output=*binary* | output=*$variable* ]\n* Default: --\n* Context: location, if in location, upstream\n\nSets sql (named only nginx variables allowed as identifier only), optional (several) $argument_value (nginx variables allowed), $argument_oid (nginx variables allowed) and output csv/plain/value/binary (location only, no nginx variables allowed) or $variable (upstream only, create nginx variable) for prepare and execute:\n```nginx\nlocation =/postgres {\n    pq_pass postgres; # upstream is postgres\n    pq_query \"SELECT now()\" output=csv; # prepare and execute simple query and csv output type\n}\n# or\nlocation =/postgres {\n    pq_pass postgres; # upstream is postgres\n    pq_query \"listen $channel\"; # listen channel from variable $channel\n}\n# or\nlocation =/postgres {\n    pq_pass postgres; # upstream is postgres\n    pq_query \"SELECT 1/0\"; # simple query with error\n}\n# or\nlocation =/postgres {\n    pq_pass postgres; # upstream is postgres\n    pq_query \"SELECT $1, $2::text\" string::25 $arg output=plain; # prepare and execute extended query with two arguments (first argument is string and its oid is 25 (TEXTOID) and second argument is taken from $arg variable and auto oid) and plain output type\n}\n```\n# Embedded Variables\n-------------\n* Syntax: $pq_*name*\n\n```nginx\nlocation =/postgres {\n    add_header application_name $pq_application_name always; # application_name parameter status\n    add_header cipher $pq_cipher always; # cipher ssl attribute\n    add_header client_encoding $pq_client_encoding always; # client_encoding parameter status\n    add_header column_name $pq_column_name always; # column_name result error field\n    add_header compression $pq_compression always; # compression ssl attribute\n    add_header constraint_name $pq_constraint_name always; # constraint_name result error field\n    add_header context $pq_context always; # context result error field\n    add_header datatype_name $pq_datatype_name always; # datatype_name result error field\n    add_header datestyle $pq_datestyle always; # datestyle parameter status\n    add_header db $pq_db always; # database name\n    add_header default_transaction_read_only $pq_default_transaction_read_only always; # default_transaction_read_only parameter status\n    add_header host $pq_host always; # database host name\n    add_header hostaddr $pq_hostaddr always; # database host address\n    add_header in_hot_standby $pq_in_hot_standby always; # in_hot_standby parameter status\n    add_header integer_datetimes $pq_integer_datetimes always; # integer_datetimes parameter status\n    add_header internal_position $pq_internal_position always; # internal_position result error field\n    add_header internal_query $pq_internal_query always; # internal_query result error field\n    add_header intervalstyle $pq_intervalstyle always; # intervalstyle parameter status\n    add_header is_superuser $pq_is_superuser always; # is_superuser parameter status\n    add_header key_bits $pq_key_bits always; # key_bits ssl attribute\n    add_header library $pq_library always; # library ssl attribute\n    add_header message_detail $pq_message_detail always; # message_detail result error field\n    add_header message_hint $pq_message_hint always; # message_hint result error field\n    add_header message_primary $pq_message_primary always; # message_primary result error field\n    add_header options $pq_options always; # options parameter status\n    add_header pid $pq_pid always; # backend pid\n    add_header port $pq_port always; # database port\n    add_header protocol $pq_protocol always; # protocol parameter status\n    add_header schema_name $pq_schema_name always; # schema_name result error field\n    add_header server_encoding $pq_server_encoding always; # server_encoding parameter status\n    add_header server_version $pq_server_version always; # server_version parameter status\n    add_header session_authorization $pq_session_authorization always; # session_authorization parameter status\n    add_header severity $pq_severity always; # severity result error field\n    add_header severity_nonlocalized $pq_severity_nonlocalized always; # severity_nonlocalized result error field\n    add_header source_file $pq_source_file always;# source_file result error field\n    add_header source_function $pq_source_function always; # source_function result error field\n    add_header source_line $pq_source_line always; # source_line result error field\n    add_header sqlstate $pq_sqlstate always; # sqlstate result error field\n    add_header standard_conforming_strings $pq_standard_conforming_strings always; # standard_conforming_strings parameter status\n    add_header statement_position $pq_statement_position always; # statement_position result error field\n    add_header table_name $pq_table_name always; # table_name result error field\n    add_header timezone $pq_timezone always; # timezone parameter status\n    add_header transaction_status $pq_transaction_status always; # transaction status\n    add_header user $pq_user always; # database user\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frekgrpth%2Fngx_pq_module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frekgrpth%2Fngx_pq_module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frekgrpth%2Fngx_pq_module/lists"}