How to import sql file in postgresql using command line?

Syntex:

psql -h localhost -U postgres -p PORT DATABASE < FILE_PATH 

Command:

psql -h localhost -U postgres -p 5432 testdb < C:\Users\Downloads\data.sql

Flags
-U username: username of the database that you want to connect.
-d dbname: name of the database.
-h hostname: name of the host machine on which the Postgresql server running.

  1. Go in bin dir of postgres.