首页 > 解决方案 > 如何将新数据附加到 PostgreSQL 中的日志文件

问题描述

我正在将 oracle 代码迁移到 postgresql,我需要将查询附加到现有日志文件。

基本上我想要在 PostgreSQL 中相当于 oracle 命令“SPOOL test.log APPEND”。有没有办法做到这一点?

我尝试使用 \o 或 \o+ 将新数据附加到日志文件或在 PostgreSQL 中复制,但它会覆盖日志文件。

我的代码是这样的:

甲骨文:

spool test.log
select  uid from users where uid='1111';
spool off

select sysdate from dual;   
//other business logic code
                                                      -
spool test.log append
select balance from balances where uid='1111';
spool off

PostgreSQL:

\o test.log
select  uid from users where uid='1111';
\o

select current_date;  
//other business logic code
                                                       -
\o test.log  
select balance from balances where uid='1111';
\o

我希望 \o 块中的两个查询附加到 PostgreSQL 中的同一个文件。

标签: postgresqldatabase-migrationplpgsql

解决方案


你可以使用

\o | cat >> test.log

在 UNIX 平台上。


推荐阅读