This sounds like it should be a very easy thing to do, however, I cannot find ANYWHERE how to do it.
I have a .sql file I am building for an upgrade to my application that alters tables, inserts/updates, etc.
I want to write to the screen after every command finishes.
So, for instance if I have something like:
insert into X...
I want to see something like,
Starting to insert into table X
Finished inserting into table X
Is this possible in Postgres?
There's probably a better way to do it. But if you need to use vanilla SQL, try this:
Via: https://stackoverflow.com/a/18828523/2014857
Depending on what you're doing, I'd be worried about doing a bunch of anonymous code blocks. You might consider storing the above as a function, and passing in whatever value you want logged.
If you're just feeding a big pile of SQL to
psql
then you have a couple options.You could run
psql
with--echo-all
:That and the other "echo everything of this type" options (see the manual) are probably too noisy though. If you just want to print things manually, use
\echo
:So you can say: