{"id":14973865,"url":"https://github.com/nikolays/postgres_dba","last_synced_at":"2025-05-14T20:07:13.894Z","repository":{"id":27809500,"uuid":"90880856","full_name":"NikolayS/postgres_dba","owner":"NikolayS","description":"The missing set of useful tools for Postgres DBAs and all engineers","archived":false,"fork":false,"pushed_at":"2024-10-23T16:39:17.000Z","size":298,"stargazers_count":1162,"open_issues_count":11,"forks_count":127,"subscribers_count":48,"default_branch":"master","last_synced_at":"2025-04-06T12:05:17.409Z","etag":null,"topics":["dba","postgres","postgres-dba","postgres-server","postgresql","psql"],"latest_commit_sha":null,"homepage":"","language":"PLpgSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NikolayS.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":"2017-05-10T15:38:28.000Z","updated_at":"2025-03-31T22:16:24.000Z","dependencies_parsed_at":"2024-11-15T20:31:20.325Z","dependency_job_id":"00859cc8-0868-479b-ad4a-45929133db01","html_url":"https://github.com/NikolayS/postgres_dba","commit_stats":{"total_commits":306,"total_committers":7,"mean_commits":"43.714285714285715","dds":0.08496732026143794,"last_synced_commit":"9b5762bcc6641a8b08c7b1378414c6c3b9b8aaa8"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikolayS%2Fpostgres_dba","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikolayS%2Fpostgres_dba/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikolayS%2Fpostgres_dba/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikolayS%2Fpostgres_dba/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NikolayS","download_url":"https://codeload.github.com/NikolayS/postgres_dba/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248732486,"owners_count":21152852,"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":["dba","postgres","postgres-dba","postgres-server","postgresql","psql"],"created_at":"2024-09-24T13:49:35.936Z","updated_at":"2025-04-13T15:10:20.518Z","avatar_url":"https://github.com/NikolayS.png","language":"PLpgSQL","readme":"# postgres_dba (PostgresDBA)\nThe missing set of useful tools for Postgres DBA and mere mortals.\n\n:warning: If you have great ideas, feel free to create a pull request or open an issue.\n\n\u003cimg alt=\"Demo\" src=\"https://user-images.githubusercontent.com/1345402/74124060-dbe25c00-4b85-11ea-9538-8d3b67f09896.gif\"\u003e\n\n\n:point_right: See also [postgres-checkup](https://gitlab.com/postgres-ai/postgres-checkup), a tool for automated health checks and SQL performance analysis.\n\n## Questions?\n\nQuestions? Ideas? Contact me: nik@postgres.ai, Nikolay Samokhvalov.\n\n## Credits\n\n**postgres_dba** is based on useful queries created and improved by many developers. Here is incomplete list of them:\n * Jehan-Guillaume (ioguix) de Rorthais https://github.com/ioguix/pgsql-bloat-estimation\n * Alexey Lesovsky, Alexey Ermakov, Maxim Boguk, Ilya Kosmodemiansky et al. from Data Egret (aka PostgreSQL-Consulting) https://github.com/dataegret/pg-utils\n * Josh Berkus, Quinn Weaver et al. from PostgreSQL Experts, Inc. https://github.com/pgexperts/pgx_scripts\n\n## Requirements\n\n**You need to have psql version 10 or newer**, but the Postgres server itself can be older – most tools work with it.\nYou can install postgresql-client library version, say, 12 on your machine and use it to work with Postgres server version 9.6 and older – in this case postgres_dba will work. But you do need to have psql from the latest (version 12) Postgres release.\n\nOn clean Ubuntu, this is how you can get postgresql-client and have the most recent psql:\n```\nsudo sh -c \"echo \\\"deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main\\\" \u003e\u003e /etc/apt/sources.list.d/pgdg.list\"\nwget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -\nsudo apt-get update\nsudo apt-get install -y postgresql-client-12\n```\n\nUsing alternative psql pager called \"pspg\" is highly recommended (but not required): https://github.com/okbob/pspg.\n\n## Installation\nThe installation is trivial. Clone the repository and put \"dba\" alias to your `.psqlrc` file (works in bash, zsh, and csh):\n```bash\ngit clone https://github.com/NikolayS/postgres_dba.git\ncd postgres_dba\nprintf \"%s %s %s %s\\n\" \\\\echo 🧐 🐘 'postgres_dba 6.0 installed. Use \":dba\" to see menu' \u003e\u003e ~/.psqlrc\nprintf \"%s %s %s %s\\n\" \\\\set dba \\'\\\\\\\\i $(pwd)/start.psql\\' \u003e\u003e ~/.psqlrc\n```\n\nThat's it.\n\n## Usage\n\n### Connect to Local Postgres Server\nIf you are running psql and Postgres server on the same machine, just launch psql:\n```bash\npsql -U \u003cusername\u003e \u003cdbname\u003e\n```\n\nAnd type `:dba \u003cEnter\u003e` in psql. (Or `\\i /path/to/postgres_dba/start.psql` if you haven't added shortcut to your `~/.psqlrc` file).\n\n– it will open interactive menu.\n\n### Connect to Remote Postgres Server\nWhat to do if you need to connect to a remote Postgres server? Usually, Postgres is behind a firewall and/or doesn't listen to a public network interface. So you need to be able to connect to the server using SSH. If you can do it, then just create SSH tunnel (assuming that Postgres listens to default port 5432 on that server:\n\n```bash\nssh -fNTML 9432:localhost:5432 sshusername@you-server.com\n```\n\nThen, just launch psql, connecting to port 9432 at localhost:\n```bash\npsql -h localhost -p 9432 -U \u003cusername\u003e \u003cdbname\u003e\n```\n\nAnd type `:dba \u003cEnter\u003e` in psql to launch **postgres_dba**.\n\n### Connect to Heroku Postgres\nJust open psql as you usually do with Heroku:\n```bash\nheroku pg:psql -a \u003cyour_project_name\u003e\n```\n\nAnd then:\n```\n:dba\n```\n\n## How to Extend (Add More Queries)\nYou can add your own useful SQL queries and use them from the main menu. Just add your SQL code to `./sql` directory. The filename should start with some 1 or 2-letter code, followed by underscore and some additional arbitrary words. Extension should be `.sql`. Example:\n```\n  sql/f1_cool_query.sql\n```\n– this will give you an option \"f1\" in the main menu. The very first line in the file should be an SQL comment (starts with `--`) with the query description. It will automatically appear in the menu.\n\nOnce you added your queries, regenerate `start.psql` file:\n```bash\n/bin/bash ./init/generate.sh\n```\n\nNow your have the new `start.psql` and can use it as described above.\n\n‼️ If your new queries are good consider sharing them with public. The best way to do it is to open a Pull Request (https://help.github.com/articles/creating-a-pull-request/).\n\n## Uninstallation\nNo steps are needed, just delete **postgres_dba** directory and remove `\\set dba ...` in your `~/.psqlrc` if you added it.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikolays%2Fpostgres_dba","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikolays%2Fpostgres_dba","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikolays%2Fpostgres_dba/lists"}