Installation

Install postgres:

pkg install postgresql10-server-10.1

Enable service:

sysrc postgresql_enable="YES"

If postgreSQL is installed within a jail, enable SysV IPC for that Jail (this here):

echo 'security.jail.sysvipc_allowed=1' >> /etc/sysctl.conf
echo 'jail_sysvipc_allow="YES"' >> /etc/rc.conf 

# in /usr/local/etc/ezjail/JAILNAME, update:
# export jail_JAILNAME_parameters=”allow.sysvipc=1″

# restart jail
ezjail-admin restart JAILNAME

Initialize DB (I don't know what this is). This would fail if postgresQL is installed in a jail and SysV IPC is not allowed for the jail.

service postgresql initdb

Now start the service:

service postgresql start

There was a failure regarding SysV IPC during initdb, it looked like this:

~ service postgresql initdb
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "C".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /var/db/postgres/data10 ... ok
creating subdirectories ... ok
selecting default max_connections ... 10
selecting default shared_buffers ... 400kB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... 2017-11-28 18:23:03.857 UTC [72052] FATAL:  could not create shared memory segment: Function not implemented
2017-11-28 18:23:03.857 UTC [72052] DETAIL:  Failed system call was shmget(key=1, size=48, 03600).
child process exited with exit code 1
initdb: removing data directory "/var/db/postgres/data10"

Create users and databases

You would need to create a PostgreSQL user or role that matches the name of the primary system account that will use the database. For example, I would use it in a jail, with the root account. So I need to create a PSQL role matching that account:

> su postgres         # switch to account `postgres`
> createuser root
> createdb test_db
> exit                # quit being `postgres`

# now as `root`:
> psql test_db
psql (10.1)
Type "help" for help.

test_db=>