Skip to content

Commit 4dd809b

Browse files
committed
docs: add vs code setup doc page
This is not yet ready, because it lacks `tasks.json` file setup. It will be ready when page with postgresql configuration with setup scripts will be ready
1 parent c847a8b commit 4dd809b

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed
66.3 KB
Loading

docs/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ This is a VS Code extension to assist PostgreSQL Hackers - source code developer
55
## Table of contents
66

77
- [Configuration](./configuration.md)
8+
- [VS Code setup](./vscode_setup.md)
9+
- Tutorials:
10+
- [Create extension](./create_extension.md)

docs/vscode_setup.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# Visual Studio Code setup
2+
3+
Here is shown VS Code setup for PostgreSQL debugging.
4+
5+
## Extensions
6+
7+
### PostgreSQL Hacker Helper
8+
9+
This is the main extension we are talking about. It significantly simplifies development and debugging of source code.
10+
11+
[Link](https://marketplace.visualstudio.com/items?itemName=ash-blade.postgresql-hacker-helper).
12+
13+
This is the only extension I recommend installing, because there are no alternatives to it.
14+
For the further extensions you are free to choose that suit you - no restrictions, just suggestions.
15+
16+
### Debugger extension
17+
18+
First things first, you have to install debugger extension, which will provide debugging functionality.
19+
20+
There are 2 supported (by PostgreSQL Hacker Helper) debugger extensions:
21+
22+
- [C/C++](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)
23+
- [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)
24+
25+
Which one to choose is up to you, but I use a rule of thumb: if have built source code using `gcc`, then C/C++ with `dbg` debugger, otherwise (`clang`) use `CodeLLDB` with `lldb` debugger.
26+
27+
Also, you would like to have autocompletions. You can use [IntelliCode Completions](https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.vscodeintellicode-completions).
28+
29+
### Perl
30+
31+
PostgreSQL has different test types. One of them is TAP-tests which are written in Perl, so you might want to add extension with Perl support.
32+
33+
Example, [Perl](https://marketplace.visualstudio.com/items?itemName=richterger.perl) extension.
34+
35+
### Markdown
36+
37+
This is utility extension that will help create markdown files.
38+
They are popular because many documentation or README are written using Markdown syntax.
39+
40+
Example: [Markdown All in One](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one).
41+
42+
### SQL queries
43+
44+
SQL is the main language, so SQL-syntax support is must-have.
45+
46+
You can use builtin SQL syntax support, or install [Better PostgreSQL syntax](https://marketplace.visualstudio.com/items?itemName=felixfbecker.postgresql-syntax) extension which provides several PostgreSQL specific syntax features, like type cast.
47+
48+
### Database connections
49+
50+
When developing you may need to connect to database and execute queries.
51+
For this you can choose any tool: `psql`, `pgAdmin` or vs code extension.
52+
53+
There is no recommendation, because I do not use VS Code extension: only `psql` or `pgAdmin`, because VS Code extension targets primarily on Database usage while I am as database *source code* developer can request specific features that general extension does not provide. In example, I can create patch, that breaks binary protocol compatibility or adds extensions to it, which is obviously not supported by extension. Thus it is more preferable to have your own automation scripts.
54+
55+
Moreover, you may have multiple different versions of PostgreSQL installed on your system simultaneously and again, it is unlikely that the general solution (extension) takes into account such features.
56+
57+
## `launch.json`
58+
59+
File `.vscode/launch.json` describes debug session configuration: name, debugger, path to binary/pid to attach, launch args, etc...
60+
When we are talking about PostgreSQL you should remember that it has multi-process architecture, not multi-threaded, this defines how we start debugging.
61+
Next, typical configurations for different uses cases will be presented.
62+
63+
### Backend
64+
65+
Mostly you will be debugging a backend. It forks from postmaster, setup it's own state and then start main query processing loop.
66+
As it forks, then we can not just launch backend as usual binary - we have to attach to specific pid.
67+
68+
```json
69+
{
70+
"version": "0.2.0",
71+
"configurations": [
72+
{
73+
"name": "Backend (cppdbg)",
74+
"type": "cppdbg",
75+
"request": "attach",
76+
"program": "${workspaceFolder}/src/backend/postgres",
77+
"processId": "${command:pickProcess}",
78+
"MIMode": "gdb",
79+
"setupCommands": [
80+
{
81+
"description": "Enable pretty-printing for gdb",
82+
"text": "-enable-pretty-printing",
83+
"ignoreFailures": true
84+
}
85+
],
86+
"internalConsoleOptions": "neverOpen",
87+
},
88+
{
89+
"name": "Backend (lldb)",
90+
"type": "lldb",
91+
"request": "attach",
92+
"program": "${workspaceFolder}/src/backend/postgres",
93+
"pid": "${command:pickProcess}",
94+
"internalConsoleOptions": "neverOpen"
95+
}
96+
]
97+
}
98+
```
99+
100+
These are template configurations created by default, but with some customization:
101+
102+
1. To get PID of process special value is used: `${command:pickProcess}` - it will open quick pick window where you can choose backend to attach.
103+
It shows all running processes, but actually all you have to do is to type "postgres" and choose penultimate element - usually it is the only running backend.
104+
![Shown quick-pick window with target backend](./img/vscode_setup/quickpick_pid.png)
105+
2. `"program"` points to `src/backend/postgres` - default location of `postgres` binary. It contains all server debug symbols and it's location do not change, so you do not have to specify installation path each time.
106+
3. `internalConsoleOptions` is set to `neverOpen` because when debugging starts C/C++ extension opens `Debug Console` and shows logs, but usually it is not necessary and just only knocks down the focus.
107+
108+
### Frontend
109+
110+
Frontend - are all utilities that run outside the server, i.e. `pg_dump`, `pg_ctl`, etc...
111+
112+
They are separate binaries, so you can launch them directly, but usually they interact with the database, so they need database installation info.
113+
114+
We can pass it directly using flags, but a better idea would be to use environment variables, because different binaries can use different flags.
115+
116+
All frontend utilities are located in own `src/bin/UTILITY_NAME` directory and after building each directory contains it's binary.
117+
118+
For example configuration for `pg_ctl` would be:
119+
120+
```json
121+
{
122+
"version": "0.2.0",
123+
"configurations": [
124+
{
125+
"name": "pg_ctl",
126+
"type": "cppdbg",
127+
"request": "launch",
128+
"program": "${workspaceFolder}/src/bin/pg_ctl/pg_ctl",
129+
"cwd": "${workspaceFolder}",
130+
"args": [
131+
"status"
132+
],
133+
"environment": [
134+
{
135+
"name": "PGDATA",
136+
"value": "${workspaceFolder}/data"
137+
}
138+
]
139+
}
140+
]
141+
}
142+
```
143+
144+
Here we are debugging `pg_ctl status` command (see `"args"`) and pass `PGDATA` environment variable directly.
145+
146+
The value of it can be any, but in the example I suppose that for development purposes your installation in `data` directory in the repository itself.
147+
148+
> A better idea than passing environment variables would be to pass environmental variable *file*.
149+
> It have 2 benefits against manual specifying:
150+
>
151+
> 1. This file can be automatically generated during database creation
152+
> 2. If you have configuration for multiple binaries, then you do not have to enter the same parameters - just pass this env file.
153+
154+
## `tasks.json`
155+
156+
TODO

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ theme: readthedocs
55
nav:
66
- Home: index.md
77
- Configuration: configuration.md
8+
- VS Code setup: vscode_setup.md
89
- Tutorials:
910
- Create extension: create_extension.md

0 commit comments

Comments
 (0)