Friday, December 11, 2020

postgreSQL: see trigger dependencies of an extension

Source: How to select functions that belong in a given extension in PostgreSQL?
The StackExchange question shows this is the request to use:
SELECT e.extname, ne.nspname AS extschema, p.proname, np.nspname AS proschema
FROM pg_catalog.pg_extension AS e
    INNER JOIN pg_catalog.pg_depend AS d ON (d.refobjid = e.oid)
    INNER JOIN pg_catalog.pg_proc AS p ON (p.oid = d.objid)
    INNER JOIN pg_catalog.pg_namespace AS ne ON (ne.oid = e.extnamespace)
    INNER JOIN pg_catalog.pg_namespace AS np ON (np.oid = p.pronamespace)
WHERE d.deptype = 'e'
ORDER BY 1, 3
which led me to use
SELECT e.extname, t.tgname
FROM pg_catalog.pg_extension AS e
JOIN pg_catalog.pg_depend AS d ON (d.refobjid = e.oid)
JOIN pg_catalog.pg_trigger AS t ON (t.tgfoid = d.objid)
where e.extname = 'mbqt_shared_api'

┌─────────────────┬─────────────────────────────────────┐
│     extname     │               tgname                │
├─────────────────┼─────────────────────────────────────┤
│ mbqt_shared_api │ dt_dialdigit_after_ins_trg          │
│ mbqt_shared_api │ dt_imsi_range_before_ins_or_upd_trg │
│ mbqt_shared_api │ dt_rzgthlr_after_ins_trg            │
│ mbqt_shared_api │ dt_rzgthlr_before_del_trg           │
│ mbqt_shared_api │ dt_rzgthlr_after_upd_trg            │
│ mbqt_shared_api │ dt_dialdigit_after_upd_trg          │
│ mbqt_shared_api │ dt_tadig_after_ins_trg              │
│ mbqt_shared_api │ dt_mccmnc_after_ins_trg             │
└─────────────────┴─────────────────────────────────────┘

Monday, November 23, 2020

macOS: Brew emacs 27.1 keeps crashing on Big Sur 11.0.1

[Edit] Updated way to compile emacs on macOS 12: https://github.com/jimeh/build-emacs-for-macos

Version: macOS v11.0.1
Constant crashes of Emacs v27.1 installed from Brew for no reason.
As a workaround, let's compile the latest version locally (bleeding edge).
source: Transitioning to GUI'd Emacs on macOS
$ git clone https://git.savannah.gnu.org/git/emacs.git
$ cd emacs
Check out the native compilation branch.
$ git checkout feature/native-comp
Let's make it.
$ export LIBXML2_CFLAGS="-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2"
$ ./autogen.sh
$ ./configure --without-makeinfo
$ make
$ make install
Then, replace the Brew version.
$ brew cask remove emacs
$ mv nextstep/Emacs.app/ /Applications/

Tuesday, November 10, 2020

jq: keep array values

 [jerome@jeroboam] > echo '["foo", "bar", "Baz"]' | jq '.[] | select(test("b"; "i"))'

"bar"

"Baz"


Wednesday, November 4, 2020

Clojure: destructuring map without naming key

Source: Destructuring map of map with unknown keys
user> (let [[[k {:keys [pim pam]}]] (seq {:basic {:pim 2 :pam 3}})] [k pim pam])
[:basic 2 3]
But no need of seq if we iterate with for.
user> (into {} (for [[k {:keys [pim pam]}] {:basic {:pim 2 :pam 3} :simple {:pim 20 :pam 30}}] [k {:pam pim :pim pam}]))
{:basic {:pam 2, :pim 3}, :simple {:pam 20, :pim 30}}

Friday, September 4, 2020

MacOS: unzip failure: need PK compat. v5.1 (can do v4.5)

 [jerome@jeroboam] > unzip CONNECTSA-565.zip 

Archive:  CONNECTSA-565.zip

   skipping: MBQT01186.OUT           need PK compat. v5.1 (can do v4.5)

   skipping: MBQT01191.OUT           need PK compat. v5.1 (can do v4.5)

   skipping: MBQT01197.OUT           need PK compat. v5.1 (can do v4.5)


[jerome@jeroboam] > brew install p7zip

[jerome@jeroboam] > 7za x CONNECTSA-565.zip 


Friday, August 14, 2020

MacOS: create a bootable Windows 10 install USB drive

Sources: 

Identify USB device

jerome@centurion ~ % diskutil list

This shows the USB drive is using /dev/disk4 in my case.

Format USB drive

jerome@centurion ~ % diskutil eraseDisk MS-DOS "WIN10" MBR /dev/disk4

