Friday, 29 May 2020

how to execute .sql files in postgres database

Just put it on the command line after psql:

psql example.sql

psql will take the file and run each line to the server.

If the server is not running on your computer, you will need to specify the hostname to the computer and a username to log into the server with:

psql -h server.postgres.com -U username example.sql --password

To send multiple files, just list them all:

psql example1.sql example2.sql example3.sql

No comments:

Post a Comment