Skip to main content

PostgreSQL in the core

About

Postgres native support was added in FreeSWITCH 1.2.5.

Click here to expand Table of Contents

Dependencies

libpq and the associated dev packages are required

CentOS

yum install libpq-devel

Debian

sudo apt-get install libpq-dev

Configure

If you have installed a later version of PostgreSQL from a source other then your distro's repositories, and its installed to a non-standard location such as /usr/pgsql-9.5 you will need to adjust your PATH and/or PKG_CONFIG_PATH environment variables to properly locate either pg_config or libpq.pc

export PKG_CONFIG_PATH=/usr/pgsql-9.5/lib/pkgconfig
export PATH=/usr/pgsql-9.3/bin:$PATH
./configure --enable-core-pgsql-support

Adjust your PKG_CONFIG_PATH and PATH as required for your platform.

conf/autoload_configs/switch.conf.xml

<!-- to use a numeric IP address (no DNS names!): -->
<param name="core-db-dsn" value="pgsql://hostaddr=127.0.0.1 dbname=freeswitch user=freeswitch password='' options='-c client_min_messages=NOTICE' application_name='freeswitch'" />

<!-- OR to use a resolvable DNS hostname (not a numeric i.p. address): -->
<param name="core-db-dsn" value="pgsql://host=localhost dbname=freeswitch user=freeswitch password='' options='-c client_min_messages=NOTICE' application_name='freeswitch'" />

<!-- to disable SSL encyption need to add sslmode=disable -->
<param name="core-db-dsn" value="pgsql://host=localhost dbname=freeswitch user=freeswitch password='' options='-c client_min_messages=NOTICE' application_name='freeswitch' sslmode=disable" />

host vs hostaddr

'hostaddr' ONLY takes a numeric ip address and will not resolve a hostname. Use 'host' for a DNS hostname. If you specify both 'host' and 'hostaddr' settings, 'hostaddr' takes precedence.

PostgreSQL

For PostgreSQL, FS strips the 'pgsql://' from the DSN and passes the remainder of the string directly to libpq's PQconnectdb() for connection to the database. See the libpq docs for further information on creating a proper connections string.

Database Tables

Once you have PostgreSQL configured in the core, you can connect to the database and ensure you have tables, like the following.

PostgreSQL tables

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 | interfaces | table | freeswitch
public | nat | table | freeswitch
public | recovery | table | freeswitch
public | registrations | table | freeswitch
public | tasks | table | freeswitch
(9 rows)