Connect to a database from the command-line use
$ psql --user $USER --database $YOUR_DB
psql shell, you have access to a series of special commands.
- Connect to given database.
\d name Describe table, view, sequence, or index.
- List schemas available in current database.
- List relations in schema.
- Get help for given SQL command.
- List availables databases.
- Get help for available psql commands (
- Execute the given command in the operating system's shell.
In order to avoid typing too many parameters when launching
psql from the command line, you can configure default values. By all means, I strongly recommend not to store your password without second thoughts. For storing defaults, there are three options. The first is the use of environment variables.
export PGHOST=localhost export PGPORT=5433 export PGUSER=... export PGPASSWORD=... export PGDATABASE=...
Alternatively, you could use a
.pgpass file using the following format.
Finally, you can use the
.pg_service.conf file which uses an ini like format.
[example] host=localhost port=5432 dbname=... user=... password=...