PostgreSQL psql

created:

updated:

tags: postgresql database

psql

psql is a terminal-based front-end to PostgreSQL. It enables you to type in queries interactively, issue them to PostgreSQL, and see the query results. Alternatively, input can be from a file or from command line arguments. In addition, psql provides a number of meta-commands and various shell-like features to facilitate writing scripts and automating a wide variety of tasks.

Options

-d dbname (–dbname=dbname)

Specifies the name of the database to connect to.

psql -d database_abc

-f filename (–file=filename)

Read commands from the file filename, rather than standard input. This option can be combined in any order with the -c option.

-U username (–username=username)

Connect to the database as the user username instead of the default. (You must have permission to do so, of course.)

psql -U db_user

References