improve tx_history_txid checks

This commit is contained in:
Michael Hoennig 2024-08-27 20:13:27 +02:00
parent 2f198664fa
commit 38121ad3dd

View File

@ -21,16 +21,26 @@ create or replace function tx_history_txid()
language plpgsql as $$
declare
historicalTxIdSetting text;
historicalTimestampSetting text;
historicalTxId xid8;
historicalTimestamp timestamp;
begin
select current_setting('hsadminng.tx_history_txid', true) into historicalTxIdSetting;
raise notice 'tx_history_txid(): historicalTxIdSetting=%', historicalTxIdSetting;
select coalesce(current_setting('hsadminng.tx_history_txid', true), '') into historicalTxIdSetting;
select coalesce(current_setting('hsadminng.tx_history_timestamp', true), '') into historicalTimestampSetting;
if historicalTxIdSetting > '' and historicalTimestampSetting > '' then
raise exception 'either hsadminng.tx_history_txid or hsadminng.tx_history_timestamp must be set, but both are set: (%, %)',
historicalTxIdSetting, historicalTimestampSetting;
end if;
if historicalTxIdSetting = '' and historicalTimestampSetting = '' then
raise exception 'either hsadminng.tx_history_txid or hsadminng.tx_history_timestamp must be set, but both are unset or empty: (%, %)',
historicalTxIdSetting, historicalTimestampSetting;
end if;
-- just for debugging / making sure the function is only called once per query
-- raise notice 'tx_history_txid() called with: (%, %)', historicalTxIdSetting, historicalTimestampSetting;
if historicalTxIdSetting is null or historicalTxIdSetting = '' then
select current_setting('hsadminng.tx_history_timestamp', true)::timestamp into historicalTimestamp;
raise notice 'tx_history_txid(): historicalTimestamp=%', historicalTimestamp;
select historicalTimestampSetting::timestamp into historicalTimestamp;
select max(txc.txid) from tx_context txc where txc.txtimestamp <= historicalTimestamp into historicalTxId;
raise notice 'tx_history_txid(): historicalTxId=%', historicalTxId;
else
historicalTxId = historicalTxIdSetting::xid8;
end if;
@ -169,7 +179,7 @@ commit;
-- single version at point in time
-- set hsadminng.tx_history_txid to (select max(txid) from tx_context where txtimestamp<='2024-08-27 12:13:13.450821');
set hsadminng.tx_history_txid to '3249';
--set hsadminng.tx_history_timestamp to '2024-08-27 17:52:07.755407';
set hsadminng.tx_history_timestamp to '';
-- all versions
select tx_history_txid(), txc.txtimestamp, txc.currentUser, txc.currentTask, haex.*
from hs_hosting_asset_ex haex