Slow Asterisk Startup

I upgrade from asterisk 16.11.1 to asterisk 22 .
In asterisk 16 I used sip , now I use pjsip
I migrate sippeers to ps_endpoints and ps_auth
and insert ps_aors
after asterisk is ready users get register and call will be stablished .
but every time I restart asterisk , it take long time to be ready
in tables
ps_endpoints rows :10000 records
ps_auth rows : 10000 record
….
what should I do ,
As I understand on startuop it load all ps_endpoints and … in memory
How can I disable this and just cache every time user request …
Or if problem is something else , please help me

sorcery.conf
[res_pjsip]
endpoint/cache = memory_cache,object_lifetime_stale=600,object_lifetime_maximum=1800,maximum_objects=10,expire_on_reload=yes,full_backend_cache=no
endpoint = realtime,ps_endpoints
auth/cache=memory_cache,expire_on_reload=yes,maximum_objects=10,full_backend_cache=no
auth = realtime,ps_auths
aor/cache = memory_cache,object_lifetime_stale=1500,object_lifetime_maximum=1800,maximum_objects=10,expire_on_reload=yes,full_backend_cache=no
aor = realtime,ps_aors

;[res_pjsip]
;endpoint=config,pjsip.conf,criteria=type=endpoint
;endpoint=realtime,ps_endpoints
;auth=realtime,ps_auths
;aor=config,pjsip.conf,criteria=type=aor
;aor=realtime,ps_aors
;aor=config,pjsip.conf,criteria=type=aor
;aor=realtime,ps_aors
;transport=config,pjsip.conf,criteria=type=transport
;global=config,pjsip.conf,criteria=type=global

—————–
extconfig.conf
;
; Static and realtime external configuration
; engine configuration
;
; See Realtime Database Configuration - Asterisk Documentation
; for basic table formatting information.
;
[settings]

; Only map authentication to database
;ps_auths => odbc,asterisk,ps_auths
;extensions => odbc,asterisk,extensions ; Only if you need extensions from DB

;exten => odbc,asterisk,odbc

extensions => odbc,asterisk,extensions
ps_endpoints => odbc,asterisk,ps_endpoints,id=‘1’

ps_auths => odbc,asterisk,ps_auths,id=‘1’
ps_aors => odbc,asterisk,ps_aors
;ps_domain_aliases => odbc,asterisk,ps_domain_aliases

—-

How long?

There isn’t the ability to do so. It needs to load things in to set up certain state where applicable. The lazy loading approach that chan_sip used is not implemented.

How long?

about 15 minutes

What are you running this on, and where is your database server?

services:
db:
image: postgres:17
container_name: asterisk_postgres3ports:

“5445:5432”environment:POSTGRES_USER: asteriskPOSTGRES_PASSWORD: asteriskPOSTGRES_DB: asterisk#POSTGRES_INITDB_ARGS: --encoding=UTF8 --lc-collate=fa_IR.UTF8 --lc-ctype=fa_IR.UTF8volumes:

postgres_data:/var/lib/postgresql/datahealthcheck:test: [“CMD-SHELL”, “pg_isready -U asterisk -d asterisk -h localhost”]interval: 10stimeout: 5sretries: 5start_period: 10snetworks:asterisk_net:ipv4_address: 10.0.1.235

asterisk:

image: gitlab.local.boshrapardaz.ir:4567/idogram/new_asterisk:testbuild3
network_mode: host
tty: true
container_name: asterisk
environment:
 AS_DATABASE_HOST: 10.0.1.235
 AS_DATABASE_NAME: "asterisk"
 AS_DATABASE_USER: "asterisk"
 AS_DATABASE_PASS: "asterisk"
 AS_DATABASE_PORT: 5432
 AS_EXTEN_CONTEXT_NAME: "idogramdev.local.boshrapardaz.ir"
 AS_OLDDATABASE_HOST: 10.0.0.235
 AS_OLDDATABASE_NAME: "asterisk"
 AS_OLDDATABASE_USER: "db"
 AS_OLDDATABASE_PASS: "qMfnYBWJs6art7uh"
 AS_OLDDATABASE_PORT: 5432

volumes:

- ./run.sh:/usr/bin/run

- ./conf/modules.conf:/etc/asterisk/modules.conf

  - ./common:/etc/asterisk/keys
  - ./conf/stasis.conf:/etc/asterisk/stasis.conf
  - ./conf/res_odbc.conf:/etc/asterisk/res_odbc.conf
  - ./conf/pjsip.conf:/etc/asterisk/pjsip.conf
  - ./logger.conf:/etc/asterisk/logger.conf
    #- ./conf/cdr_pgsql.conf:/etc/asterisk/cdr_pgsql.conf
    #- ./conf/cel_pgsql.conf:/etc/asterisk/cel_pgsql.conf
  - ./conf/extconfig.conf:/etc/asterisk/extconfig.conf
  - ./conf/sorcery.conf:/etc/asterisk/sorcery.conf

depends_on:
  db:
    condition: service_healthy

volumes:postgres_data:

networks:asterisk_net:driver: bridgeipam:driver: defaultconfig:

