{"id":36530732,"url":"https://github.com/firmfoundation/dbquery","last_synced_at":"2026-01-12T03:00:59.447Z","repository":{"id":181480913,"uuid":"657003180","full_name":"firmfoundation/dbquery","owner":"firmfoundation","description":"API Service for Query Statistics","archived":false,"fork":false,"pushed_at":"2023-07-15T20:41:02.000Z","size":10290,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-06-21T02:10:15.225Z","etag":null,"topics":["analytics","postgresql","query","statistics"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/firmfoundation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-06-22T05:30:13.000Z","updated_at":"2023-06-26T16:13:37.000Z","dependencies_parsed_at":"2024-06-21T01:21:08.434Z","dependency_job_id":null,"html_url":"https://github.com/firmfoundation/dbquery","commit_stats":null,"previous_names":["firmfoundation/dbquery"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/firmfoundation/dbquery","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firmfoundation%2Fdbquery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firmfoundation%2Fdbquery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firmfoundation%2Fdbquery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firmfoundation%2Fdbquery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firmfoundation","download_url":"https://codeload.github.com/firmfoundation/dbquery/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firmfoundation%2Fdbquery/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28332835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"online","status_checked_at":"2026-01-12T02:00:08.677Z","response_time":98,"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":["analytics","postgresql","query","statistics"],"created_at":"2026-01-12T03:00:37.924Z","updated_at":"2026-01-12T03:00:59.438Z","avatar_url":"https://github.com/firmfoundation.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# API Service for Query Statistics\n\nThis is a Golang API service that allows you to connect to any PostgreSQL database and retrieve query statistics. The service supports filtering by query type, pagination, and sorting by slowest or fastest queries. The service is designed to handle high loads of API calls and uses Redis for caching to improve performance.\n\nYou can easily analyze your all query performance and identify areas for optimization with single API call. And with Redis caching, the service can handle high loads of API calls without sacrificing performance.\n## Getting Started\n\nTo run the code, use the following command:\n\ngo run ./cmd/dbquery/app.go\n\n\nBefore using the API service, make sure that the PostgreSQL database you are connecting to has the pg_stat_statements extension loaded correctly. You also need to configure postgresql.conf with shared_preload_libraries = ‘pg_stat_statements’. Additionally, you need to have a local running Redis server.\n\n## Usage\n\nTo use the API service, you can send HTTP requests to the API endpoint with the appropriate parameters. \n\n### Connecting any PostgreSQL Database\n\nTo connect to any PostgreSQL database, use the following endpoint:\n\nPOST /connect\n\nyou will get `database_instance_id` and you need it for query api. \n\nThe request body should be in JSON format and include the following fields:\n\n```\n{\n    \"DBHost\": \"127.0.0.1\",\n    \"DBUserName\": \"postgres\",\n    \"DBUserPassword\": \"password123\",\n    \"DBName\": \"dbname\",\n    \"DBPort\": \"5432\"\n}\n```\n\n### Retrieve Query Statistics\n\nTo retrieve query statistics, use the following endpoint:\n\nGET /querystate?page=1\u0026page_size=50\u0026sort=slowest\u0026filter_query=all\u0026database_instance_id=d96fceb7-c576-404d-b8ab-c46db4fd1422\n\n\nYou can use query parameters to filter and paginate the results. The available query parameters are:\n\n- page: The page number to retrieve (default is 1).\n- page_size: The number of query statistics to retrieve per page (default is 50).\n- sort: The sorting order for the query statistics. You can sort by slowest or fastest (default is slowest).\n- filter_query: The query type to filter by. You can filter by all, select, insert, update, or delete (default is all).\n- database_instance_id: The database connection. You will get this id from database connect api.\n\n## Testing\n\nTo run the tests, you will need to have Redis and PostgreSQL databases running. You can use Docker to easily set up these databases:\n\n# Start a Redis container\ndocker run --name my-redis -d -p 6379:6379 redis\n\n# Start a PostgreSQL container\ndocker run --name my-postgres -e POSTGRES_PASSWORD=password123 -d -p 5432:5432 postgres\n\n\nOnce the databases are running, you can run the tests with the following command:\n\ngo test ./...\n## Conclusion\n\nThis API service provides a fast and efficient way for clients to retrieve query statistics from any PostgreSQL database. With support for filtering, pagination, and sorting, clients can easily analyze their query performance and identify areas for optimization. And with Redis caching, the service can handle high loads of API calls without sacrificing performance.\n\n## CI-CD Jenkies \n\nJenkins pipeline is configured to build and deploy the application. \n\n## Screenshot\n\n![image](https://github.com/firmfoundation/dbquery/assets/25494022/efdf7f6d-d2a7-4dbf-b204-3ec901edbb06)\n\n## To do soon \nfrontend 🤩️","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirmfoundation%2Fdbquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirmfoundation%2Fdbquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirmfoundation%2Fdbquery/lists"}