Freeswitch Core DB в Postgresql

А также internal db, mod_lcr.

Использование core db в postgres вместо ванильного sqlite обязательно для «продакшн».
Установить Postgresql на Debian

https://wiki.debian.org/ru/PostgreSql
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-9-4-on-debian-8

Установить libpq
  apt-get install libpq-dev
Конфигурация FS

Если FS скомпилирован из исходников, то это должно быть сделано с флагом:

--enable-core-pgsql-support

если установлен из бинарника, то никаких лишних телодвижений. Полноценный репозиторий есть только под debian 8/9. В репе centos 7, может не быть некоторых пакетов.

Таблицы внутренней БД (native db):

../autoload_configs/db.conf.xml

  • group_data
  • limit_data
  • db_data
   <param name="odbc-dsn" value="pgsql://hostaddr=127.0.0.1 dbname=freeswitch  user=freeswitch password=''"/>

таблицы FS CORE:

../autoload_configs/switch.conf.xml

<param name="core-db-dsn" value="pgsql://hostaddr=127.0.0.1 dbname=freeswitch  user=freeswitch password='' options='-c client_min_messages=NOTICE'" />
  • aliases
  • calls
  • channels
  • complete
  • interfaces
  • nat
  • recovery
  • registrations

Таблицы LCR (опционально):

Обслуживаю модуль mod_lcr

../autoload_configs/lcr.conf.xml

  <settings>
   <param name="odbc-dsn" value="pgsql://hostaddr=127.0.0.1 dbname=freeswitch user=freeswitch password=''"/>
  </settings>
  • carrier_gateway
  • carriers
  • lcr

Таблицы SIP профилей(опция):

Здесь будут храниться данные о регистрациях.

../sip_profiles/internal.xml

     <param name="odbc-dsn" value="pgsql://hostaddr=127.0.0.1 dbname=freeswitch  user=freeswitch password=''"/>
  • sip_authentication
  • sip_dialogs
  • sip_presence
  • sip_registrations
  • sip_shared_appearance_dialogs
  • sip_shared_appearance_subscriptions
  • sip_subscriptions

postgres

Где pg_hba.conf?

Данный конфиг определяет политики пользователей postgres.

$ su - postgres
postgres@fs:~$ psql
psql (9.4.15)
Type "help" for help.

postgres=# SHOW hba_file;
               hba_file
--------------------------------------
 /etc/postgresql/9.4/main/pg_hba.conf
(1 row)
Что в pg_hba.conf?

trust разрешает доступ без пароля. Это простейший вариант, но наверное не лучший. Ознакомьтесь с документацией postgresql.
https://chartio.com/resources/tutorials/how-to-set-the-default-user-password-in-postgresql/
https://www.postgresql.org/docs/9.6/client-authentication.html

     TYPE   DATABASE      USER                    ADDRESS              METHOD 
     host    freeswitch  freeswitch             127.0.0.1/32           trust
Как перечитать конфиг postgres?
 /etc/init.d/postgresql reload
Создать пользователя и БД
Из под рут shell
 # su - postgres
И затем из postgres shell
 $ createuser freeswitch
 $ createdb -O freeswitch freeswitch
 $ exit
Таблицы создаст сам fs, для этого его надо перезагрузить.
Обратите внимание на следующие параметры в //switch.conf.xml//:
    <!-- The system will create all the db schemas automatically, set this to false to avoid this behaviour -->
    <!-- <param name="auto-create-schemas" value="true"/> -->
    <!-- <param name="auto-clear-sql" value="true"/> -->

Они закомментированы по умолчанию имея значение true. Это значит, что FS автоматически создает таблицы по указанным DSN.

FS Restart
 # systemctl restart freeswitch

или нежно

fs_cli -x 'fsctl shutdown elegant restart'
Посмотрим что получилось

Если все сделано правильно, то будут созданы таблицы, из соответствующих конфигов.

 # su - freeswitch
 $ psql freeswitch
 freeswitch=> \dt

Обратите внимание на колонку Owner.

You are now connected to database "freeswitch" as user "freeswitch".
freeswitch=> \dt
                         List of relations
 Schema |                Name                 | Type  |   Owner
--------+-------------------------------------+-------+------------
 public | aliases                             | table | freeswitch
 public | calls                               | table | freeswitch
 public | channels                            | table | freeswitch
 public | complete                            | table | freeswitch
 public | db_data                             | table | freeswitch
 public | group_data                          | table | freeswitch
 public | interfaces                          | table | freeswitch
 public | limit_data                          | table | freeswitch
 public | nat                                 | table | freeswitch
 public | recovery                            | table | freeswitch
 public | registrations                       | table | freeswitch
 public | sip_authentication                  | table | freeswitch
 public | sip_dialogs                         | table | freeswitch
 public | sip_presence                        | table | freeswitch
 public | sip_registrations                   | table | freeswitch
 public | sip_shared_appearance_dialogs       | table | freeswitch
 public | sip_shared_appearance_subscriptions | table | freeswitch
 public | sip_subscriptions                   | table | freeswitch
 public | tasks                               | table | freeswitch
(19 rows)

Теперь все данные используемые fs в процессе обработки вызовов будут храниться в postgres. Для создания высоконагруженных стрессоустойчивых систем связи все вышеперечисленное крайне необходимо.

https://freeswitch.org/confluence/display/FREESWITCH/PostgreSQL+in+the+core

  • freeswitch/db/fs_coredb_postgres.txt
  • Последние изменения: 2019/03/12