Execute a script SQL file in PostgreSQL

Run a SQL file using the command line in PostgreSQL

Run the SQL file with the PSQL utility which connects with the PostgreSQL database

psql -h localhost -d Store -U admin -p 5432 -a -q -f C:\script\postgrefile.sql

-h PostgreSQL server IP address
-d database name
-U user name
-p port 
-f path to SQL script
-a all echo
-q quiet

Direct connect with PostgreSQL command utility:

psql -h 127.0.0.1 -d test -u admin
password ******
postgres> \i C:\script\postgresfile.sql
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.