NB: It is crucial to use MBR and not GPT in order to avoid the infamous error "Windows could not prepare the computer to boot into the next phase of installation. To install Windows, restart the installation." during setup on my laptop after that.

Mount Windows 10 ISO

jerome@centurion ~ % hdiutil mount ~/Desktop/Windows10.iso

This will create /Volumes/CCCOMA_X64FRE_EN-US_DV9

Copy Windows files to USB drive

One file of the installation, install.esd, is more than 4 GB, which is not supported on FAT32.

So, copy all files but this one.

jerome@centurion ~ % rsync -vha --exclude=sources/install.esd /Volumes/CCCOMA_X64FRE_EN-US_DV9/ /Volumes/WIN10

In order to copy install.esd, we will have to split it with wimlib, so install wimlib first.

jerome@centurion ~ % brew install wimlib                                                              

Then, split install.esd into 2 files of less than 4 GB, and copy them to the USB volume.

jerome@centurion ~ % wimlib-imagex split /Volumes/CCCOMA_X64FRE_EN-US_DV9/sources/install.esd /Volumes/WIN10/sources/install.swm 4000
[ERROR] Splitting of WIM containing solid resources is not supported.
        Export it in non-solid format first.
ERROR: Exiting with error code 68:
       The requested operation is unsupported.

install.esd is actually a solid archive compressed with LZMS, and apparently it cannot be split. So, export it to non-solid WIM as advised. For this, follow WIMEXPORT

jerome@centurion ~ % wimexport 
/Volumes/CCCOMA_X64FRE_EN-US_DV9/sources/install.esd all 
~/Desktop/install.wim --compress=LZX            
Using LZX compression with 12 threads
Archiving file data: 13 GiB of 13 GiB (100%) done

 Then try splitting again.

jerome@centurion ~ % wimlib-imagex split ~/Desktop/install.wim /Volumes/WIN10/sources/install.swm 4000
Writing "/Volumes/WIN10/sources/install.swm" (part 1 of 2): 0 MiB of 6037 MiB (0%) written
Writing "/Volumes/WIN10/sources/install2.swm" (part 2 of 2): 3997 MiB of 6037 MiB (66%) written
Finished writing split WIM part 2 of 2
 

Then eject WIN10, and you're good to go to install Windows 10 by booting from the USB drive.


Friday, July 17, 2020

Git: view unpushed commits

Source: Viewing unpushed Git commits
[jerome@jeroboam] > git lol @{u}..
* 00e9d99cf (HEAD -> PLTFRS-12002_Move_USSD_VAS_to_AWS) (Mon Jun 1 12:00:14 2020 GitHub) Merge pull request #726 from AirVantage/PLTFRS-12002_Move_USSD_VAS_to_AWS

Monday, June 22, 2020

MacOS: How to test netcat

Source: How To Use Netcat to Establish and Test TCP and UDP Connections on a VPS
Terminal #1:
[jerome@jeroboam] > nc -l 4444
Terminal #2:
[jerome@jeroboam] > nc localhost 4444
toto

Then terminal #1 will display toto as well.

Monday, June 15, 2020

PgBouncer: WARNING DNS lookup failed: host.docker.internal: result=0

If you're using PgBouncer in a Docker container and try to connect to the host via host.docker.internal, you may experience this error:
2020-06-15 17:23:46.211 UTC [1] WARNING DNS lookup failed: host.docker.internal: result=0
This fix resolves it: Fix DNS for Docker #8

Monday, June 1, 2020

PostgreSQL: plpgsql_check

