windows 下使用批處理執行 postgresql 命令行操作


1.准備好命令文件 loraserver.sql

create role loraserver_as with login password 'dbpassword';
create role loraserver_ns with login password 'dbpassword';
create database loraserver_as with owner loraserver_as;
create database loraserver_ns with owner loraserver_ns;
\c loraserver_as
create extension pg_trgm;
create extension hstore;
\q

2.寫批處理文件 run.bat

psql 這里使用了絕對路徑,這樣不依賴於環境變量,但需要更改為實際安裝路徑。
后邊的 pause 命令是為了讓雙擊運行在執行完之后能停留在命令窗口,以便看到輸出的運行結果。

"C:\Program Files\PostgreSQL\9.6a\bin\psql.exe" -U postgres < loraserver.sql

% The purpose of the command below is to make the window not close! %
pause

3.執行批處理文件

這一步,還是要輸入密碼:

然后,就會自動執行命令文件中的操作了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM