HomeMogDBMogDB StackUqbar
v3.1

Documentation:v3.1

Supported Versions:

Other Versions:

pgcli

pgcli is a command line interface for Postgres with auto-completion and syntax highlighting, which is also suitable for MogDB.

Source: https://github.com/dbcli/pgcli


Install

sudo pip3 install pgcli

For detailed installation steps for different OS, please refer to the pgcli home page: http://pgcli.com

After the installation is complete, you can use the help command to view help information.

[root@mogdb-kernel-0004 ~]# pgcli --help
Usage: pgcli [OPTIONS] [DBNAME] [USERNAME]

Options:
  -h, --host TEXT            Host address of the postgres database.
  -p, --port INTEGER         Port number at which the postgres instance is
                             listening.
  -U, --username TEXT        Username to connect to the postgres database.
  -u, --user TEXT            Username to connect to the postgres database.
  -W, --password             Force password prompt.
  -w, --no-password          Never prompt for password.
  --single-connection        Do not use a separate connection for completions.
  -v, --version              Version of pgcli.
  -d, --dbname TEXT          database name to connect to.
  --pgclirc FILE             Location of pgclirc file.
  -D, --dsn TEXT             Use DSN configured into the [alias_dsn] section
                             of pgclirc file.
  --list-dsn                 list of DSN configured into the [alias_dsn]
                             section of pgclirc file.
  --row-limit INTEGER        Set threshold for row limit prompt. Use 0 to
                             disable prompt.
  --less-chatty              Skip intro on startup and goodbye on exit.
  --prompt TEXT              Prompt format (Default: "\u@\h:\d> ").
  --prompt-dsn TEXT          Prompt format for connections using DSN aliases
                             (Default: "\u@\h:\d> ").
  -l, --list                 list available databases, then exit.
  --auto-vertical-output     Automatically switch to vertical output mode if
                             the result is wider than the terminal width.
  --warn [all|moderate|off]  Warn before running a destructive query.
  --help                     Show this message and exit.

Example of Connecting MogDB

Switch to the user omm through the su - omm command, and then run pgcli -d postgres -p 26000 to connect to MogDB.

[root@mogdb-kernel-0004 ~]# su - omm
Last login: Wed Feb 16 15:31:37 CST 2022 on pts/1
[omm@mogdb-kernel-0004 ~]$ pgcli -d postgres -p 26000
Server: PostgreSQL 9.2.4
Version: 3.3.1
Home: http://pgcli.com
postgres> \l
+-----------+---------+----------+-------------+-------------+-------------------+
| Name      | Owner   | Encoding | Collate     | Ctype       | Access privileges |
|-----------+---------+----------+-------------+-------------+-------------------|
| postgres  | omm     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | <null>            |
| template0 | omm     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/omm            |
|           |         |          |             |             | omm=CTc/omm       |
| template1 | omm     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/omm            |
|           |         |          |             |             | omm=CTc/omm       |
+-----------+---------+----------+-------------+-------------+-------------------+
SELECT 3
Time: 0.020s
postgres>
Copyright © 2011-2024 www.enmotech.com All rights reserved.