简体   繁体   中英

How to execute *.sql file using psql

I have created an index.sql file which contains index creating script for 95 table

for example

DROP INDEX IF EXISTS gtab03_vrctrlid_idx cascade;
CREATE UNIQUE INDEX gtab03_vrctrlid_idx ON gtab03 USING btree (vrctrlid);

I have consolidated all table's index creating script to a file called index.sql I need to run the entire script at a time, is it possible to execute the index.sql file using psql

这就是你的意思吗?

\i e:/myFolder/index.sql;

Following script worked for me,

psql -U postgres -d mydb -a -f "D:\index.sql" -- Absolute path to .sql file

-U, -a, -f

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM