processone / processone/ejabberd

SQL query error when running ejabberdctl delete_old_mam_messages on PostgreSQL database

Open
#4,591 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component:MAM
Dominant language
Erlang
Stars
6.7k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

  • ejabberd version: 26.03

When running ejabberdctl delete_old_mam_messages_batch movim.eu all 365 1000 10000 I have:

2026-07-13 11:15:48.845004+02:00 [error] <0.621.0>@ejabberd_sql:sql_query_internal/1:734 PREPARE failed for SQL query at {mod_mam_sql,{234,16}}: [{severity,'ERROR'},
    {86,<<"ERROR">>},
    {code,<<"42601">>},
    {message,
    <<"syntax error at or near \"limit\"">>},
    {position,50},
    {file,<<"scan.l">>},
    {line,1244},
    {routine,
    <<"scanner_yyerror">>}]
2026-07-13 11:15:48.845788+02:00 [error] <0.621.0>@ejabberd_sql:check_error/2:1477 SQL query 'delete from archive where timestamp < 1752398148843975 and 0=0 limit 1000' failed: [{severity,
    'ERROR'},
    {86,
    <<"ERROR">>},
    {code,
    <<"42601">>},
    {message,
    <<"syntax error at or near \"limit\"">>},
    {position,
    64},
    {file,
    <<"scan.l">>},
    {line,
    1244},
    {routine,
    <<"scanner_yyerror">>}]
2026-07-13 11:15:48.846018+02:00 [error] <0.621.0>@ejabberd_sql:check_error/2:1470 SQL query 'Q132631412' at {mod_mam_sql,{234,16}} failed: [{severity,'ERROR'},
    {86,<<"ERROR">>},
    {code,<<"42601">>},
    {message,
    <<"syntax error at or near \"limit\"">>},
    {position,64},
    {file,<<"scan.l">>},
    {line,1244},
    {routine,
    <<"scanner_yyerror">>}]

And when running ejabberdctl delete_old_mam_messages all 365 I have:

 2026-07-13 11:17:15.838003+02:00 [error] <0.3791138.0>@ejabberd_sql:check_error/2:1470 SQL query 'Q9506383' at {mod_mam_sql,{274,20}} failed: <<"timed out">>

In the logs, but no error in the console, would be nice to have one.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the mod_mam_sql entry points used by ejabberdctl delete_old_mam_messages_batch and delete_old_mam_messages, then trace the PostgreSQL queries shown in the report and their error handling. Reproduce both commands against PostgreSQL; done means batch deletion no longer fails on the LIMIT syntax and timeout failures are surfaced in the console as requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
erlang, postgresql, sql
Domain
backend, cli, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.