Skip to content

Ошибка плагина ARCHIVECOMMAND на реплике (версия 3.0.0) #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sgrinko opened this issue Aug 26, 2021 · 4 comments
Assignees
Labels
Milestone

Comments

@sgrinko
Copy link
Contributor

sgrinko commented Aug 26, 2021

Добрый день,

при работе mamonsu новой версии на реплике плагин ARCHIVECOMMAND падает с ошибкой:

[ERROR] 2021-08-26 12:07:35,762 - ARCHIVECOMMAND        -       catch error: {'S': 'ERROR', 'V': 'ERROR', 'C': '55000', 'M': 'recovery is in progress', 'H': 'WAL control functions cannot be execut
ed during recovery.', 'W': 'SQL function "archive_command_files" statement 1', 'F': 'xlogfuncs.c', 'L': '341', 'R': 'pg_current_wal_lsn'}
[INFO] 2021-08-26 12:07:35,762 - ARCHIVECOMMAND -       hint: enable debug level to full exception trace

режим bootstrap

Предлагаю встроить в код функции проверку:

CREATE OR REPLACE FUNCTION mamonsu.archive_command_files()
  RETURNS TABLE(count_files bigint, size_files bigint) AS
$BODY$
begin
    if pg_is_in_recovery() then
        return query select 0::bigint as count_files, 0::bigint as size_files;
    else
        return query
        with
        segment_parts_count as
        (
            select 4096 / (setting::bigint / 1024 / 1024) as value from pg_settings where name = 'wal_segment_size'
        ),
        segment_size as
        (
            select setting::bigint as value from pg_settings where name = 'wal_segment_size'
        ),
        last_wal_div as
        (
            select ('x' || substring(last_archived_wal from 9 for 8))::bit(32)::int as value from pg_stat_archiver
        ),
        last_wal_mod as
        (
            select ('x' || substring(last_archived_wal from 17 for 8))::bit(32)::int as value from pg_stat_archiver
        ),
        current_wal_div as
        (
            select ('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 9 for 8))::bit(32)::int as value
        ),
        current_wal_mod as
        (
            select ('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 17 for 8))::bit(32)::int as value
        )
        select greatest(coalesce( (segment_parts_count.value - last_wal_mod.value)
                                  + ((current_wal_div.value - last_wal_div.value - 1) * segment_parts_count.value)
                                  + current_wal_mod.value - 1
                                 , 0)
                       , 0) as count_files,
               greatest(coalesce( ( (segment_parts_count.value - last_wal_mod.value)
                                    + ((current_wal_div.value - last_wal_div.value - 1) * segment_parts_count.value)
                                    + current_wal_mod.value - 1
                                  ) * segment_size.value
                                , 0)
                       , 0)      as size_files
        FROM segment_parts_count, segment_size, last_wal_div, last_wal_mod, current_wal_div, current_wal_mod;
    end if;
end
$BODY$
  LANGUAGE plpgsql VOLATILE SECURITY DEFINER PARALLEL UNSAFE COST 100 ROWS 1000;
@cuprumtan cuprumtan added the bug label Aug 26, 2021
@cuprumtan cuprumtan self-assigned this Aug 26, 2021
@cuprumtan cuprumtan added this to the 3.0.1 milestone Aug 26, 2021
@cuprumtan
Copy link
Contributor

Добрый день! Исправлено в патче 3.0.1

@sgrinko
Copy link
Contributor Author

sgrinko commented Sep 6, 2021

Проверил версию 3.0.1
Падает...

[INFO] 2021-09-06 15:41:32,844 - PGSQL-(host=localhost db=mamonsu user=mamonsu port=5432)       -       Found mamonsu bootstrap
[INFO] 2021-09-06 15:41:32,877 - PGSQL-(host=localhost db=publishing user=mamonsu port=5432)    -       connecting
[ERROR] 2021-09-06 15:41:32,933 - ARCHIVECOMMAND        -       catch error: {'S': 'ERROR', 'V': 'ERROR', 'C': '55000', 'M': 'recovery is in progress', 'H': 'WAL control functions cannot be executed during recovery.', 'W': 'SQL function archive_command_files" statement 1', 'F': 'xlogfuncs.c', 'L': '341', 'R':'pg_current_wal_lsn'}
[INFO] 2021-09-06 15:41:32,934 - ARCHIVECOMMAND -       hint: enable debug level to full exception trace

в функции mamonsu.archive_command_files() нет проверки на работу на реплике...

(я предлагал добавить эту проверку внутрь функции)

в коде плагина эта функция также вызывается
изображение

режим bootstrap!

@cuprumtan cuprumtan reopened this Sep 6, 2021
@cuprumtan cuprumtan modified the milestones: 3.0.1, 3.0.2 Sep 7, 2021
@cuprumtan
Copy link
Contributor

Добавили изменения в bootstrap в новом патче.

@sgrinko
Copy link
Contributor Author

sgrinko commented Oct 11, 2021

Спасибо, посмотрю

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants