Realtime PJSIP Endpoints Retrieval from PostgreSQL via ODBC

Hello Asterisk Community,

I’m reaching out for assistance regarding a challenge I’ve encountered with my Asterisk setup. I am currently using Asterisk 18.20.2 and have configured it to fetch real-time PJSIP endpoint data from a PostgreSQL database using ODBC, but I’m facing some issues.

Here’s a brief overview of my setup:

  1. ODBC Configuration: I have set up the ODBC connection to my PostgreSQL database. My res_odbc.conf and odbc.ini files are configured with the necessary details, and the ODBC DSN is named “asterisk-postgresql”.
  2. Asterisk Configuration:

extconfig.conf

[settings]
ps_endpoints => odbc,asterisk
ps_auths => odbc,asterisk
ps_aors => odbc,asterisk
ps_domain_aliases => odbc,asterisk
ps_endpoint_id_ips => odbc,asterisk
ps_contacts => odbc,asterisk

res_odbc.conf

[asterisk]
enabled => yes
dsn => asterisk-postgresql
username => asterisk
password => asterisk
pre-connect => yes
sanitysql => select 1
logging => yes

sorcery.conf

[res_pjsip]
endpoint=realtime,ps_endpoints
auth=realtime,ps_auths
aor=realtime,ps_aors

[res_pjsip_endpoint_identifier_ip]
identify=realtime,ps_endpoint_id_ips

[res_pjsip_outbound_publish]
outbound-publish=realtime,ps_outbound_publish

[res_pjsip_pubsub]
inbound-publication=realtime,ps_inbound_publication

[res_pjsip_publish_asterisk]
asterisk-publication=realtime,ps_asterisk_publication
  1. PostgreSQL Database: The necessary tables for PJSIP settings are created in the database using cpntrib/realtime/postgresql/postgresql_config.sql.

Tables populated with data:

insert into ps_aors (id, max_contacts) values (801, 1);
insert into ps_aors (id, max_contacts) values (802, 1);
insert into ps_aors (id, max_contacts) values (803, 1);
insert into ps_aors (id, max_contacts) values (804, 1);
insert into ps_aors (id, max_contacts) values (805, 1);

insert into ps_auths (id, auth_type, password, username) values (801, 'userpass', 'Obelix', 801);
insert into ps_auths (id, auth_type, password, username) values (802, 'userpass', 'Obelix', 802);
insert into ps_auths (id, auth_type, password, username) values (803, 'userpass', 'Obelix', 803);
insert into ps_auths (id, auth_type, password, username) values (804, 'userpass', 'Obelix', 804);
insert into ps_auths (id, auth_type, password, username) values (805, 'userpass', 'Obelix', 805);

insert into ps_endpoints (id, aors, auth, context, allow, direct_media, dtls_auto_generate_cert, media_encryption) values (801, '801', '801', 'call-router', 'ulaw|alaw|g722|gsm|opus', 'no', 'yes', 'sdes');
insert into ps_endpoints (id, aors, auth, context, allow, direct_media, dtls_auto_generate_cert, media_encryption) values (802, '802', '802', 'call-router', 'ulaw|alaw|g722|gsm|opus', 'no', 'yes', 'sdes');
insert into ps_endpoints (id, aors, auth, context, allow, direct_media, dtls_auto_generate_cert, media_encryption) values (803, '803', '803', 'call-router', 'ulaw|alaw|g722|gsm|opus', 'no', 'yes', 'sdes');
insert into ps_endpoints (id, aors, auth, context, allow, direct_media, dtls_auto_generate_cert, media_encryption) values (804, '804', '804', 'call-router', 'ulaw|alaw|g722|gsm|opus', 'no', 'yes', 'sdes');
insert into ps_endpoints (id, aors, auth, context, allow, direct_media, dtls_auto_generate_cert, media_encryption) values (805, '805', '805', 'call-router', 'ulaw|alaw|g722|gsm|opus', 'no', 'yes', 'sdes');

However, when I run pjsip show endpoints in the Asterisk CLI, I receive a “No objects found” message, despite having PJSIP endpoint data in the PostgreSQL database:

> odbc show all

ODBC DSN Settings
-----------------
  Name:   asterisk
  DSN:    asterisk-postgresql
    Number of active connections: 1 (out of 1)
    Logging: Enabled
    Number of prepares executed: 0
    Number of queries executed: 0

I have double-checked the database connection, and it seems to be active with no apparent issues. Also, the Asterisk logs don’t reveal any specific errors related to ODBC or PJSIP.

Here are some steps I have already tried:

  • Ensuring that the database and tables exist and are accessible.
  • Reloading ODBC and PJSIP modules in Asterisk.
  • Checking the Asterisk logs for any error messages or warnings.

I’m wondering if anyone in the community has faced a similar issue or might have insights into what could be going wrong. Any guidance or suggestions would be greatly appreciated!

Thank you for your time and assistance.

Best regards,
Henry

Howdy!

Restarting Asterisk as well ?

Realtime is great but not a panacea - some things are probably better stored there than others.

Here’s one approach to consider as you design your sorcery.conf file:

WHAT WHERE
Things that change a lot memory (RAM)
Things that change frequently astdb (SQLite)
Things that change occasionally realtime (PostgreSQL)
Things that change rarely config (pjsip.conf, pjsip_wizard.conf)

That said, your sorcery.conf might need a little more fleshing out… maybe something like this helps you:

[res_pjsip]

; configure first the fairly static plain text items
; (some with the wizard)
auth=config,pjsip.conf,criteria=type=auth
domain_alias=config,pjsip.conf,criteria=type=domain_alias
global=config,pjsip.conf,criteria=type=global
system=config,pjsip.conf,criteria=type=system
transport=config,pjsip.conf,criteria=type=transport
aor=config,pjsip.conf,criteria=type=aor
endpoint=config,pjsip.conf,criteria=type=endpoint
contact=config,pjsip.conf,criteria=type=contact

; realtime where it makes the most sense
; (just these three tables)
endpoint=realtime,ps_endpoints
auth=realtime,ps_auths
aor=realtime,ps_aors

; local Asterisk SQLite database storage
; (for frequently changing contact info)
contact=astdb,registrator

[res_pjsip_endpoint_identifier_ip]
identify=config,pjsip.conf,criteria=type=identify

[res_pjsip_outbound_publish]
outbound-publish=config,pjsip.conf,criteria=type=outbound-publish

[res_pjsip_outbound_registration]
registration=config,pjsip.conf,criteria=type=registration

[res_pjsip_pubsub]
subscription_persistence=memory

…combine that with pjsip.conf for global, system, transport, and pub-sub configuration; plus pjsip_wizard.conf for SIP trunk registrations; and you might reach a happy medium that works for you and your users!

Upstream there’s some official Asterisk Realtime documentation dealing with MySQL but mostly adaptable to PostgreSQL.

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