PgCLI Manager is a user-friendly Bash utility that simplifies working with PostgreSQL databases using pgcli.
It allows you to manage connections, track history, and interact with databases through intuitive command-line commands.
- Connection Management: Add, list, edit, and remove database connections effortlessly.
- Smart Alias System:
- Quick connect without 'connect' command when alias mode is enabled
- Default connection support for instant database access
- Automatically connect to a default database if no parameters are provided
- Secure Password Handling: Choose to save passwords or input them securely at runtime.
- History Tracking: Automatically log all connections for quick reference.
- Configuration Backup: Import and export connection settings easily.
- Customizable: Modify default paths and settings in the configuration files.
pgclimust be installed on your system# Using pip pip install pgcli # Or using your system package manager # For Ubuntu/Debian sudo apt-get install pgcli # For MacOS brew install pgcli
- Clone the repository:
git clone https://github.com/Kazilsky/pgcli_manager.git cd pgcli-manager chmod +x pgcli_manager.sh - (Optional) Add an alias for easier usage:
alias pgm="/path/to/pgcli-manager/pgcli_manager.sh" source ~/.bashrc
Alias mode simplifies the connection process by removing the need for the connect command. When enabled:
- Standard Connection:
pgm mydb # Instead of 'pgm connect mydb'
- Default alias provides instant connection to your preferred database without specifying any parameters:
pgm # instead of 'pgm connect [BASE]' - Set Default:
pgm default_alias dev_db # Sets 'dev_db' as default connection - Check Current Default (Coming soon):
pgm default_alias # Shows which connection is currently set as default
When both features are enabled:
- Set up your environment:
pgm alias on # Enable alias mode pgm default_alias dev_db # Set default connection
- Quick access:
pgm prod_db # Connects to prod_db pgm # Connects to default database (dev_db)
- Run the script with one of the following commands:
pgm [command] [arguments]
- You can get acquainted through
pgm helpor by runningpgmwithout arguments.
add NAME DATABASE USER [PASSWORD]: Add a new connectionremove NAME: Remove an existing connectionlist: Show all saved connectionsconnect NAME: Connect to a databasehistory: Show connection historyalias on|off: Enable or disable alias modedefault_alias NAME: Set or show the default aliashelp: Show help message
- Add a new connection (password will be prompted):
pgm add mydb database1 user1
- Connect to a database:
pgm connect mydb
- List all connections:
pgm list
- Enable alias mode:
pgm alias on - Set a default alias:
pgm default_alias mydb
- Host:
localhost - Port:
5432
- Connections are stored in
~/.pgcli_manager/connections.conf - History is stored in
~/.pgcli_manager/history.log - Alias settings are stored in
~/.pgcli_manager/alias.conf
By default, passwords are saved in the configuration file. If you'd prefer to enter the password each time you connect, you can leave it out when adding a new connection. The script will prompt for the password securely during runtime.
If you encounter issues with connecting to the database or any other command, try the following:
- Ensure that
pgcliis installed and working properly. - Double-check your configuration file (
connections.conf) for correctness. - If there are permission issues with configuration files, make sure they are readable and writable.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.