问题
I am working as a software tester. I want to to test my project locally. So I want to insert the database using the psql command. I tried so many times. I couldn't get to access the login page.
This is what I did:
postgres@naveen-Inspiron-3542:/home/naveen$ psql -U admin docmgr
Password for user admin: psql (9.5.4) Type "help" for help.
docmgr=> psql docmgr -f /var/www/html/docmgr/application/assets/dd/structs/docmgr_21Oct2016.sql -U admin
docmgr-> \dt No relations found.
docmgr-> \dt No relations found.
docmgr-> select * from admin_users;
ERROR: syntax error at or
near "psql" LINE 1: psql docmgr -f
/var/www/html/docmgr/application/assets/dd/st...
^
回答1:
This is wrong:
docmgr=> psql docmgr -f /var/www/html/docmgr/application/assets/dd/structs/docmgr_21Oct2016.sql
You are running psql from within psql but "psql" is not a SQL statement.
You either need to run directly from the command prompt:
postgres@naveen-Inspiron-3542:/home/naveen$ psql -U admin -d docmgr -f /var/www/html/docmgr/application/assets/dd/structs/docmgr_21Oct2016.sql
Or from within psql you need to use the \i command to run a SQL script:
postgres@naveen-Inspiron-3542:/home/naveen$ psql -U admin docmgr
Password for user admin: psql (9.5.4) Type "help" for help.
docmgr=> \i /var/www/html/docmgr/application/assets/dd/structs/docmgr_21Oct2016.sql
来源:https://stackoverflow.com/questions/40214589/how-do-i-run-an-sql-file-in-postgresql-using-a-linux-terminal