Postgresql under windows using a batch execute command line operations

1. Prepare a command file 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. Write a batch file run.bat

psql using an absolute path here, so do not depend on environment variables, but you need to change the actual installation path.
Behind the pause command is to allow double-click to run after executing able to stay in the command window to see the output of the results.

"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. Perform batch file

This step, or to enter a password:

Then, it will automatically execute the operation command file.

Guess you like

Origin www.cnblogs.com/timeddd/p/11237689.html