-
Notifications
You must be signed in to change notification settings - Fork 0
postgres
Pedro Felix edited this page Mar 1, 2020
·
1 revision
Some notes on using PostgreSQL and the psql
command line interface.
-
psql
is a command line tool that can be used to:- Connect to a PostgreSQL server.
- Execute SQL commands on that server.
- Execute scripts from the command line.
-
Use
psql <database> -h <host> -U <username>
to create an interactive shell.- The password can be defined on the
PGPASSWORD
environment variable. - The user name can be defined on the
PGUSER
environment variable.
- The password can be defined on the
-
Use `psql -f <script_file> to execute a script.
-
The following commands are available inside the
psql
interactive shell.-
\l
lists all databases. -
\c
connects to a database. -
\d
lists all relations (e.g. tables). -
\i
executes a script. -
\q
exits the interactive shell.
-
-
SQL commands can be executed directly in the interactive shell, ended with ';'.