🧠 PostgreSQL Connection Tools β€” psql vs pg

When you work with PostgreSQL, there are two common ways to connect and interact with your database:

  1. psql β†’ CLI (manual interaction, debugging, admin tasks)
  2. pg β†’ Node.js library (programmatic interaction inside your backend)

βš™οΈ 1. psql β€” Command-line Interface for PostgreSQL

πŸ“˜ What it is:

psql is a terminal-based interactive shell for PostgreSQL.

It comes preinstalled when you install Postgres locally or via Docker.

You can use it to:


πŸ’‘ Typical Usage (Syntax)

psql -h <host> -p <port> -U <username> -d <database>

Example:

psql -h localhost -p 5432 -U postgres -d mydb

or using password inline: