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
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
5 Comments
Stream
I need the full answer with example. how to connect with database.
Johann Oskarsson
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.Stream
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.
Johann Oskarsson
Stack overflow is not an excuse not to read the manual. However, I'll update the answer.
@JharanaGharti: stackoverflow.com/questions/15359348/… and stackoverflow.com/q/6405127/330315