what is the equivalent of psql for other database technos?
- User
what is the equivalent of psql for other database technos?
Assistant
what is the equivalent of psql for other database technos?
Of course! This is an excellent question. psql is often considered the gold standard for command-line interfaces (CLIs) due to its power, interactivity, and introspection capabilities.
The short answer is that nearly every major database has its own native command-line client, which serves as the equivalent of psql.
Here is a breakdown of the psql equivalents for other popular database technologies.
These are the most direct comparisons to PostgreSQL.
| Database | Primary CLI Tool | Key Characteristics & Comparison |
|---|---|---|
| MySQL | mysql | Very similar to psql in basic function. You connect and run SQL queries. Meta-commands use keywords instead of backslashes (e.g., SHOW TABLES; instead of \dt, \s for status). |
| MariaDB | mariadb (or mysql) | MariaDB is a fork of MySQL, and its CLI is a compatible, drop-in replacement for the mysql client. It functions almost identically. |
| Microsoft SQL Server | sqlcmd & mssql-cli | sqlcmd is the traditional, script-oriented utility. It's powerful but less interactive. mssql-cli is the modern, open-source equivalent. It was built to feel like psql and mycli, with auto-completion and syntax highlighting, making it the true spiritual successor. |
| Oracle Database | SQL*Plus & SQLcl | SQL*Plus is the classic, venerable CLI for Oracle. It's extremely powerful but has a famously arcane syntax. SQLcl (SQL Command Line) is the modern, Java-based replacement. It's much more user-friendly, with features like command history, inline editing, and tab completion, bringing it closer to the psql experience. |
| SQLite | sqlite3 | A simple, file-based database, its CLI is equally straightforward. It supports both SQL statements and special "dot-commands" (e.g., .tables, .schema) that are analogous to psql's backslash commands. |
For NoSQL databases, the CLI is often called a "shell" and may not use SQL. The interaction is based on the database's native query language or API.
| Database | Primary CLI Tool | Key Characteristics & Interaction Style |
|---|---|---|
| MongoDB | mongosh | This is the modern MongoDB Shell. Instead of SQL, you write JavaScript commands to interact with the database (e.g., db.collection.find({name: "Alice"})). It offers syntax highlighting, intelligent autocompletion, and is a huge improvement over the legacy mongo shell. |
| Redis | redis-cli | A very direct and fast CLI. You type Redis commands exactly as you would use them in an application (e.g., SET mykey "hello", GET mykey, HGETALL user:1000). It’s more of a direct command executor than an interactive shell like psql. |
| Cassandra | cqlsh | The Cassandra Query Language Shell. It's designed to feel very much like a SQL client. You use CQL (Cassandra Query Language), which looks very similar to SQL (e.g., SELECT * FROM users;, DESCRIBE KEYSPACES;). It offers tab completion and is quite user-friendly. |
| Elasticsearch | (none) - typically curl | Elasticsearch does not have a dedicated, interactive CLI in the same way. Its primary interface is a REST API. Therefore, the most common "CLI" for interacting with it is a standard command-line HTTP client like curl or HTTPie. (e.g., curl -X GET "localhost:9200/_cat/indices?v"). |
For developers who work with many different databases, using a universal CLI tool can be more efficient than learning each native client. These tools often aim to replicate the best features of psql for other databases.
| Universal Tool | Supported Databases | Description |
|---|---|---|
| usql | PostgreSQL, MySQL, SQL Server, Oracle, SQLite, and many more. | An open-source CLI written in Go, its explicit goal is to be a universal client with a user experience that is highly consistent with psql, including its backslash commands. |
| DBeaver (CLI) | Virtually any database with a JDBC driver. | The popular GUI database tool DBeaver also has a command-line version (dbeaver-cli) for executing scripts and exporting data, though it's less focused on interactive sessions. |
| mycli / pgcli | MySQL / PostgreSQL | These aren't universal, but they are "souped-up" versions of their respective native CLIs, adding powerful features like smart auto-completion and syntax highlighting. mssql-cli was inspired by these. |
| Database Technology | Primary CLI Tool(s) | Typical "Show Tables" Command |
|---|---|---|
| PostgreSQL | psql | \dt |
| MySQL | mysql | SHOW TABLES; |
| MariaDB | mariadb | SHOW TABLES; |
| MS SQL Server | sqlcmd / mssql-cli | SELECT name FROM sys.tables; |
| Oracle | SQL*Plus / SQLcl | SELECT table_name FROM user_tables; |
| SQLite | sqlite3 | .tables |
| MongoDB | mongosh | show collections |
| Cassandra | cqlsh | DESCRIBE TABLES; |
| Redis | redis-cli | KEYS * (Use with caution on prod!) |
| Elasticsearch | curl | curl "localhost:9200/_cat/indices?v" |