Source: plpgsql_check
Cannot get it to compile from Github sources on macOS 10.15.5.
So, retrieve it from pgxn.
Then compile and install it.
[jerome@jeroboam] > make
clang -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -O2  -undefined dynamic_lookup -I/usr/local/Cellar/postgresql@9.4/9.4.26/lib/pgxs/src/makefiles/../../src/pl/plpgsql/src -I. -I./ -I/usr/local/Cellar/postgresql@9.4/9.4.26/include/server -I/usr/local/Cellar/postgresql@9.4/9.4.26/include/internal -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk   -I/usr/local/opt/gettext/include -I/usr/local/opt/openldap/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/readline/include -I/usr/local/opt/tcl-tk/include  -c -o plpgsql_check.o plpgsql_check.c
clang -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -O2  -undefined dynamic_lookup -I/usr/local/Cellar/postgresql@9.4/9.4.26/lib/pgxs/src/makefiles/../../src/pl/plpgsql/src -bundle -multiply_defined suppress -o plpgsql_check.so plpgsql_check.o -L/usr/local/Cellar/postgresql@9.4/9.4.26/lib    -L/usr/local/opt/gettext/lib -L/usr/local/opt/openldap/lib -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/tcl-tk/lib -Wl,-dead_strip_dylibs   -bundle_loader /usr/local/Cellar/postgresql@9.4/9.4.26/bin/postgres
[jerome@jeroboam] > make install
/bin/sh /usr/local/Cellar/postgresql@9.4/9.4.26/lib/pgxs/src/makefiles/../../config/install-sh -c -d '/usr/local/Cellar/postgresql@9.4/9.4.26/lib'
/bin/sh /usr/local/Cellar/postgresql@9.4/9.4.26/lib/pgxs/src/makefiles/../../config/install-sh -c -d '/usr/local/Cellar/postgresql@9.4/9.4.26/share/extension'
/bin/sh /usr/local/Cellar/postgresql@9.4/9.4.26/lib/pgxs/src/makefiles/../../config/install-sh -c -d '/usr/local/Cellar/postgresql@9.4/9.4.26/share/extension'
/usr/bin/install -c -m 755  plpgsql_check.so '/usr/local/Cellar/postgresql@9.4/9.4.26/lib/plpgsql_check.so'
/usr/bin/install -c -m 644 plpgsql_check.control '/usr/local/Cellar/postgresql@9.4/9.4.26/share/extension/'
/usr/bin/install -c -m 644 plpgsql_check--1.0.sql '/usr/local/Cellar/postgresql@9.4/9.4.26/share/extension/'
[jerome@jeroboam] > 
Then from psql:
crmmbqt=# CREATE EXTENSION plpgsql_check;
CREATE EXTENSION
Time: 317.716 ms

PostgreSQL: ERROR: could not access file "$libdir/plpython2": No such file or directory

After upgrading postgres from 9.4.18 to 9.4.26 on MacOS 10.15.5 with
[jerome@jeroboam] > brew upgrade 'postgresql@9.4'
I then discovered that plpython was gone.
[jerome@jeroboam] > make
touch sql/mbqt_post_api.out
../bin/replace_extension.pl sql/mbqt_post_api.sql
DBG> schema = mbqt_db, extension = mbqt_post_api
DBG> installed version = 1.21, new version = 1.21
CMD> cat sql/mbqt_post_api.sql > sql/mbqt_post_api--1.21.sql
CMD> /usr/bin/install -m 644 sql/mbqt_post_api--1.21.sql sql/mbqt_post_api.control /usr/local/Cellar/postgresql@9.4/9.4.26/share/postgresql@9.4/extension
CMD> psql -Upostgres -h127.0.0.1 -p5432 -dcrmmbqt -q<<END_OF_SQL
\set ON_ERROR_STOP ON
create schema if not exists mbqt_db authorization postgres;
drop extension if exists mbqt_post_api cascade;
create extension mbqt_post_api with schema mbqt_db;
END_OF_SQL
2020-06-01 14:12:47
NOTICE:  schema "mbqt_db" already exists, skipping
Time: 11.778 ms
NOTICE:  extension "mbqt_post_api" does not exist, skipping
Time: 12.900 ms
ERROR:  could not access file "$libdir/plpython2": No such file or directory
And indeed
[jerome@jeroboam] > ll -rt /usr/local/opt/postgresql\@9.4/lib/pl*
-r--r--r--  1 jerome  staff    42K Jun  1 12:41 /usr/local/opt/postgresql@9.4/lib/pltcl.so
-r--r--r--  1 jerome  staff   164K Jun  1 12:41 /usr/local/opt/postgresql@9.4/lib/plpgsql.so
-r--r--r--  1 jerome  staff    84K Jun  1 12:41 /usr/local/opt/postgresql@9.4/lib/plperl.so
I tried
[jerome@jeroboam] > brew reinstall postgresql@9.4 --with-python
But it failed with
Error: invalid option: --with-python
And indeed, as per Remove all options from Homebrew/homebrew-core formulae, they estimated that options in brew are bad from now.
Then I found out: petere / homebrew-postgresql.
So, I used
[jerome@jeroboam] > brew tap petere/postgresql
And
[jerome@jeroboam] > brew reinstall petere/postgresql/postgresql@9.4
which ended up with
configure: error: header file <perl.h> is required for Perl

If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):
  https://github.com/petere/homebrew-postgresql/issues


Error: A newer Command Line Tools release is available.
Update them from Software Update in System Preferences or run:
  softwareupdate --all --install --force

If that doesn't show you an update run:
  sudo rm -rf /Library/Developer/CommandLineTools
  sudo xcode-select --install
