How to execute/run a .sql file in PostgreSQL 9.2.6 + CentOs

centos-6postgresql

I would like to know how to execute a .sql file in PostgreSQL.
I'm using CentOs 6.4.

I have created a database and just need to run a script given to me to create tables.

Thanking you in advance.

Best Answer

Use psql:

psql -f thefile.sql targetdatabase

You may need to specify additional parameters, like username to connect as, host to connect to, etc.