1. Install PostgreSQL using MSYS2 and MinGW
(1) Download MSYS2 installer from the following link and install along with the installer
(2) Add path to D:\msys2-64\mingw64\bin.
(3) Start MSYS2 by running the following command in command prompt
(4) Install build tools and debug tool by running the following commands in MSYS2
pacman –needed -S mingw-w64-x86_64-gcc base-devel
pacman –needed -S mingw-w64-x86_64-gdb
(5) Create makefile by running the following comannds in MSYS2
tar -x -zf ./postgresql-13.0.tar.gz
./configure –host=x86_64-w64-mingw32 –prefix=/d/pgsql-13/ –enable-debug
(5) Remove a flag which means code optimization from “src/Makefile.global”
CFLAGS = -Wall (…) -fexcess-precision=standard -g -O2
CXXFLAGS = -Wall (…) -g -O2
CFLAGS = -Wall (…) -fexcess-precision=standard -g
CXXFLAGS = -Wall (…) -g
(6) Execute build and install by running the following comannds in MSYS2
2. Setup PostgreSQL
(1) Add path to d:\pgsql-13\bin
(2) Init database cluster by running the following command in comannd prompt
initdb.exe -D D:\pgsql-13\data
(3) Register PostgreSQL service by running the following command in comannd prompt as the Administrator
pg_ctl.exe register -N “postgresql-x64-13” -U “NT AUTHORITY\NetworkService” -D “D:/pgsql-13/data” -w -S demand
(4) Start servie “postgresql-x64-13”
(5) Create postgres user by running the following command in command prompt. In the following commands, <login_user> is the name of login user and <password> is a password of postges.
psql -U <login_user> -d postgres -c “create user postgres with superuser ‘<password>’ ”
(6) Create sample table and insert sample data into the table in psql terminal.
create table t1(id integer, name text);
insert into t1 values(1, ‘hoge1’);
insert into t1 values(2, ‘hoge2’);
3. Debugging PostgreSQL
(1) Show the pid of PostgreSQL server in psql terminal
(2) Run gdb in command prompt as the Administrator and run the following commands. In the following command, <pid> is the output of (1).
(3) Start sample query, for example, “select * from t1 where id = 1”. If you can see PostgreSQL server stopping at planner() in planner.c, debugging success..
 BUILDING POSTGRESQL WITH MSYS2 AND MINGW UNDER WINDOWS