2

Hello expert I want to refresh materialized view in postgresql via batch file. I don't have any idea how to connect postgresql database via batch file. I have to run following query via batch file - "REFRESH MATERIALIZED VIEW deposit.mv_transaction_view"

asked Nov 23, 2017 at 4:15

1 Answer 1

3

Update: based on comments, filled in all the parameters required to connect to a database "planet" with user, port and password information. The quotes are really for the shell, for easy replacement.

You can do this with psql.

psql -Upostgres -p5432 -c "REFRESH MATERIALIZED VIEW deposit.mv_transaction_view" planet

and put that in the batch file or script or whatever.

With this in your ~/.pgpass file:

localhost:5432:planet:postgres:pes

or variants thereof. You can also use

*:*:*:postgres:pes
answered Nov 23, 2017 at 5:06

5 Comments

I need the full answer with example. how to connect with database.
This is the full example. On my machine this works psql -c "select version()" You can add --host=hostname, --port=portnum, --username=username and dbname as standalone parameter. Put your psasword in ~/.pgpass.
If you don't mind i need the complete script for batch file example- i have a database "planet", user="postgres", password="pes", port="5432" and i want to run "REFRESH MATERIALIZED VIEW deposit.mv_transaction_view" query.
Stack overflow is not an excuse not to read the manual. However, I'll update the answer.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.