Skip to content

Commit de46b1c

Browse files
authored
db.pg: update Windows installation instructions for postgres (#26606)
1 parent dfd9673 commit de46b1c

1 file changed

Lines changed: 51 additions & 29 deletions

File tree

‎vlib/db/pg/README.md‎

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,36 +55,58 @@ gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin
5555

5656
**Windows**:
5757

58+
The directory structure of the `@VEXEROOT/thirdparty/pg` folder will look like the following
59+
after following all instructions. Create the `pg` folder yourself if it does not exist yet.
5860
```
59-
1. Download PostgreSQL SDK from official site
60-
2. Extract archive to postgres-master folder
61-
3. Copy folder postgres-master/src/interfaces/libpq to v/thirdparty/pg
62-
4. Copy file postgres-master/src/include/postgres_ext.h to v/thirdparty/pg/libpq
63-
64-
If you build PostgreSQL from source pg_config_ext.h and pg_config.h will be created automatically:
65-
5. Copy file postgres-master/src/include/pg_config_ext.h to v/thirdparty/pg/libpq
66-
6. Copy file postgres-master/src/include/pg_config.h to v/thirdparty/pg/libpq
67-
68-
If you do not build PostgreSQL from source code:
69-
5. Copy file postgres-master/src/include/pg_config_ext.h.in to v/thirdparty/pg/libpq
70-
- rename pg_config_ext.h.in to pg_config_ext.h
71-
- in pg_config_ext.h change line **#undef PG_INT64_TYPE** to **#define PG_INT64_TYPE long int**
72-
6. Copy file postgres-master/src/include/pg_config.h.in to v/thirdparty/pg/libpq
73-
- rename pg_config.h.in to pg_config.h
74-
- in pg_config.h change line **#undef PG_VERSION_NUM** to **#define PG_VERSION_NUM X0Y0Z**
75-
where X is major db version, Y is minor version, Z is patch version. So if your version is 17.1.2
76-
PG_VERSION_NUM will be 170102, PG_VERSION_NUM should be number, dot sign is changing to 0,
77-
format *PG_VERSION_NUM 17* without 0 also should work
78-
79-
7. Add libpq.dll to v/thirdparty/pg/win64
80-
81-
If you are going to use the msvc compiler:
82-
7. Add libpq.lib(C:\Program Files\PostgreSQL\{version}\lib) to v/thirdparty/pg/win64/msvc
83-
84-
8. Add libpq.dll, libcrypto-3-x64.dll, libssl-3-x64.dll to where your executable is.
85-
86-
To get the libpq.dll file, you can install the PostgreSQL database,
87-
and get this dll from its bin/ folder, or compile DB from source code.
61+
@VEXEROOT/thirdparty/pg
62+
├───libpq
63+
│ libpq-fe.h
64+
│ pg_config.h
65+
│ postgres_ext.h
66+
67+
└───win64
68+
└───msvc
69+
libpq.lib
70+
```
71+
72+
Installation instructions are as follows
73+
```
74+
Download the latest PostgreSQL version from the official website
75+
(currently https://www.enterprisedb.com/downloads/postgres-postgresql-downloads)
76+
77+
In one of the steps in the installer, tick the following boxes:
78+
[X] PostgreSQL Server
79+
[ ] pgAdmin 4
80+
[ ] Stack Builder
81+
[X] Command Line Tools
82+
83+
We need PostgreSQL Server because it brings with it the C header files
84+
needed for building programs that link to `libpq.dll`.
85+
86+
After finishing installation, add the folder `C:/Program Files/PostgreSQL/<version>/bin` to PATH.
87+
Any program that wants to use postgres client functionality require these DLLs found in `/bin`:
88+
- libcrypto-3-x64.dll
89+
- libiconv-2.dll
90+
- libintl-9.dll
91+
- libpq.dll
92+
- libssl-3-x64.dll
93+
- libwinpthread-1.dll
94+
95+
If you want to compile with MSVC, you will need to copy `C:/Program Files/PostgreSQL/<version>/bin/libpq.lib`
96+
into the `@VEXEROOT/thirdparty/pg/win64/msvc` directory.
97+
98+
Navigate to `C:/Program Files/PostgreSQL/<version>/include`. There you will find the files:
99+
- `libpq-fe.h`
100+
- `pg_config.h`
101+
- `postgres_ext.h`
102+
103+
Copy the header files into `@VEXEROOT/thirdparty/pg/libpq`. You can now compile programs using the `db.pg` module.
104+
105+
---
106+
107+
After building an executable that uses `db.pg`, you may want to distribute it to others
108+
who might not have the postgres DLLs installed on their machine. All you need to do is to
109+
make sure a copy of all the required DLLs are in the same folder as your executable.
88110
```
89111

90112
## Getting Started with [PostgreSQL](https://www.postgresqltutorial.com/postgresql-getting-started)

0 commit comments

Comments
 (0)