Then let's go
[jerome@jeroboam] > sudo rm -rf /Library/Developer/CommandLineTools
[jerome@jeroboam] > sudo xcode-select --install
And finally
[jerome@jeroboam] > brew reinstall petere/postgresql/postgresql@9.4
which ended OK this time

==> Summary
🍺  /usr/local/Cellar/postgresql@9.4/9.4.26: 2,989 files, 41.0MB, built in 2 minutes 8 seconds
And guess what? plpython is back.
[jerome@jeroboam] > ll -rt /usr/local/opt/postgresql\@9.4/lib/pl*
-r--r--r--  1 jerome  staff    42K Jun  1 15:53 /usr/local/opt/postgresql@9.4/lib/pltcl.so
-r--r--r--  1 jerome  staff   108K Jun  1 15:53 /usr/local/opt/postgresql@9.4/lib/plpython2.so
-r--r--r--  1 jerome  staff   164K Jun  1 15:53 /usr/local/opt/postgresql@9.4/lib/plpgsql.so
-r--r--r--  1 jerome  staff    84K Jun  1 15:53 /usr/local/opt/postgresql@9.4/lib/plperl.so

Thursday, May 28, 2020

Linux: list SSL certificates

Source: List all available ssl ca certificates
locate .pem | grep "\.pem$"

Perl SSL: get debug details when it's not working

When trying to understand why LWP::UserAgent cannot post to HTTPS, you can try:
use IO::Socket::SSL qw(debug4);
so as to get more details.

Monday, May 25, 2020

postgreSQL: streaming replication delay

From the standby DB:
crmmbqt=# select now() - pg_last_xact_replay_timestamp() as replication_delay;
┌───────────────────────┐
│   replication_delay   │
├───────────────────────┤
│ 1 day 05:45:26.277667 │
└───────────────────────┘
or get more details with
crmmbqt=# pg_last_xlog_receive_location(), pg_last_xlog_replay_location(), pg_last_xact_replay_timestamp(), case when pg_last_xlog_receive_location() = pg_last_xlog_replay_location() then 0 else extract(epoch from now() - pg_last_xact_replay_timestamp()) end as replication_delay;

Wednesday, May 20, 2020

AWS: Launch an EC2 template over multiple subnets

Source: AWS Ec2 - Launch template spanning multiple subnets / availability zones
First create a launch template in the VPC with a Security Group.
Then, at the end, select Create Auto Scaling Group.

And then specify the subnets.

AWS: add .pem to SSH agent

Be sure the SSH agent is running.
[ec2-user@ip-10-75-40-54 .ssh]$ ssh-add par-vas-key.pem 
Could not open a connection to your authentication agent.
Start the ssh-agent with:
[ec2-user@ip-10-75-40-54 .ssh]$ eval `ssh-agent -s`
Agent pid 32703
Add .pem:
[ec2-user@ip-10-75-40-54 .ssh]$ ssh-add par-vas-key.pem 
Identity added: par-vas-key.pem (par-vas-key.pem)
Check public key known to the agent:
[ec2-user@ip-10-75-40-54 .ssh]$ ssh-add -L
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQClUygT8u3RS02SLEL44XkE... par-vas-key.pem

Thursday, May 14, 2020

Docker Alpine Linux: ssh keeps asking for password

Suppose we are running an sshd Docker Alpine (3.11) container. Even if properly configured by installing an SSH public key for root, you may keep being prompted for the root password by sshing the container.
[jerome@jeroboam] > docker run -e 'SSH_PUBLIC_KEY="..." -it --rm -p 2223:22 --name ss-ussd-sshd ss-ussd/sshd
[jerome@jeroboam] > ssh -p 2223 root@localhost
Warning: Permanently added '[localhost]:2223' (ECDSA) to the list of known hosts.
root@localhost's password: 
Solution: can't config ssh service when i use alpine:3.9 #28
Root cause: CVE-2019-5021

Bottom line: add this command in the Dockerfile:
# make sure root login is disabled
RUN sed -i -e 's/^root::/root:!:/' /etc/shadow

Tuesday, May 5, 2020

Validate CloudFormation

CloudFormation Linter
MacOS Install
[jerome@jeroboam] > brew install cfn-lint
Run
[jerome@jeroboam] > cfn-lint ussd_vas.yaml

Tuesday, March 31, 2020

Bash: for loop alphabet

Source: For loop with Alphabet
[jerome@jeroboam] > for i in `seq 97 102`; do printf "\\$(printf %o $i)\n"; done
a
b
c
d
e
f

Wednesday, March 18, 2020

Linux: sum numbers

