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"

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
Sign up to request clarification or add additional context in comments.

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.