subnet: 10.0.1.0/24


I use docker containers . this is my docker-composese

I wouldn’t expect it to take that long, provided sufficient resources are given. I am aware some other people are using things at that scale based on issue reports/feature request. Aside from updating the caching settings so that they actually reflect expectations, or trying full backend caching, I don’t have any other comments.

I see these logs and after a while (15-20 min) asterisk be ready

How can I debug what is in progress ?

asterisk -f -vvv

Asterisk 22.5.2, Copyright (C) 1999 - 2025, Sangoma Technologies Corporation and others.
Created by Mark Spencer markster@digium.com
Asterisk comes with ABSOLUTELY NO WARRANTY; type ‘core show warranty’ for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type ‘core show license’ for details.

XSLT support not found. XML documentation may be incomplete.
PBX UUID: d6a69117-d7ef-4406-b67d-c3bdba0bc4af
Asterisk PBX Core Initializing
Asterisk Dynamic Loader Starting:
[Sep 9 13:23:20] NOTICE[27]: loader.c:2568 load_modules: 322 modules will be loaded.
[Sep 9 13:23:20] WARNING[27]: res_odbc.c:605 load_odbc_config: The ‘pooling’, ‘shared_connections’, ‘limit’, and ‘idlecheck’ options were replaced by ‘max_connections’. See res_odbc.conf.sample.
[Sep 9 13:23:20] NOTICE[27]: res_odbc.c:718 load_odbc_config: Registered ODBC class ‘asterisk’ dsn->[Asterisk-PGSQL]
[Sep 9 13:23:20] WARNING[27]: res_config_pgsql.c:1546 parse_config: PostgreSQL RealTime: no requirements setting found, using ‘warn’ as default.
== PostgreSQL RealTime reloaded.
[Sep 9 13:23:20] NOTICE[27]: cdr.c:4639 cdr_toggle_runtime_options: CDR simple logging enabled.
[Sep 9 13:23:20] WARNING[27]: http.c:2564 __ast_http_load: Ignoring unknown option ‘prometheus’ in http.conf
Bound HTTP server ‘http server’ to address 0.0.0.0:8088
[Sep 9 13:23:20] NOTICE[27]: indications.c:1100 load_indications: Default country for indication tones: us
[Sep 9 13:23:20] NOTICE[27]: indications.c:424 ast_set_indication_country: Setting default indication country to ‘us’
– Local IPv4 address determined to be: 192.168.1.200
– Local IPv6 address determined to be: fe80::250:56ff:fe8d:975f

Debug level logs[1] may show more information including what it is doing.

[1] Collecting Debug Information - Asterisk Documentation

What else it the host doing?

Now ,we just have this services

All users have the same configuration

And just username and password is different.

Is it possible load one configuration for all users from pjsip.conf or other file for endpoints and aors

And just load and check username and password from database (ps_auths)

@jcolp

Yes. Remove the explicit lines in sorcery.conf for the things you don’t want to be in realtime. The default will be to have them from pjsip.conf

I decide to load configs and users from db and cache them
I use these config in sorcery.conf

[res_pjsip]

endpoint/cache = memory_cache,object_lifetime_stale=600,object_lifetime_maximum=1800,expire_on_reload=yes
endpoint = realtime,ps_endpoints

auth/cache=memory_cache,object_lifetime_stale=600,object_lifetime_maximum=1800,expire_on_reload=yes
auth = realtime,ps_auths

aor/cache = memory_cache,object_lifetime_stale=600,object_lifetime_maximum=1800,expire_on_reload=yes
aor = realtime,ps_aors

and extconfig.conf

[settings]

extensions => odbc,asterisk,extensions
ps_endpoints => odbc,asterisk,ps_endpoints,
ps_auths => odbc,asterisk,ps_auths
ps_aors => odbc,asterisk,ps_aors

Its very slow to be ready asterisk.
I enable debugging on postgresql and it seems

BEGIN;declare “SQL_CUR0x55dd1daa93a0” cursor with hold for SELECT * FROM ps_endpoints WHERE id LIKE ‘%’ ORDER BY id;fetch 100 in “SQL_CUR0x55dd1daa93a0”

BEGIN;declare “SQL_CUR0x7ff424007b20” cursor with hold for SELECT * FROM ps_aors WHERE id LIKE ‘%’ ORDER BY id;fetch 100 in “SQL_CUR0x7ff424007b20”

this is in progress in asterisk on startup

as we have about 15000 records
1- fetch 100 per step is the bottleneck
Is there any option to change 100 to bigger , example 1000 (we have no memory problem)

2- condition LIKE ‘%’ can be the problem too
And how can I modify condition to remove this condition

@jcolp

Please do not explicitly tag me. If I have anything to add to posts and wish to, then I do so. I do not know where “fetch 100” is coming from, and modifications to the broader SQL queries would have to be done through modifications to the C code.

I can’t see how this is going to have more than a few percent effect on the timing. and a clever database engine would optimise the LIKE clause out. A sensible query plan would scan on the index that contained id. so would have to read it all, anyway.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.