We can run SQL commands in a file from the command line and also when we are connected to a database.

Command line

_$: psql -U user -d database-devel -f /path/to/file.sql [--single-transaction]

Database

_$: psql -U user database-devel
database-devel=# \i /path/to/file.sql