Skip to content

Лаг репликации на primary сервере #180

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
pkarezin opened this issue Dec 7, 2021 · 3 comments
Closed

Лаг репликации на primary сервере #180

pkarezin opened this issue Dec 7, 2021 · 3 comments
Assignees
Labels
Milestone

Comments

@pkarezin
Copy link

pkarezin commented Dec 7, 2021

Добрый день, столкнулись со следующей проблемой при использовании mamonsu 3.1.2 и PostgreSQL 9.6.

Если процесс postmaster будет завершен некорректно (kill -9), то после запуска сервера будет взведен триггер PostgreSQL: streaming replication lag, даже если это primary или standalone сервер.
SELECT now() - pg_last_xact_replay_timestamp() будет отображать время с момента запуска startup на сервере.

# SELECT now() - pg_last_xact_replay_timestamp();
    ?column?
----------------
 00:21:15.10736
(1 row)
@cuprumtan cuprumtan added the bug label Dec 22, 2021
@cuprumtan cuprumtan self-assigned this Dec 22, 2021
@cuprumtan cuprumtan added this to the 3.2.2 milestone Dec 22, 2021
@sgrinko
Copy link
Contributor

sgrinko commented Jan 10, 2022

Подтверждаю.
В режиме bootstrap в функции mamonsu.timestamp_get() не учтен вариант запуска данной функции на master реплике.
Дело в том, что при вычислении выражения мы получаем LSN = NULL - это даёт ложь и вычисляется ELSE
изображение

Необходимо изменить функцию mamonsu/mamonsu/plugins/pgsql/driver/pool.py :

"replication_lag_slave_query": (
	"""
	SELECT CASE WHEN coalesce(pg_last_{1}(), '0/00000000') = coalesce(pg_last_{2}(), '0/00000000')
				THEN 0
				ELSE extract (epoch FROM now() - coalesce(pg_last_xact_replay_timestamp(), now() - INTERVAL '{0} seconds'))
		   END;
	""",
	"""
	SELECT mamonsu.timestamp_get();
	"""
),

таким образом ->

"replication_lag_slave_query": (
	"""
	SELECT CASE WHEN not pg_is_in_recovery() or coalesce(pg_last_{1}(), '0/00000000') = coalesce(pg_last_{2}(), '0/00000000')
				THEN 0
				ELSE extract (epoch FROM now() - coalesce(pg_last_xact_replay_timestamp(), now() - INTERVAL '{0} seconds'))
		   END;
	""",
	"""
	SELECT mamonsu.timestamp_get();
	"""
),

@cuprumtan cuprumtan modified the milestones: 3.2.2, 3.3.0 Jan 17, 2022
@cuprumtan
Copy link
Contributor

Добрый день! Добавили фикс в версию 3.3.0.

@sgrinko
Copy link
Contributor

sgrinko commented Jan 19, 2022

Спасибо!
Будем пробовать

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

3 participants