Install pg_partman on macOS

2.6k Views Asked by At

Hi I have PostgreSQL 12 installed by homebrew and I clone the pg_partman at this commit https://github.com/pgpartman/pg_partman/commit/63328c5bd1f8009fc95592fcdd8ff45f148829e6.

In the cloned folder, I ran make install but it says:

(pg_partman) git:(master) $ make install

cat sql/types/types.sql sql/tables/tables.sql sql/functions/apply_cluster.sql sql/functions/apply_constraints.sql sql/functions/apply_foreign_keys.sql sql/functions/apply_privileges.sql sql/functions/apply_publications.sql sql/functions/autovacuum_off.sql sql/functions/autovacuum_reset.sql sql/functions/check_control_type.sql sql/functions/check_default.sql sql/functions/check_name_length.sql sql/functions/check_subpart_sameconfig.sql sql/functions/check_subpartition_limits.sql sql/functions/create_function_id.sql sql/functions/create_function_time.sql sql/functions/create_parent.sql sql/functions/create_partition_id.sql sql/functions/create_partition_time.sql sql/functions/create_sub_parent.sql sql/functions/create_trigger.sql sql/functions/drop_constraints.sql sql/functions/drop_partition_column.sql sql/functions/drop_partition_id.sql sql/functions/drop_partition_time.sql sql/functions/dump_partition_table_definition.sql sql/functions/inherit_template_properties.sql sql/functions/partition_data_id.sql sql/functions/partition_data_time.sql sql/functions/partition_gap_fill.sql sql/functions/reapply_privileges.sql sql/functions/run_maintenance.sql sql/functions/show_partition_info.sql sql/functions/show_partition_name.sql sql/functions/show_partitions.sql sql/functions/stop_sub_partition.sql sql/functions/undo_partition.sql sql/procedures/partition_data_proc.sql sql/procedures/reapply_constraints_proc.sql sql/procedures/run_maintenance_proc.sql sql/procedures/undo_partition_proc.sql > sql/pg_partman--4.4.1.sql
clang -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -O2  -I. -I./ -I/usr/local/opt/postgresql@12/include/server -I/usr/local/opt/postgresql@12/include/internal -I/usr/local/Cellar/icu4c/67.1/include -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -I/usr/local/opt/[email protected]/include -I/usr/local/opt/readline/include   -c -o src/pg_partman_bgw.o src/pg_partman_bgw.c
src/pg_partman_bgw.c:10:10: fatal error: 'postgres.h' file not found
#include "postgres.h"
         ^~~~~~~~~~~~
1 error generated.
make: *** [src/pg_partman_bgw.o] Error 1

A quick investigations suggest installing postgresql-server-dev-12, but I cant find anything relevant for macOS.

Any idea what am I missing? Thanks in advance!

3

There are 3 best solutions below

0
On

Or use this custom homebrew formula from https://github.com/sj26/homebrew-postgresql-extensions/:

$ brew install sj26/postgresql-extensions/pg_partman

Then follow the instructions to edit postgresql conf.

0
On

I think I had a bad PostgreSQL installed when I asked the question (that’s why missing header). So if you hit the same error, you can try to reinstall your PostgreSQL.

The installation of pg_partman is exactly as how their README described. Clone the repository, change PostgreSQL configuration, restart PostgreSQL, then run CREATE EXTENSION.

$ git clone https://github.com/pgpartman/pg_partman.git
$ cd pg_partman
$ make install

$ vim $HOMEBREW_PREFIX/var/postgres/postgresql.conf
shared_preload_libraries = 'pg_partman_bgw'     # (change requires restart)

$ brew services restart postgresql

$ psql yourdb
=# CREATE EXTENSION pg_partman;

Then you can \dx to see if you got it installed correctly:

List of installed extensions
        Name        | Version |   Schema   |                              Description
--------------------+---------+------------+------------------------------------------------------------------------
 pg_partman         | 4.5.1   | public     | Extension to manage partitioned tables by time or ID
0
On

I installed a specific version of postgres (12) so I guess the installer was not able to find my postgres server directory. The command that worked for me was:

make CFLAGS="-I/usr/local/Cellar/postgresql@12/12.12_2/include/postgresql/server/" install

I had installed postgres with brew install postgresql@12, if your version is different you may need a slightly different path in your command. I found the path by doing:

find /usr/local/Cellar -name "postgres.h" -print

Of course I have multiple versions of postgres installed ‍ so I found the directory of the one I actually run and used that.