File tree 14 files changed +92
-31
lines changed
running_pg_cluster_in_docker
1. Hello Postgres cluster
4. Healthcheck and limits
7. Monitoring with postgres_exporter
14 files changed +92
-31
lines changed Original file line number Diff line number Diff line change 2
2
A set of useful SQL scripts (mostly for PostgreSQL)
3
3
4
4
## Content
5
+ * [ Useful commands] ( useful_commands/usefulCommands.md )
6
+ * [ PostgreSQL Performance Optimization] ( performance_optimization/configuration.md )
5
7
* [ How to run PostgreSQL in Docker] ( running_pg_in_docker/postgresInDocker.md )
6
8
* [ How to run PostgreSQL cluster in Docker] ( running_pg_cluster_in_docker/postgresClusterInDocker.md )
Original file line number Diff line number Diff line change 1
- # Оптимизация производительности PostgreSQL
1
+ # PostgreSQL Performance Optimization ( Оптимизация производительности PostgreSQL)
2
2
3
3
Ниже перечислены основные параметры, на которые следует обратить внимание при оптимизации производительности PostgreSQL.
4
4
@@ -25,7 +25,7 @@ show max_wal_size;
25
25
show work_mem;
26
26
```
27
27
28
- [ См.] ( https://www.citusdata.com/blog/2018/06/12/configuring-work-mem-on-postgres/ )
28
+ [ См.] ( https://www.citusdata.com/blog/2018/06/12/configuring-work-mem-on-postgres/ )
29
29
[ См. также] ( https://www.depesz.com/2011/07/03/understanding-postgresql-conf-work_mem/ )
30
30
31
31
### maintenance_work_mem
Original file line number Diff line number Diff line change 2
2
3
3
## Docker Compose
4
4
### Start
5
- ` docker-compose --project-name="habr-pg-ha-14" up -d `
5
+ ``` shell
6
+ docker-compose --project-name=" habr-pg-ha-14" up -d
7
+ ```
6
8
7
9
### Stop
8
- ` docker-compose --project-name="habr-pg-ha-14" down `
10
+ ``` shell
11
+ docker-compose --project-name=" habr-pg-ha-14" down
12
+ ```
9
13
10
14
### Run psql
11
- ` psql -U postgres -d habrdb `
12
- ` psql -U habrpguser -d habrdb `
15
+ ``` shell
16
+ psql -U postgres -d habrdb
17
+ ```
18
+ ``` shell
19
+ psql -U habrpguser -d habrdb
20
+ ```
13
21
14
22
See:
15
23
``` sql
@@ -23,14 +31,14 @@ select case when pg_is_in_recovery() then 'secondary' else 'primary' end as host
23
31
```
24
32
25
33
Without log in to psql:
26
- ``` bash
34
+ ``` shell
27
35
psql -c " select case when pg_is_in_recovery() then 'secondary' else 'primary' end as host_status;" " dbname=habrdb user=habrpguser password=pgpwd4habr"
28
36
```
29
37
30
38
## How to manually init failover
31
39
32
40
### Stop container with current primary
33
- ``` bash
41
+ ``` shell
34
42
docker stop postgres_1
35
43
```
36
44
@@ -43,7 +51,7 @@ LOG: database system is ready to accept connections
43
51
```
44
52
45
53
### Return the first host to the cluster
46
- ``` bash
54
+ ``` shell
47
55
docker start postgres_1
48
56
```
49
57
Original file line number Diff line number Diff line change 1
1
# How to run PostgreSQL cluster in Docker
2
+
3
+ ## Content
4
+ 1 . [ Hello Postgres cluster] ( ./1.%20Hello%20Postgres%20cluster/README.md )
Original file line number Diff line number Diff line change 1
1
# The simplest way to run PostgreSQL in Docker
2
2
3
3
## Docker
4
- ```
4
+ ``` shell
5
5
docker run --name habr-pg-14 -p 5432:5432 -e POSTGRES_USER=habrpguser -e POSTGRES_PASSWORD=pgpwd4habr -e POSTGRES_DB=habrdb -d postgres:14.5
6
6
```
7
7
8
8
### Run psql
9
- ` psql -U habrpguser -d habrdb `
9
+ ``` shell
10
+ psql -U habrpguser -d habrdb
11
+ ```
10
12
11
13
## Docker Compose
12
14
### Start
13
- ` docker-compose --project-name="habr-pg-14" up -d `
15
+ ``` shell
16
+ docker-compose --project-name=" habr-pg-14" up -d
17
+ ```
14
18
15
19
### Stop
16
- ` docker-compose --project-name="habr-pg-14" down `
20
+ ``` shell
21
+ docker-compose --project-name=" habr-pg-14" down
22
+ ```
Original file line number Diff line number Diff line change 1
1
# Initializing Postgres database at startup
2
2
3
3
## Docker
4
- ```
4
+ ``` shell
5
5
docker run --name habr-pg-14 -p 5432:5432 -e POSTGRES_USER=habrpguser -e POSTGRES_PASSWORD=pgpwd4habr -e POSTGRES_DB=habrdb -d -v " /absolute/path/to/directory-with-init-scripts" :/docker-entrypoint-initdb.d postgres:14.5
6
6
```
7
7
8
8
### Auto detect current directory (for macOS and Linux)
9
- ```
9
+ ``` shell
10
10
docker run --name habr-pg-14 -p 5432:5432 -e POSTGRES_USER=habrpguser -e POSTGRES_PASSWORD=pgpwd4habr -e POSTGRES_DB=habrdb -d -v " $( pwd) " :/docker-entrypoint-initdb.d postgres:14.5
11
11
```
12
12
13
13
### Run psql
14
- ` psql -U habrpguser -d habrdb `
14
+ ``` shell
15
+ psql -U habrpguser -d habrdb
16
+ ```
15
17
16
18
## Docker Compose
17
19
### Start
18
- ` docker-compose --project-name="habr-pg-14" up -d `
20
+ ``` shell
21
+ docker-compose --project-name=" habr-pg-14" up -d
22
+ ```
19
23
20
24
### Stop
21
- ` docker-compose --project-name="habr-pg-14" down `
25
+ ``` shell
26
+ docker-compose --project-name=" habr-pg-14" down
27
+ ```
Original file line number Diff line number Diff line change 1
1
# Specifying catalog for database files
2
2
3
3
## Docker
4
- ```
4
+ ``` shell
5
5
docker run --name habr-pg-14 -p 5432:5432 -e POSTGRES_USER=habrpguser -e POSTGRES_PASSWORD=pgpwd4habr -e POSTGRES_DB=habrdb -e PGDATA=/var/lib/postgresql/data/pgdata -d -v " /absolute/path/to/directory-with-data" :/var/lib/postgresql/data -v " /absolute/path/to/directory-with-init-scripts" :/docker-entrypoint-initdb.d postgres:14.5
6
6
```
7
7
8
8
### Auto-detect current directory (for macOS and Linux)
9
- ```
9
+ ``` shell
10
10
docker run --name habr-pg-14 -p 5432:5432 -e POSTGRES_USER=habrpguser -e POSTGRES_PASSWORD=pgpwd4habr -e POSTGRES_DB=habrdb -e PGDATA=/var/lib/postgresql/data/pgdata -d -v " $( pwd) " :/var/lib/postgresql/data -v " $( pwd) /../2. Init Database" :/docker-entrypoint-initdb.d postgres:14.5
11
11
```
12
12
13
13
## Docker Compose
14
14
### Start
15
- ` docker-compose --project-name="habr-pg-14" up -d `
15
+ ``` shell
16
+ docker-compose --project-name=" habr-pg-14" up -d
17
+ ```
16
18
17
19
### Stop
18
- ` docker-compose --project-name="habr-pg-14" down `
20
+ ``` shell
21
+ docker-compose --project-name=" habr-pg-14" down
22
+ ```
Original file line number Diff line number Diff line change 2
2
3
3
## Docker Compose
4
4
### Start
5
- ` docker-compose --project-name="habr-pg-14" up -d `
5
+ ``` shell
6
+ docker-compose --project-name=" habr-pg-14" up -d
7
+ ```
6
8
7
9
### Stop
8
- ` docker-compose --project-name="habr-pg-14" down `
10
+ ``` shell
11
+ docker-compose --project-name=" habr-pg-14" down
12
+ ```
Original file line number Diff line number Diff line change 2
2
3
3
## Docker Compose
4
4
### Start
5
- ` docker-compose --project-name="habr-pg-14" up -d `
5
+ ``` shell
6
+ docker-compose --project-name=" habr-pg-14" up -d
7
+ ```
6
8
7
9
### Stop
8
- ` docker-compose --project-name="habr-pg-14" down `
10
+ ``` shell
11
+ docker-compose --project-name=" habr-pg-14" down
12
+ ```
Original file line number Diff line number Diff line change 2
2
3
3
## Docker Compose
4
4
### Start
5
- ` docker-compose --project-name="habr-pg-14" up -d `
5
+ ``` shell
6
+ docker-compose --project-name=" habr-pg-14" up -d
7
+ ```
6
8
7
9
### Stop
8
- ` docker-compose --project-name="habr-pg-14" down `
10
+ ``` shell
11
+ docker-compose --project-name=" habr-pg-14" down
12
+ ```
9
13
10
14
## Access to PgAdmin
11
15
Open in browser [ http://localhost:5050 ] ( http://localhost:5050 )
Original file line number Diff line number Diff line change 2
2
3
3
## Docker Compose
4
4
### Start
5
- ` docker-compose --project-name="habr-pg-14" up -d `
5
+ ``` shell
6
+ docker-compose --project-name=" habr-pg-14" up -d
7
+ ```
6
8
7
9
### Stop
8
- ` docker-compose --project-name="habr-pg-14" down `
10
+ ``` shell
11
+ docker-compose --project-name=" habr-pg-14" down
12
+ ```
9
13
10
14
## Access to PgAdmin
11
15
Open in browser [ http://localhost:5050 ] ( http://localhost:5050 )
Original file line number Diff line number Diff line change 1
1
# How to run PostgreSQL in Docker
2
+ Read my article on Habr [ Running PostgreSQL in Docker: from simple to complex] ( https://habr.com/ru/articles/578744/ )
3
+
4
+ ## Content
5
+ 1 . [ Hello Postgres] ( ./1.%20Hello%20Postgres/README.md )
6
+ 2 . [ Init Database] ( ./2.%20Init%20Database/README.md )
7
+ 3 . [ Where is my data] ( ./3.%20Where%20is%20my%20data/README.md )
8
+ 4 . [ Healthcheck and limits] ( ./4.%20Healthcheck%20and%20limits/README.md )
9
+ 5 . [ Tuning parameters] ( ./5.%20Tuning%20parameters/README.md )
10
+ 6 . [ UI via pgAdmin] ( ./6.%20UI%20via%20pgAdmin/README.md )
11
+ 7 . [ Monitoring with postgres_exporter] ( ./7.%20Monitoring%20with%20postgres_exporter/README.md )
Original file line number Diff line number Diff line change 1
- ## Getting information about the PostgreSQL database
1
+ ## Getting information about PostgreSQL database
2
2
3
3
### Replication status, list of replicas (synchronous\asynchronous)
4
4
``` sql
Original file line number Diff line number Diff line change
1
+ # Useful commands for PostgreSQL users
2
+
3
+ ## Content
4
+ * [ Getting information about PostgreSQL database] ( ./db_info.md )
5
+ * [ Index Maintenance] ( ./index_maintenance.md )
6
+ * [ System Administration Functions] ( ./kill_process.md )
You can’t perform that action at this time.
0 commit comments