DEV Community

theBridge2
theBridge2

Posted on • Edited on

PostgreSQL command line psql cheat sheet

Tools Overview

postgres = open source relational database software
psql = command line tool to connect to postgres
pgAdmin = web based tool front end to psql - not discussing here

Image description

This cheat sheet is for psql. Other 3rd party tools exist for connecting to postgres databases. (Dbeaver is a popular choice)

Postgres cmd line tool psql

Official docs
https://www.postgresql.org/docs/current/app-psql.html

Command Description
psql --help list help
psql --username=postgres login to postgres cmd line

When logged in:

Command Description
\list print out list of databases
\c <db name> connect to a certain database
\dt show all tables in current schema
\df list functions of current database
\dv list views of current database
\du list users and roles
\q quit postgres cmd line
SELECT * from mytable; select statement to table

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay