Need help with postgres_dba?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

576 Stars 69 Forks BSD 3-Clause "New" or "Revised" License 345 Commits 9 Opened issues


The missing set of useful tools for Postgres DBAs and all engineers

Services available


Need anything else?

Contributors list


postgres_dba (PostgresDBA)

The missing set of useful tools for Postgres DBA and mere mortals.

:warning: If you have great ideas, feel free to create a pull request or open an issue.


:point_right: See also postgres-checkup, a tool for automated health checks and SQL performance analysis.


Questions? Ideas? Contact me: [email protected], Nikolay Samokhvalov.


postgres_dba is based on useful queries created and improved by many developers. Here is incomplete list of them: * Jehan-Guillaume (ioguix) de Rorthais * Alexey Lesovsky, Alexey Ermakov, Maxim Boguk, Ilya Kosmodemiansky et al. from Data Egret (aka PostgreSQL-Consulting) * Josh Berkus, Quinn Weaver et al. from PostgreSQL Experts, Inc.


You need to have psql version 10 or newer, but the Postgres server itself can be older – most tools work with it. You 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.

On clean Ubuntu, this is how you can get postgresql-client and have the most recent psql:

sudo sh -c "echo \"deb `lsb_release -cs`-pgdg main\" >> /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-client-12

Using alternative psql pager called "pspg" is highly recommended (but not required):


The installation is trivial. Clone the repository and put "dba" alias to your

file (works in bash, zsh, and csh):
git clone
cd postgres_dba
echo '\\echo 🧐 🐘 postgres_dba 6.0 installed. Use ":dba" to see menu' >> ~/.psqlrc
printf "%s %s %s %s\n" \\set dba \'\\\\i $(pwd)/start.psql\' >> ~/.psqlrc

That's it.


Connect to Local Postgres Server

If you are running psql and Postgres server on the same machine, just launch psql:

psql -U  

And type

in psql. (Or
\i /path/to/postgres_dba/start.psql
if you haven't added shortcut to your

– it will open interactive menu.

Connect to Remote Postgres Server

What 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:

ssh -fNTML 9432:localhost:5432 [email protected]

Then, just launch psql, connecting to port 9432 at localhost:

psql -h localhost -p 9432 -U  

And type

in psql to launch postgres_dba.

Connect to Heroku Postgres

Just open psql as you usually do with Heroku:

heroku pg:psql -a 

And then:


How to Extend (Add More Queries)

You can add your own useful SQL queries and use them from the main menu. Just add your SQL code to

directory. The filename should start with some 1 or 2-letter code, followed by underscore and some additional arbitrary words. Extension should be
. Example:
– 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.

Once you added your queries, regenerate

/bin/bash ./init/

Now your have the new

and can use it as described above.

‼️ If your new queries are good consider sharing them with public. The best way to do it is to open a Pull Request (


No steps are needed, just delete postgres_dba directory and remove

\set dba ...
in your
if you added it.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.