{"id":28693331,"url":"https://github.com/matteogioioso/serverless-pgx","last_synced_at":"2026-02-25T11:35:59.634Z","repository":{"id":57555293,"uuid":"311258404","full_name":"MatteoGioioso/serverless-pgx","owner":"MatteoGioioso","description":"Golang module for managing PostgreSQL connections at serverless scale.","archived":false,"fork":false,"pushed_at":"2021-05-22T03:02:50.000Z","size":32,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-15T07:42:22.822Z","etag":null,"topics":["aws","aws-lambda","go","golang","pgx","postgres","postgresql","serverless"],"latest_commit_sha":null,"homepage":"","language":"Go","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/MatteoGioioso.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}},"created_at":"2020-11-09T07:35:46.000Z","updated_at":"2024-06-08T14:21:27.000Z","dependencies_parsed_at":"2022-09-14T11:01:33.265Z","dependency_job_id":null,"html_url":"https://github.com/MatteoGioioso/serverless-pgx","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/MatteoGioioso/serverless-pgx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatteoGioioso%2Fserverless-pgx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatteoGioioso%2Fserverless-pgx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatteoGioioso%2Fserverless-pgx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatteoGioioso%2Fserverless-pgx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatteoGioioso","download_url":"https://codeload.github.com/MatteoGioioso/serverless-pgx/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatteoGioioso%2Fserverless-pgx/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259783084,"owners_count":22910304,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["aws","aws-lambda","go","golang","pgx","postgres","postgresql","serverless"],"created_at":"2025-06-14T08:13:00.102Z","updated_at":"2026-02-25T11:35:59.603Z","avatar_url":"https://github.com/MatteoGioioso.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![GitHub](https://img.shields.io/github/license/MatteoGioioso/serverless-pgx)\n\n# PGX Serverless\nPgx-serverless is a wrapper for **[pgx](https://github.com/jackc/pgx)** go package.\nIt is heavily inspired by Jeremy Daly's **[serverless-mysql](https://github.com/jeremydaly/serverless-mysql)** Nodejs package.\n\n### Why I need this module?\nIn a serverless application a function can scale almost \"infinitely\" by creating separate container instances \nfor each concurrent user. \nEach container can correspond to a database connection which, for performance purposes, is left opened for further\nre-utilization. If we have a sudden spike of concurrent traffic, the available connections can be quickly maxed out\nby other competing functions.\nIf we reach the max connections limit, Postgres will automatically reject any frontend trying to connect to its backend.\nThis can cause heavy disruption in your application.\n\n### What does it do?\nPgx-serverless adds a connection management component specifically for FaaS based applications.\nBy calling the method `.Clean()` at the end of your functions, the module will constantly monitor the status of all\nthe processes running in the PostgreSQL backend and then, based on the configuration provided, \nwill garbage collect the \"zombie\" connections.\nIf the client fails to connect with `\"sorry, too many clients already\"` error, the module will retry\nusing trusted backoff algorithms.\n\n\u003e **NOTE:** This module *should* work with any PostgreSQL server. \nIt has been tested with AWS's RDS Postgres, Aurora Postgres, and Aurora Serverless.\n\nFeel free to request additional features and contribute =)\n\n## Install\n\n```\ngithub.com/MatteoGioioso/serverless-pgx/slsPgx\n```\n\n## Usage\n\nDeclare the ServerlessClient outside the lambda handler\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/MatteoGioioso/serverless-pgx/slsPgx\"\n\t\"github.com/aws/aws-lambda-go/events\"\n\t\"github.com/aws/aws-lambda-go/lambda\"\n\t\"os\"\n)\n\nvar (\n\tserverlessClient = slsPgx.New(slsPgx.SlsConnConfigParams{\n\t\tDebug: slsPgx.Bool(true),\n\t})\n\tuser = os.Getenv(\"DB_USER\")\n\tpassword = os.Getenv(\"DB_PASSWORD\")\n\thost = os.Getenv(\"DB_HOST\")\n\tdb = os.Getenv(\"DB_NAME\")\n\tconnectionString = fmt.Sprintf(\"postgres://%v:%v@%v:5432/%v?sslmode=disable\", user, password, host, db)\n)\n\nfunc function(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {\n\tif err := serverlessClient.Connect(context.Background(), connectionString); err != nil {\n\t\treturn events.APIGatewayProxyResponse{}, err\n\t}\n\n\trows, err := serverlessClient.Query(context.Background(), \"SELECT 1+1 AS result\")\n\tif err != nil {\n\t\treturn events.APIGatewayProxyResponse{}, err\n\t}\n\n\tfor rows.Next() {\n\t\tvar res int\n\t\tif err := rows.Scan(\u0026res); err != nil {\n\t\t\treturn events.APIGatewayProxyResponse{}, err\n\t\t}\n\t\t\n\t\tfmt.Println(res)\n\t}\n    \n\tif _, err := serverlessClient.Clean(context.Background()); err != nil {\n\t\treturn events.APIGatewayProxyResponse{}, err\n\t}\t\n\n\treturn events.APIGatewayProxyResponse{\n\t\tStatusCode:        200,\n\t\tBody:              \"Done\",\n\t}, nil\n}\n\nfunc main() {\n\tlambda.Start(function)\n}\n\n\n```\n\n### Currently under development\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatteogioioso%2Fserverless-pgx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatteogioioso%2Fserverless-pgx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatteogioioso%2Fserverless-pgx/lists"}