FreeBSD: Mixing ports and packages

tl;dr: Use pkg install `make missing | cut -f2 -d/` to install dependencies for ports that you don't want to compile locally.

We want to install php73-pdo_pgsql which depends on postgresql95-client, but we already have postgresql11-client.

Checking integrity... done (1 conflicting)
  - postgresql95-client-9.5.15_2 conflicts with postgresql11-client-11.1 on /usr/local/bin/clusterdb
Checking integrity... done (0 conflicting)
Conflicts with the existing packages have been found.
One more solver iteration is needed to resolve them.
The following 5 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
    postgresql95-client: 9.5.15_2
    php73-pdo: 7.3.2
    php73-pdo_pgsql: 7.3.2

Number of packages to be installed: 3

The process will require 11 MiB more space.

Proceed with this action? [y/N]: ^C

Installing php-pdo_pgsql from ports will install dependencies from ports as well, which we don't want. Instead, we'd like to install those dependencies as packages.

Update the ports tree:

portsnap auto

List the dependencies for the desired port:

cd /usr/ports/databases/php73-pdo_pgsql
make missing

That gives us:

devel/autoconf
devel/m4
print/texinfo
misc/help2man
devel/p5-Locale-gettext
devel/gettext-tools
devel/p5-Locale-libintl
converters/libiconv
converters/p5-Text-Unidecode
textproc/p5-Unicode-EastAsianWidth
devel/autoconf-wrapper
databases/php73-pdo

To translate those port names to package names and install them, we do:

pkg install `make missing | cut -f2 -d/`

After running make missing again to verify that all dependencies are indeed now present, compile and install the port:

make install clean