Source: Shell command to sum integers, one per line?
$ grep ussd\. MBQTUSG_20200302_001.csv | head -5
ussd.mt,8,02/03/2020 00:00:00,02/03/2020 23:59:59,88060
ussd.mo,576,02/03/2020 00:00:00,02/03/2020 23:59:59,172099
ussd.mt,576,02/03/2020 00:00:00,02/03/2020 23:59:59,172099
ussd.mo,1,02/03/2020 00:00:00,02/03/2020 23:59:59,254078
ussd.mt,34,02/03/2020 00:00:00,02/03/2020 23:59:59,254078

$ grep ussd\.m MBQTUSG_20200302_001.csv | cut -d, -f2 | perl -lpe '$c+=$_}{$_=$c'
243648

Tuesday, March 3, 2020

Format json file

The simplest way to reformat a one line JSON file into multiple lines is
jq . file.json

Monday, March 2, 2020

macOS: add PYTHONPATH to PostgreSQL brew service

Source: Changing the Homebrew Apache PATH variable.

Let's suppose we installed Python requests module.
On my system, requests has been installed in /usr/local/lib/python2.7/site-packages/.
Then, trying to import it from postgres like in
create or replace function tutu(o_status out int) as
$$
import sys, os
import requests, json
plpy.info(sys.version)
plpy.info(sys.path)
return (500)
$$ language plpython2u security definer;
will cause
select * from tutu()
to output
Query 1 ERROR: ERROR:  ImportError: No module named requests
By default, postgres will look in /Library/Python/2.7/site-packages/.
We then need to update PYTHONPATH.
With brew starting postgres, we will update the postgres plist file.
[jerome@jeroboam] > vi /usr/local/opt/postgresql\@9.4/homebrew.mxcl.postgresql\@9.4.plist


  KeepAlive
  
  Label
  homebrew.mxcl.postgresql@9.4
  EnvironmentVariables
  
    PYTHONPATH
    /usr/local/lib/python2.7/site-packages
  
  ProgramArguments
  
    /usr/local/opt/postgresql@9.4/bin/postgres
    -D
    /usr/local/var/postgresql@9.4
  
  RunAtLoad
  
  WorkingDirectory
  /usr/local
  StandardErrorPath
  /usr/local/var/log/postgresql@9.4.log


Then
[jerome@jeroboam] > brew services stop postgresql@9.4
[jerome@jeroboam] > brew services start postgresql@9.4
Then
select * from tutu()
outputs
INFO:  2.7.16 (default, Dec 13 2019, 18:00:32) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s
INFO:  ['/usr/local/lib/python2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Users/jerome/Library/Python/2.7/lib/python/site-packages', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

macOS AnyConnect: AnyConnect cannot confirm it is connected to your secure gateway


Workaround: AnyConnect: Got an error after updating macOS Catalina

Wednesday, February 26, 2020

macOS: ld: warning: directory not found for option '-L/Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk/usr/lib'

If your PostgreSQL extension Makefile uses PGXS like in
PG_CONFIG = pg_config
...
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
And you updated MacOS since you installed PostgreSQL, you may experience the following error at compile time :
[jerome@jeroboam] > make
...
clang -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -D_XOPEN_SOURCE  -L/usr/local/Cellar/postgresql@9.4/9.4.18/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L/Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk/usr/lib  -Wl,-dead_strip_dylibs   -bundle -bundle_loader /usr/local/Cellar/postgresql@9.4/9.4.18/bin/postgres -o src/pg_proctab.so src/pg_proctab.o
ld: warning: directory not found for option '-L/Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk/usr/lib'
Then replace MacOSX10.13 for CPPFLAGS and LDFLAGS in
[jerome@jeroboam] > sudo vi /usr/local/Cellar/postgresql\@9.4/9.4.18/lib/pgxs/src/Makefile.global
with e.g. MacOSX10.15.

MacOS: fatal error: 'sys/vfs.h' file not found

[jerome@jeroboam] > make
clang -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -D_XOPEN_SOURCE  -I. -I./ -I/usr/local/Cellar/postgresql@9.4/9.4.18/include/server -I/usr/local/Cellar/postgresql@9.4/9.4.18/include/internal -I/usr/local/opt/openssl/include -I/usr/local/opt/readline/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk/usr/include/libxml2   -c -o src/pg_proctab.o src/pg_proctab.c
src/pg_proctab.c:14:10: fatal error: 'sys/vfs.h' file not found
#include 
         ^~~~~~~~~~~
1 error generated.
make: *** [src/pg_proctab.o] Error 1
Then replace
#include <sys/vfs.h>
with
#if defined(__APPLE__)
#include <sys/mount.h>
#else
#include <sys/vfs.h>
#endif