我们维护一个用 PostgreSQL 和 python 实现的大型数据仓库。我们所做的一种非常常见的模式是进行更新插入,并在更新时进行记录。我们有一些独特的键my_key
和值,例如my_uuid, my_text, my_int, my_date
。如果给定的任何这些值发生变化,my_key
我们希望更新该行。没关系,我们有一个运行良好的模式:
insert into my_table (
my_key,
my_uuid,
my_text,
my_int,
my_date
)
select
some_key,
some_uuid,
some_text,
some_int,
some_date
from some_table
on conflict (my_key) do update set
some_uuid = excluded.some_uuid,
some_text = excluded.some_text,
some_int = excluded.some_int,
some_date = excluded.some_date,
update_timestamp = now()
where
coalesce(my_table.some_uuid, uuid_nil()) <> coalesce(excluded.some_uuid, uuid_nil())
or coalesce(my_table.some_text, '') <> coalesce(excluded.some_text, '')
or coalesce(my_table.some_int, -1) <> coalesce(excluded.some_int, -1)
or coalesce(my_table.some_date, '3000-01-01'::date) <> coalesce(excluded.some_date, '3000-01-01'::date)
Run Code Online (Sandbox Code Playgroud)
最后一个on conflict …
我们的 PostgreSQL 数据库之一中有一些大型临时表/临时表。其中的数据可以在数据库恢复后从其他数据库自动重新生成,并且不是业务关键型数据。使用 Barman 备份时有没有办法忽略这些表?它们都在一个模式中。
这是为了减少恢复时间并节省空间。
也许我们可以使用某种持久临时表?表空间?
我们有这些表是因为我们做 ETL 时很方便。但不被任何应用程序或客户端使用。
还有其他替代方法可以做类似的事情吗?
我读过的一些文档: