1

I am trying to add POWA to my PostgreSQL installation. In order to do that I have to add an extension called pg_stat_statements. Since I am on windows platform I have to create a DLL of this extension and add it to the lib folder of PostgreSQL. I Followed the tutorial in this link. It is for PostgreSQL 9.3 using Visual Studio 2010. But I am using PostgreSQL 9.6.1 and Visual Studio 2015.

I am sure that I didn't miss any step in that tutorial. I have set the compilation mode to C and included the source file paths. But I am getting many compilation errors when I try to build my project.

See this image for included paths and compilation errors

Why am I getting errors even after including all the necessary source files? When I include the pg_stat_statements.c file I get even more errors?

I am not familiar with C/C++ coding. Please help me to solve this issue.

user3112250
  • 53
  • 1
  • 10
  • Your include paths look like they're pointing at the Postgres source code. You should use the includes which were installed with the server, e.g. in `C:\Program Files\PostgreSQL\9.6\include`. – Nick Barnes Oct 31 '16 at 21:04
  • @NickBarnes No, I have pointed to my PostgreSQL installed directory, not to source code – user3112250 Oct 31 '16 at 21:41
  • The REL9_6_1 directory isn't part of a standard Postgres installation. Does `F:\PostgreSQL\9.6\include` exist? – Nick Barnes Nov 01 '16 at 01:47
  • @NickBarnes I added REL9_6_1 directory while compiling and installing the code. That is my installation path. What's the problem with that? – user3112250 Nov 01 '16 at 16:05

1 Answers1

3

pg_stat_statements is bundled in PostgreSQL. You don't need to compile it yourself.


Update: user compiled PostgreSQL its self from source. In this case, pg_stat_statements is part of contrib/ and is compiled with the rest of the contrib tools.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • No, pg_stat_statements are not bundled in PostgreSQL. We have to execute the create extension command to add this extension. That alone not enough for windows. We have to add the DLL to the lib folder of PostgreSQL – user3112250 Nov 01 '16 at 16:06
  • @user3112250: If you used the [Windows installer](http://www.enterprisedb.com/products-services-training/pgdownload#windows), then `pg_stat_statements.dll` should already be there – Nick Barnes Nov 01 '16 at 21:38
  • Right, you still have to `CREATE EXTENSION pg_stat_statements` but the DLL should be there already. If it isn't, you're probably using some dodgy redistribution of PostgreSQL. – Craig Ringer Nov 02 '16 at 01:37
  • @CraigRinger I didn't use windows installer. I download the code form git and compiled myself. When I execute create extension I get an error saying: could not access file "$libdir/pg_stat_statements": No such file or directory – user3112250 Nov 02 '16 at 09:34
  • Anyway I will have to compile the powa.c file in order to add powa. Therefore I want to resolve those compilation errors – user3112250 Nov 02 '16 at 09:36
  • @user3112250 Well, that was critical information. If you compiled from source you don't need to create a visual studio project for the extension, it's already in `contrib`. You just have to compile and install the contrib modules that are part of the PostgreSQL source distribution. This should be done automatically when you run `.\src\tools\msvc\build` so I'm ... puzzled ... as to why it's not already installed. But run `.\src\tools\msvc\build contrib` then `.\src\tools\msvc\install contrib` to confirm. If you want to modify `pg_stat_statements` modify the one in your postgres source tree. – Craig Ringer Nov 02 '16 at 12:38
  • The reference to `powa.c` seems to be regarding https://github.com/dalibo/powa-archivist . That's a whole different extension. You can't just drop it into `pg_stat_statements`. – Craig Ringer Nov 02 '16 at 12:44
  • @CraigRinger Well, I used msys2 to compile the source using gcc. It didn't install pg_stat_statements. After seeing your comment what I did was, I installed PostgreSQL using the windows installer and copied the DLL from that to my lib folder. Then I was able to create the extension. Now I want to install powa (https://github.com/dalibo/powa-archivist). When I try to compile it using windows I am getting the same Visual Studio compilation errors. – user3112250 Nov 02 '16 at 13:20
  • Ugh, you shouldn't do that. Why not just compile `contrib` with msys2 as well? As for POWA, do you know it's actually supposed to work on Windows? Try adding the `powa-archivist` dir to `contrib/`, adding it to the `subdirs` list in `contrib/Makefile`, and compiling it there. – Craig Ringer Nov 02 '16 at 13:23
  • @CraigRinger I wanted to install pg_stat_statements because it is required by powa as mentioned in the question. Please tell me why I am getting those compilation errors from c.h, palloc.h and fmgr.h. Anyway your comments helped me to resolve part of my problem. So Please update your answer, then I can accept it. – user3112250 Nov 02 '16 at 13:24
  • Can't really say why you're getting the errors w/o the full project file and more time than I have. Something's wrong with includes, possibly also missing appropriate macros. – Craig Ringer Nov 02 '16 at 13:25
  • @CraigRinger I will take your advise and try to compile the contrib folder. If I understand you properly, You are telling me to add the powa source also to the contrib/ and compile it. I will do that and see. – user3112250 Nov 02 '16 at 13:28