我有一个查询,旨在循环和搜索重复地址,该查询使用 REGEX_REPLACE。我正在尝试在正则表达式上建立索引,就像进行解释一样,并且它使用正则表达式上的过滤器对 user_property 表进行顺序扫描
EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS) with user_detail AS (
SELECT user_id,
max(user_property_value) FILTER (WHERE user_property_type_id = 6 ) AS FIRST_NAME,
max(user_property_value) FILTER (WHERE user_property_type_id = 7 ) AS LAST_NAME,
max(TO_DATE(user_property_value, 'YYYY-MM-DD')) FILTER (WHERE user_property_type_id = 8 ) AS DOB,
max(user_property_value) FILTER (WHERE user_property_type_id = 33 ) AS BIRTH_NUMBER
FROM PUBLIC.user_property cp
JOIN PUBLIC.user c using (user_id)
WHERE c.user_group_id= '38'
AND cp.user_property_is_active
GROUP BY user_id
),
duplicate as (
SELECT COALESCE(MAX(
CASE WHEN REGEXP_REPLACE((address_line1), E'\\_|\\W','','g') = 'Flat …Run Code Online (Sandbox Code Playgroud) I have recently implemented an Agent Job which checks SQL Server every 10mins for any long running queries and if detected it will send out a mail to recipients with the information. However since putting this in, I notice alot of the below query and wonder if this is something I should be concerned about:
WAITFOR(RECEIVE conversation_handle, service_contract_name, message_type_name, message_body FROM ExternalMailQueue INTO @msgs), TIMEOUT @rec_timeout
Run Code Online (Sandbox Code Playgroud)
从数据库邮件中了解它,等待信息是 (1x: 62093ms)BROKER_RECEIVE_WAITFOR 但我是否需要担心或只是将其从警报中排除。
通过 sp_whoisactive 查看可以看到 open_transaction 计数为 1,状态为挂起。
任何帮助表示赞赏。
我正在尝试在生产中同时创建索引。\d然而,这样做时,通过查看时的索引会显示INVALID。
为什么会这样呢?以前从未见过这种情况发生。
尝试过重新创建,但仍然遇到同样的问题:
指数:
create index concurrently idx_wallet_customer_id_credit_stake_expires on wallet (customer_id,wallet_credit_stake,wallet_expires)
where wallet_closed is null and wallet_staked is null;
Run Code Online (Sandbox Code Playgroud) 目前,我们的数据库服务器中有一个大约有 20 列(其中一列是 timestamptz 数据类型)的表,该表有 8.34 亿行。就大小而言,这是一个很大的表(大约 250GB(包括索引等)。
我想找到最有效和最好的方法来删除超过 2 年的旧数据,但如果我们需要它用于报告目的,也可以定期保留这些数据,该表也有 FK 约束。
处理这个问题的最佳方法是什么?我们希望能够在需要时查看这些数据。可能位于也可能不在同一服务器上。
最好首先运行选择数据的 COPY
COPY (SELECT * FROM TABLENAME WHERE CAST((timecreated_on AT TIME ZONE 'GMT') AS date) > DATE '2020-01-01 00:00:01') TO '/path/to/a/dump/file';
Run Code Online (Sandbox Code Playgroud)
那么删除表中的数据呢?
DELETE FROM TABLENAME where CAST((timecreated_on AT TIME ZONE 'GMT') AS date) > DATE '2020-01-01 00:00:01'
Run Code Online (Sandbox Code Playgroud)
我只是在寻找一种方法,这是一个自动化的过程,我可以通过 Linux 服务器上的 cronjob 安排每年之后删除超过 1 年的数据。
知道这可能不是最好的方法,但需要查看如何管理 FK 键约束,我是否会删除它们并重新应用,这可能会导致数据完整性问题?
任何帮助深表感谢。
postgresql ×3
index ×2
archive ×1
concurrency ×1
delete ×1
regex ×1
senddbmail ×1
sql-server ×1