在Ansible上使用PSQL脚本检测交易中的错误
有以下脚本(
BEGIN;
SET client_min_messages = warning;
\COPY foo_table FROM 'foo.csv' csv header DELIMITER ';';
\COPY bar_table FROM 'bar.csv' csv header DELIMITER ';';
COMMIT;
。
我们
- name: 'Restore SQL dump(s) on database(s)'
become: yes
become_user: 'postgres'
postgresql_db:
name: 'db'
target: 'script.sql'
state: 'restore'
脚本
We have the following script (script.sql):
BEGIN;
SET client_min_messages = warning;
\COPY foo_table FROM 'foo.csv' csv header DELIMITER ';';
\COPY bar_table FROM 'bar.csv' csv header DELIMITER ';';
COMMIT;
We launch this script in an ansible playbook with
community.postgresql.postgresql_db
- name: 'Restore SQL dump(s) on database(s)'
become: yes
become_user: 'postgres'
postgresql_db:
name: 'db'
target: 'script.sql'
state: 'restore'
How can we detect if the transaction fail with a rollback to get an error on the deployment ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
常见的方法是在psql命令行上使用
-v on_error_stop = on
,或者在sql脚本中使用 on_error_stop on 。根据 documentation> documentation :
The common way is to use
-v ON_ERROR_STOP=on
on psql command line, or alternatively\set ON_ERROR_STOP on
in the SQL script.According to the documentation: