0

I am trying to get maintenance query from windows command line psql with COPY statement.(Windows 2012). The query produces maintenance query as output file. After that I wish to import maintenance query (reindex.sql) and execute with a scheduler. But I couldn't find it out why I couldnt execute script. There should be a comma trick which I couldn't solve.

psql -U postgres -c "COPY( SELECT 'REINDEX TABLE "' || schemaname || '"."' || relname || '";'FROM pg_stat_all_tables ORDER BY n_dead_tup DESC)TO 'E:\scripts\maintenance\reindex.sql';"
1
  • 1
    Could you describe "does not work" in some more detail? Commented Oct 25, 2018 at 10:17

1 Answer 1

1

Use format():

psql -U postgres -c ^
"COPY ( ^
SELECT format('REINDEX TABLE %s.%s', schemaname, relname) ^
FROM pg_stat_all_tables ^
ORDER BY n_dead_tup DESC) ^
TO 'E:\scripts\maintenance\reindex.sql'"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.