简体   繁体   中英

psql : load query from file and output psql messages to log file

I'm trying to find a one-liner to read query from external file and output psql NOTICEs to a log file. I tried:

psql -h host -d database -U username -f my_sql_file.sql > my_log_file.log

my_sql_file.sql has a multiline anonymous block like:

DO
$$
DECLARE
  stuff 
BEGIN
   RAISE NOTICE '--------- TEST ----------';
END;
$$

The log file outputs the first line of the file: "DO" and nothing else.

The notice gets written to standard error, so redirect that too:

psql -h host -d database -U username -f my_sql_file.sql > my_log_file.log 2>&1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM