Onjsdev

Share


Psql Shell in Postgresql


By onjsdev

Jan 11th, 2024

PSQL is a command-line interface (CLI) tool for interacting with PostgreSQL databases. It allows you to execute SQL commands, write scripts, automate tasks, and view database information.

How To Connect to PSQL Shell

PSQL is included with every PostgreSQL installation. If you have PostgreSQL installed on your machine, simply search for it in your machine's search box by typing 'psql'.

postgresql psql shell

After opening it, you are asked for connection details as shown below:

PSQL shell

After entering connection information and credentials, you will connect to the dafult postgres database with the default user 'postgres'.

Basic commands

Now, you can create a new user, a new database, or execute SQL queries. Additionally, there are a few commands to seamlessly work in the psql shell

  • \l: List databases
  • \c <database_name>: Connect to a database
  • \d: List tables in the current database
  • \dt: List data types
  • \h: Get help on psql commands
  • \q: Quit psql

Conclusion

The PostgreSQL shell (psql) is a important tool for interacting with PostgreSQL databases through the command line.

This guide covers the basic commands to get you started. As you become more familiar with PostgreSQL, you can explore advanced features and options available in the psql shell.

If you want to learn more about Postgresql, then check the following articles:

Thank you for reading