pgcli is a Python package that serves as an interactive command-line interface for the PostgreSQL database server. It enhances the standard PostgreSQL experience with features like auto-completion, syntax highlighting, smart-completion, and extensive support for psql-like back-slash commands. The project is actively maintained with a consistent release cadence, with version 4.4.0 being the current stable release.
pip install pgcliNo compatibility data collected yet for this library.
Connect to a local PostgreSQL database named 'my_database' using the current system username. You will be prompted for a password if required. Alternatively, use a connection URL: `pgcli postgresql://user:password@host:port/dbname`.
Upgrade your Python environment to Python 3.9 or newer. Ensure your virtual environment uses a supported Python version.
Install the necessary system packages, e.g., `sudo apt-get install python3-dev libpq-dev` (Debian/Ubuntu) or `sudo yum install python3-devel postgresql-devel` (RHEL/CentOS/Fedora) before running `pip install pgcli`.
Ensure the proxy's root certificate is installed in your system's trust chain. Verify outbound firewall rules allow PostgreSQL traffic (port 5432 by default). Consider using an SSH tunnel if direct access is restricted.
Always set `.pgpass` file permissions strictly (e.g., `chmod 600`). Avoid storing production passwords directly in shell history. Use secure credential management systems or rely on interactive password prompts where appropriate.
Utilize `pgcli`'s configuration options like `destructive_statements_require_transaction` and `destructive_warning` (introduced in 4.4.0) to prompt for confirmation before executing potentially damaging queries.
Ensure the PostgreSQL server is running, verify the host and port are correct (e.g., `pgcli -h <host> -p <port> -U <user> <dbname>`), and check any local or network firewalls that might be blocking port 5432 (or your configured port).
Install the PostgreSQL development libraries for your operating system (e.g., `sudo apt-get install libpq-dev python3-dev` on Debian/Ubuntu, `sudo yum install postgresql-devel python3-devel` on RHEL/CentOS, or `brew install postgresql` and `xcode-select --install` on macOS), then reinstall pgcli with `pip install --no-cache-dir pgcli`.
Verify the username and password are correct. You can explicitly provide them using `pgcli -U <correct_username> -W <dbname>` (which will prompt for a password) or ensure your `~/.pgpass` file is correctly configured for passwordless access.
First, ensure pgcli is installed by running `pip install pgcli`. If it is, locate the `pgcli` executable (e.g., `which pgcli` or `find / -name pgcli` for a global search) and add its directory to your system's PATH environment variable. Alternatively, use `python3 -m pgcli` to run it directly via the Python module.
Install the server's root SSL certificate into your system's trust store. If using a proxy, import the proxy's root certificate. Alternatively, for testing, you might be able to disable SSL verification with an option in pgcli's configuration or connection string (though not recommended for production).