container-superposition 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +843 -0
- package/dist/scripts/init.d.ts +3 -0
- package/dist/scripts/init.d.ts.map +1 -0
- package/dist/scripts/init.js +1190 -0
- package/dist/scripts/init.js.map +1 -0
- package/dist/scripts/migrate-to-manifests.d.ts +12 -0
- package/dist/scripts/migrate-to-manifests.d.ts.map +1 -0
- package/dist/scripts/migrate-to-manifests.js +230 -0
- package/dist/scripts/migrate-to-manifests.js.map +1 -0
- package/dist/tool/questionnaire/composer.d.ts +6 -0
- package/dist/tool/questionnaire/composer.d.ts.map +1 -0
- package/dist/tool/questionnaire/composer.js +1232 -0
- package/dist/tool/questionnaire/composer.js.map +1 -0
- package/dist/tool/readme/markdown-parser.d.ts +30 -0
- package/dist/tool/readme/markdown-parser.d.ts.map +1 -0
- package/dist/tool/readme/markdown-parser.js +139 -0
- package/dist/tool/readme/markdown-parser.js.map +1 -0
- package/dist/tool/readme/readme-generator.d.ts +9 -0
- package/dist/tool/readme/readme-generator.d.ts.map +1 -0
- package/dist/tool/readme/readme-generator.js +422 -0
- package/dist/tool/readme/readme-generator.js.map +1 -0
- package/dist/tool/schema/custom-loader.d.ts +17 -0
- package/dist/tool/schema/custom-loader.d.ts.map +1 -0
- package/dist/tool/schema/custom-loader.js +149 -0
- package/dist/tool/schema/custom-loader.js.map +1 -0
- package/dist/tool/schema/overlay-loader.d.ts +47 -0
- package/dist/tool/schema/overlay-loader.d.ts.map +1 -0
- package/dist/tool/schema/overlay-loader.js +252 -0
- package/dist/tool/schema/overlay-loader.js.map +1 -0
- package/dist/tool/schema/types.d.ts +212 -0
- package/dist/tool/schema/types.d.ts.map +1 -0
- package/dist/tool/schema/types.js +5 -0
- package/dist/tool/schema/types.js.map +1 -0
- package/docs/README.md +308 -0
- package/docs/architecture.md +233 -0
- package/docs/creating-overlays.md +549 -0
- package/docs/custom-patches.md +540 -0
- package/docs/dependencies.md +279 -0
- package/docs/examples/custom-patches-example.md +85 -0
- package/docs/examples.md +576 -0
- package/docs/messaging-comparison.md +265 -0
- package/docs/messaging-quick-start.md +385 -0
- package/docs/observability-workflow.md +537 -0
- package/docs/overlay-manifest-refactoring.md +214 -0
- package/docs/overlay-metadata-archive.md +54 -0
- package/docs/overlays.md +523 -0
- package/docs/presets-architecture.md +498 -0
- package/docs/presets.md +366 -0
- package/docs/publishing.md +476 -0
- package/docs/quick-reference.md +326 -0
- package/docs/ux.md +170 -0
- package/features/README.md +85 -0
- package/features/cross-distro-packages/README.md +146 -0
- package/features/cross-distro-packages/devcontainer-feature.json +20 -0
- package/features/cross-distro-packages/install.sh +58 -0
- package/features/local-secrets-manager/devcontainer-feature.json +18 -0
- package/features/local-secrets-manager/install.sh +127 -0
- package/features/project-scaffolder/devcontainer-feature.json +24 -0
- package/features/project-scaffolder/install.sh +100 -0
- package/features/team-conventions/devcontainer-feature.json +24 -0
- package/features/team-conventions/install.sh +93 -0
- package/overlays/.registry/README.md +14 -0
- package/overlays/.registry/base-images.yml +26 -0
- package/overlays/.registry/base-templates.yml +7 -0
- package/overlays/README.md +155 -0
- package/overlays/alertmanager/.env.example +5 -0
- package/overlays/alertmanager/README.md +465 -0
- package/overlays/alertmanager/alert-rules.yml +56 -0
- package/overlays/alertmanager/alertmanager.yml +42 -0
- package/overlays/alertmanager/devcontainer.patch.json +12 -0
- package/overlays/alertmanager/docker-compose.yml +20 -0
- package/overlays/alertmanager/overlay.yml +17 -0
- package/overlays/alertmanager/setup.sh +53 -0
- package/overlays/alertmanager/verify.sh +31 -0
- package/overlays/aws-cli/README.md +473 -0
- package/overlays/aws-cli/devcontainer.patch.json +13 -0
- package/overlays/aws-cli/overlay.yml +13 -0
- package/overlays/azure-cli/README.md +551 -0
- package/overlays/azure-cli/devcontainer.patch.json +8 -0
- package/overlays/azure-cli/overlay.yml +13 -0
- package/overlays/bun/README.md +312 -0
- package/overlays/bun/devcontainer.patch.json +41 -0
- package/overlays/bun/overlay.yml +16 -0
- package/overlays/bun/setup.sh +79 -0
- package/overlays/bun/verify.sh +30 -0
- package/overlays/codex/README.md +128 -0
- package/overlays/codex/devcontainer.patch.json +3 -0
- package/overlays/codex/overlay.yml +14 -0
- package/overlays/codex/setup.sh +24 -0
- package/overlays/codex/verify.sh +30 -0
- package/overlays/commitlint/README.md +333 -0
- package/overlays/commitlint/devcontainer.patch.json +8 -0
- package/overlays/commitlint/overlay.yml +16 -0
- package/overlays/commitlint/setup.sh +234 -0
- package/overlays/direnv/README.md +504 -0
- package/overlays/direnv/devcontainer.patch.json +6 -0
- package/overlays/direnv/overlay.yml +13 -0
- package/overlays/direnv/setup.sh +139 -0
- package/overlays/docker-in-docker/README.md +534 -0
- package/overlays/docker-in-docker/devcontainer.patch.json +10 -0
- package/overlays/docker-in-docker/overlay.yml +13 -0
- package/overlays/docker-sock/README.md +256 -0
- package/overlays/docker-sock/devcontainer.patch.json +9 -0
- package/overlays/docker-sock/docker-compose.yml +8 -0
- package/overlays/docker-sock/overlay.yml +13 -0
- package/overlays/dotnet/README.md +147 -0
- package/overlays/dotnet/devcontainer.patch.json +51 -0
- package/overlays/dotnet/global-tools.txt +24 -0
- package/overlays/dotnet/overlay.yml +13 -0
- package/overlays/dotnet/setup.sh +51 -0
- package/overlays/dotnet/verify.sh +26 -0
- package/overlays/gcloud/README.md +269 -0
- package/overlays/gcloud/devcontainer.patch.json +14 -0
- package/overlays/gcloud/overlay.yml +14 -0
- package/overlays/gcloud/verify.sh +52 -0
- package/overlays/git-helpers/README.md +168 -0
- package/overlays/git-helpers/devcontainer.patch.json +33 -0
- package/overlays/git-helpers/overlay.yml +15 -0
- package/overlays/git-helpers/setup.sh +91 -0
- package/overlays/go/README.md +293 -0
- package/overlays/go/devcontainer.patch.json +43 -0
- package/overlays/go/overlay.yml +15 -0
- package/overlays/go/setup.sh +33 -0
- package/overlays/go/verify.sh +40 -0
- package/overlays/grafana/.env.example +9 -0
- package/overlays/grafana/README.md +462 -0
- package/overlays/grafana/dashboard-provider.yml +11 -0
- package/overlays/grafana/dashboards/observability-overview.json +263 -0
- package/overlays/grafana/devcontainer.patch.json +12 -0
- package/overlays/grafana/docker-compose.yml +27 -0
- package/overlays/grafana/grafana-datasources.yml +57 -0
- package/overlays/grafana/overlay.yml +21 -0
- package/overlays/grafana/verify.sh +34 -0
- package/overlays/jaeger/.env.example +7 -0
- package/overlays/jaeger/README.md +867 -0
- package/overlays/jaeger/devcontainer.patch.json +12 -0
- package/overlays/jaeger/docker-compose.yml +17 -0
- package/overlays/jaeger/overlay.yml +19 -0
- package/overlays/java/README.md +267 -0
- package/overlays/java/devcontainer.patch.json +44 -0
- package/overlays/java/overlay.yml +16 -0
- package/overlays/java/setup.sh +41 -0
- package/overlays/java/verify.sh +42 -0
- package/overlays/just/README.md +443 -0
- package/overlays/just/devcontainer.patch.json +3 -0
- package/overlays/just/overlay.yml +13 -0
- package/overlays/just/setup.sh +182 -0
- package/overlays/kubectl-helm/README.md +660 -0
- package/overlays/kubectl-helm/devcontainer.patch.json +10 -0
- package/overlays/kubectl-helm/overlay.yml +13 -0
- package/overlays/loki/.env.example +5 -0
- package/overlays/loki/README.md +1156 -0
- package/overlays/loki/devcontainer.patch.json +12 -0
- package/overlays/loki/docker-compose.yml +18 -0
- package/overlays/loki/loki-config.yaml +45 -0
- package/overlays/loki/overlay.yml +17 -0
- package/overlays/minio/.env.example +9 -0
- package/overlays/minio/README.md +639 -0
- package/overlays/minio/devcontainer.patch.json +30 -0
- package/overlays/minio/docker-compose.yml +28 -0
- package/overlays/minio/overlay.yml +18 -0
- package/overlays/minio/setup.sh +61 -0
- package/overlays/minio/verify.sh +64 -0
- package/overlays/mkdocs/README.md +309 -0
- package/overlays/mkdocs/devcontainer.patch.json +24 -0
- package/overlays/mkdocs/overlay.yml +15 -0
- package/overlays/modern-cli-tools/README.md +556 -0
- package/overlays/modern-cli-tools/devcontainer.patch.json +3 -0
- package/overlays/modern-cli-tools/overlay.yml +13 -0
- package/overlays/modern-cli-tools/setup.sh +153 -0
- package/overlays/mongodb/.env.example +9 -0
- package/overlays/mongodb/README.md +481 -0
- package/overlays/mongodb/devcontainer.patch.json +32 -0
- package/overlays/mongodb/docker-compose.yml +44 -0
- package/overlays/mongodb/overlay.yml +17 -0
- package/overlays/mongodb/verify.sh +48 -0
- package/overlays/mysql/.env.example +11 -0
- package/overlays/mysql/README.md +542 -0
- package/overlays/mysql/devcontainer.patch.json +34 -0
- package/overlays/mysql/docker-compose.yml +55 -0
- package/overlays/mysql/overlay.yml +16 -0
- package/overlays/mysql/verify.sh +48 -0
- package/overlays/nats/.env.example +5 -0
- package/overlays/nats/README.md +762 -0
- package/overlays/nats/devcontainer.patch.json +24 -0
- package/overlays/nats/docker-compose.yml +31 -0
- package/overlays/nats/overlay.yml +18 -0
- package/overlays/nats/verify.sh +50 -0
- package/overlays/ngrok/README.md +503 -0
- package/overlays/ngrok/devcontainer.patch.json +3 -0
- package/overlays/ngrok/overlay.yml +14 -0
- package/overlays/ngrok/setup.sh +125 -0
- package/overlays/nodejs/README.md +192 -0
- package/overlays/nodejs/devcontainer.patch.json +49 -0
- package/overlays/nodejs/global-packages.txt +16 -0
- package/overlays/nodejs/overlay.yml +14 -0
- package/overlays/nodejs/setup.sh +46 -0
- package/overlays/nodejs/verify.sh +32 -0
- package/overlays/otel-collector/.env.example +9 -0
- package/overlays/otel-collector/README.md +1257 -0
- package/overlays/otel-collector/devcontainer.patch.json +28 -0
- package/overlays/otel-collector/docker-compose.yml +22 -0
- package/overlays/otel-collector/otel-collector-config.yaml +68 -0
- package/overlays/otel-collector/overlay.yml +21 -0
- package/overlays/otel-collector/setup.sh +49 -0
- package/overlays/otel-demo-nodejs/.env.example +2 -0
- package/overlays/otel-demo-nodejs/Dockerfile-otel-demo-nodejs +17 -0
- package/overlays/otel-demo-nodejs/README.md +409 -0
- package/overlays/otel-demo-nodejs/devcontainer.patch.json +12 -0
- package/overlays/otel-demo-nodejs/docker-compose.yml +19 -0
- package/overlays/otel-demo-nodejs/overlay.yml +23 -0
- package/overlays/otel-demo-nodejs/package-otel-demo-nodejs.json +20 -0
- package/overlays/otel-demo-nodejs/server-otel-demo-nodejs.js +259 -0
- package/overlays/otel-demo-nodejs/tracing-otel-demo-nodejs.js +57 -0
- package/overlays/otel-demo-nodejs/verify.sh +31 -0
- package/overlays/otel-demo-python/.env.example +2 -0
- package/overlays/otel-demo-python/Dockerfile-otel-demo-python +16 -0
- package/overlays/otel-demo-python/README.md +82 -0
- package/overlays/otel-demo-python/app-otel-demo-python.py +208 -0
- package/overlays/otel-demo-python/devcontainer.patch.json +12 -0
- package/overlays/otel-demo-python/docker-compose.yml +19 -0
- package/overlays/otel-demo-python/overlay.yml +23 -0
- package/overlays/otel-demo-python/requirements-otel-demo-python.txt +4 -0
- package/overlays/otel-demo-python/verify.sh +31 -0
- package/overlays/playwright/README.md +629 -0
- package/overlays/playwright/devcontainer.patch.json +9 -0
- package/overlays/playwright/overlay.yml +13 -0
- package/overlays/postgres/.env.example +6 -0
- package/overlays/postgres/README.md +602 -0
- package/overlays/postgres/devcontainer.patch.json +21 -0
- package/overlays/postgres/docker-compose.yml +22 -0
- package/overlays/postgres/overlay.yml +15 -0
- package/overlays/postgres/verify.sh +45 -0
- package/overlays/powershell/README.md +314 -0
- package/overlays/powershell/devcontainer.patch.json +22 -0
- package/overlays/powershell/overlay.yml +13 -0
- package/overlays/powershell/setup.sh +29 -0
- package/overlays/powershell/verify.sh +38 -0
- package/overlays/pre-commit/README.md +263 -0
- package/overlays/pre-commit/devcontainer.patch.json +9 -0
- package/overlays/pre-commit/overlay.yml +16 -0
- package/overlays/pre-commit/setup.sh +129 -0
- package/overlays/presets/docs-site.yml +118 -0
- package/overlays/presets/fullstack.yml +181 -0
- package/overlays/presets/microservice.yml +118 -0
- package/overlays/presets/web-api.yml +109 -0
- package/overlays/prometheus/.env.example +5 -0
- package/overlays/prometheus/README.md +1246 -0
- package/overlays/prometheus/devcontainer.patch.json +12 -0
- package/overlays/prometheus/docker-compose.yml +22 -0
- package/overlays/prometheus/overlay.yml +17 -0
- package/overlays/prometheus/prometheus.yml +12 -0
- package/overlays/prometheus/verify.sh +34 -0
- package/overlays/promtail/.env.example +2 -0
- package/overlays/promtail/README.md +357 -0
- package/overlays/promtail/devcontainer.patch.json +5 -0
- package/overlays/promtail/docker-compose.yml +16 -0
- package/overlays/promtail/overlay.yml +17 -0
- package/overlays/promtail/promtail-config.yaml +60 -0
- package/overlays/promtail/verify.sh +31 -0
- package/overlays/pulumi/README.md +472 -0
- package/overlays/pulumi/devcontainer.patch.json +13 -0
- package/overlays/pulumi/overlay.yml +14 -0
- package/overlays/pulumi/verify.sh +31 -0
- package/overlays/python/README.md +919 -0
- package/overlays/python/devcontainer.patch.json +41 -0
- package/overlays/python/overlay.yml +12 -0
- package/overlays/python/requirements-overlay.txt +13 -0
- package/overlays/python/setup.sh +47 -0
- package/overlays/python/verify.sh +32 -0
- package/overlays/rabbitmq/.env.example +7 -0
- package/overlays/rabbitmq/README.md +680 -0
- package/overlays/rabbitmq/devcontainer.patch.json +28 -0
- package/overlays/rabbitmq/docker-compose.yml +30 -0
- package/overlays/rabbitmq/overlay.yml +18 -0
- package/overlays/rabbitmq/verify.sh +41 -0
- package/overlays/redis/.env.example +4 -0
- package/overlays/redis/README.md +776 -0
- package/overlays/redis/devcontainer.patch.json +21 -0
- package/overlays/redis/docker-compose.yml +21 -0
- package/overlays/redis/overlay.yml +15 -0
- package/overlays/redis/verify.sh +41 -0
- package/overlays/redpanda/.env.example +10 -0
- package/overlays/redpanda/README.md +703 -0
- package/overlays/redpanda/devcontainer.patch.json +37 -0
- package/overlays/redpanda/docker-compose.yml +67 -0
- package/overlays/redpanda/overlay.yml +21 -0
- package/overlays/redpanda/verify.sh +48 -0
- package/overlays/rust/README.md +299 -0
- package/overlays/rust/devcontainer.patch.json +39 -0
- package/overlays/rust/overlay.yml +15 -0
- package/overlays/rust/setup.sh +36 -0
- package/overlays/rust/verify.sh +51 -0
- package/overlays/sqlite/README.md +584 -0
- package/overlays/sqlite/devcontainer.patch.json +14 -0
- package/overlays/sqlite/overlay.yml +15 -0
- package/overlays/sqlite/setup.sh +27 -0
- package/overlays/sqlite/verify.sh +43 -0
- package/overlays/sqlserver/.env.example +6 -0
- package/overlays/sqlserver/README.md +592 -0
- package/overlays/sqlserver/devcontainer.patch.json +22 -0
- package/overlays/sqlserver/docker-compose.yml +32 -0
- package/overlays/sqlserver/overlay.yml +17 -0
- package/overlays/sqlserver/verify.sh +30 -0
- package/overlays/tempo/.env.example +5 -0
- package/overlays/tempo/README.md +273 -0
- package/overlays/tempo/devcontainer.patch.json +12 -0
- package/overlays/tempo/docker-compose.yml +20 -0
- package/overlays/tempo/overlay.yml +20 -0
- package/overlays/tempo/tempo-config.yaml +32 -0
- package/overlays/tempo/verify.sh +31 -0
- package/overlays/terraform/README.md +389 -0
- package/overlays/terraform/devcontainer.patch.json +15 -0
- package/overlays/terraform/overlay.yml +14 -0
- package/overlays/terraform/verify.sh +63 -0
- package/package.json +74 -0
- package/templates/README.md +285 -0
- package/templates/compose/.devcontainer/devcontainer.json +46 -0
- package/templates/compose/.devcontainer/docker-compose.yml +12 -0
- package/templates/compose/README.md +20 -0
- package/templates/plain/.devcontainer/devcontainer.json +35 -0
- package/templates/plain/README.md +21 -0
- package/tool/README.md +281 -0
- package/tool/schema/base-images.schema.json +43 -0
- package/tool/schema/base-templates.schema.json +34 -0
- package/tool/schema/config.schema.json +71 -0
- package/tool/schema/overlay-manifest.schema.json +86 -0
|
@@ -0,0 +1,602 @@
|
|
|
1
|
+
# PostgreSQL Overlay
|
|
2
|
+
|
|
3
|
+
PostgreSQL 16 database server for development and testing.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **PostgreSQL 16** - Latest major version with modern SQL features
|
|
8
|
+
- **Pre-configured** - Ready to use with sensible defaults
|
|
9
|
+
- **Docker Compose service** - Runs as separate container
|
|
10
|
+
- **Persistent storage** - Data survives container restarts
|
|
11
|
+
- **pgAdmin support** - Optional web-based administration
|
|
12
|
+
- **Environment configuration** - Customizable via `.env` file
|
|
13
|
+
|
|
14
|
+
## How It Works
|
|
15
|
+
|
|
16
|
+
This overlay adds a PostgreSQL 16 database server as a separate Docker Compose service. The database runs in its own container and is accessible from your development container via the hostname `postgres`.
|
|
17
|
+
|
|
18
|
+
**Architecture:**
|
|
19
|
+
|
|
20
|
+
```mermaid
|
|
21
|
+
graph TD
|
|
22
|
+
A[Development Container<br/>Your application code<br/>psql client<br/>Connects to postgres:5432] -->|Docker network devnet| B[PostgreSQL Container<br/>PostgreSQL 16 server<br/>Port 5432<br/>Data volume]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
### Environment Variables
|
|
28
|
+
|
|
29
|
+
The overlay includes a `.env.example` file. Copy it to `.env` and customize:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
cd .devcontainer
|
|
33
|
+
cp .env.example .env
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Default values (.env.example):**
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# PostgreSQL Configuration
|
|
40
|
+
POSTGRES_USER=postgres
|
|
41
|
+
POSTGRES_PASSWORD=postgres
|
|
42
|
+
POSTGRES_DB=devdb
|
|
43
|
+
POSTGRES_PORT=5432
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
⚠️ **Important:** The `.env` file is git-ignored. Always use strong passwords in production.
|
|
47
|
+
|
|
48
|
+
### Port Configuration
|
|
49
|
+
|
|
50
|
+
The default port (5432) can be changed via the `--port-offset` option when initializing the devcontainer:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Offset all ports by 100
|
|
54
|
+
container-superposition --port-offset 100
|
|
55
|
+
|
|
56
|
+
# PostgreSQL will be on 5532 instead of 5432
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Connection Information
|
|
60
|
+
|
|
61
|
+
### From Development Container
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# Hostname: postgres (Docker Compose service name)
|
|
65
|
+
# Port: 5432
|
|
66
|
+
# Database: devdb (or value from .env)
|
|
67
|
+
# Username: postgres (or value from .env)
|
|
68
|
+
# Password: postgres (or value from .env)
|
|
69
|
+
|
|
70
|
+
# Connection string
|
|
71
|
+
postgresql://postgres:postgres@postgres:5432/devdb
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### From Host Machine
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Hostname: localhost
|
|
78
|
+
# Port: 5432 (or 5432 + port-offset)
|
|
79
|
+
# Database: devdb
|
|
80
|
+
# Username: postgres
|
|
81
|
+
# Password: postgres
|
|
82
|
+
|
|
83
|
+
# Connection string
|
|
84
|
+
postgresql://postgres:postgres@localhost:5432/devdb
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Common Commands
|
|
88
|
+
|
|
89
|
+
### Using psql (PostgreSQL CLI)
|
|
90
|
+
|
|
91
|
+
The PostgreSQL client tools are pre-installed in your development container.
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Connect to database
|
|
95
|
+
psql -h postgres -U postgres -d devdb
|
|
96
|
+
|
|
97
|
+
# Connect with connection string
|
|
98
|
+
psql postgresql://postgres:postgres@postgres:5432/devdb
|
|
99
|
+
|
|
100
|
+
# Execute SQL file
|
|
101
|
+
psql -h postgres -U postgres -d devdb -f schema.sql
|
|
102
|
+
|
|
103
|
+
# Execute single command
|
|
104
|
+
psql -h postgres -U postgres -d devdb -c "SELECT version();"
|
|
105
|
+
|
|
106
|
+
# Export data to CSV
|
|
107
|
+
psql -h postgres -U postgres -d devdb -c "COPY (SELECT * FROM users) TO STDOUT WITH CSV HEADER" > users.csv
|
|
108
|
+
|
|
109
|
+
# Import data from CSV
|
|
110
|
+
psql -h postgres -U postgres -d devdb -c "\COPY users FROM 'users.csv' WITH CSV HEADER"
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Database Management
|
|
114
|
+
|
|
115
|
+
```sql
|
|
116
|
+
-- List databases
|
|
117
|
+
\l
|
|
118
|
+
|
|
119
|
+
-- Connect to database
|
|
120
|
+
\c devdb
|
|
121
|
+
|
|
122
|
+
-- List tables
|
|
123
|
+
\dt
|
|
124
|
+
|
|
125
|
+
-- Describe table
|
|
126
|
+
\d users
|
|
127
|
+
|
|
128
|
+
-- List schemas
|
|
129
|
+
\dn
|
|
130
|
+
|
|
131
|
+
-- List users/roles
|
|
132
|
+
\du
|
|
133
|
+
|
|
134
|
+
-- Execute SQL file
|
|
135
|
+
\i schema.sql
|
|
136
|
+
|
|
137
|
+
-- Toggle expanded display
|
|
138
|
+
\x
|
|
139
|
+
|
|
140
|
+
-- Quit
|
|
141
|
+
\q
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Creating Databases and Users
|
|
145
|
+
|
|
146
|
+
```sql
|
|
147
|
+
-- Create database
|
|
148
|
+
CREATE DATABASE myapp;
|
|
149
|
+
|
|
150
|
+
-- Create user
|
|
151
|
+
CREATE USER myapp_user WITH PASSWORD 'secure_password';
|
|
152
|
+
|
|
153
|
+
-- Grant privileges
|
|
154
|
+
GRANT ALL PRIVILEGES ON DATABASE myapp TO myapp_user;
|
|
155
|
+
|
|
156
|
+
-- Grant schema privileges
|
|
157
|
+
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO myapp_user;
|
|
158
|
+
|
|
159
|
+
-- Grant future tables
|
|
160
|
+
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO myapp_user;
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Common SQL Operations
|
|
164
|
+
|
|
165
|
+
```sql
|
|
166
|
+
-- Create table
|
|
167
|
+
CREATE TABLE users (
|
|
168
|
+
id SERIAL PRIMARY KEY,
|
|
169
|
+
username VARCHAR(50) NOT NULL UNIQUE,
|
|
170
|
+
email VARCHAR(100) NOT NULL UNIQUE,
|
|
171
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
-- Insert data
|
|
175
|
+
INSERT INTO users (username, email) VALUES ('john', 'john@example.com');
|
|
176
|
+
|
|
177
|
+
-- Query data
|
|
178
|
+
SELECT * FROM users;
|
|
179
|
+
|
|
180
|
+
-- Update data
|
|
181
|
+
UPDATE users SET email = 'newemail@example.com' WHERE username = 'john';
|
|
182
|
+
|
|
183
|
+
-- Delete data
|
|
184
|
+
DELETE FROM users WHERE username = 'john';
|
|
185
|
+
|
|
186
|
+
-- Create index
|
|
187
|
+
CREATE INDEX idx_users_email ON users(email);
|
|
188
|
+
|
|
189
|
+
-- Add foreign key
|
|
190
|
+
ALTER TABLE orders ADD CONSTRAINT fk_user
|
|
191
|
+
FOREIGN KEY (user_id) REFERENCES users(id);
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Backup and Restore
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
# Backup database
|
|
198
|
+
pg_dump -h postgres -U postgres devdb > backup.sql
|
|
199
|
+
|
|
200
|
+
# Backup with custom format (compressed)
|
|
201
|
+
pg_dump -h postgres -U postgres -Fc devdb > backup.dump
|
|
202
|
+
|
|
203
|
+
# Backup all databases
|
|
204
|
+
pg_dumpall -h postgres -U postgres > all_databases.sql
|
|
205
|
+
|
|
206
|
+
# Restore from SQL file
|
|
207
|
+
psql -h postgres -U postgres devdb < backup.sql
|
|
208
|
+
|
|
209
|
+
# Restore from custom format
|
|
210
|
+
pg_restore -h postgres -U postgres -d devdb backup.dump
|
|
211
|
+
|
|
212
|
+
# Restore specific table
|
|
213
|
+
pg_restore -h postgres -U postgres -d devdb -t users backup.dump
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Performance and Monitoring
|
|
217
|
+
|
|
218
|
+
```sql
|
|
219
|
+
-- Show active connections
|
|
220
|
+
SELECT * FROM pg_stat_activity;
|
|
221
|
+
|
|
222
|
+
-- Kill connection
|
|
223
|
+
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid = 12345;
|
|
224
|
+
|
|
225
|
+
-- Show table sizes
|
|
226
|
+
SELECT
|
|
227
|
+
schemaname,
|
|
228
|
+
tablename,
|
|
229
|
+
pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) AS size
|
|
230
|
+
FROM pg_tables
|
|
231
|
+
ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC;
|
|
232
|
+
|
|
233
|
+
-- Show index usage
|
|
234
|
+
SELECT
|
|
235
|
+
schemaname,
|
|
236
|
+
tablename,
|
|
237
|
+
indexname,
|
|
238
|
+
idx_scan,
|
|
239
|
+
idx_tup_read,
|
|
240
|
+
idx_tup_fetch
|
|
241
|
+
FROM pg_stat_user_indexes
|
|
242
|
+
ORDER BY idx_scan DESC;
|
|
243
|
+
|
|
244
|
+
-- Show slow queries (requires pg_stat_statements extension)
|
|
245
|
+
SELECT
|
|
246
|
+
mean_exec_time,
|
|
247
|
+
calls,
|
|
248
|
+
query
|
|
249
|
+
FROM pg_stat_statements
|
|
250
|
+
ORDER BY mean_exec_time DESC
|
|
251
|
+
LIMIT 10;
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Application Integration
|
|
255
|
+
|
|
256
|
+
### Node.js (pg library)
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
npm install pg
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
```javascript
|
|
263
|
+
const { Pool } = require('pg');
|
|
264
|
+
|
|
265
|
+
const pool = new Pool({
|
|
266
|
+
host: 'postgres',
|
|
267
|
+
port: 5432,
|
|
268
|
+
database: 'devdb',
|
|
269
|
+
user: 'postgres',
|
|
270
|
+
password: 'postgres',
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
// Query
|
|
274
|
+
const result = await pool.query('SELECT * FROM users WHERE id = $1', [1]);
|
|
275
|
+
console.log(result.rows);
|
|
276
|
+
|
|
277
|
+
// Insert
|
|
278
|
+
await pool.query('INSERT INTO users (username, email) VALUES ($1, $2)', [
|
|
279
|
+
'john',
|
|
280
|
+
'john@example.com',
|
|
281
|
+
]);
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Python (psycopg2)
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
pip install psycopg2-binary
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
```python
|
|
291
|
+
import psycopg2
|
|
292
|
+
|
|
293
|
+
conn = psycopg2.connect(
|
|
294
|
+
host="postgres",
|
|
295
|
+
port=5432,
|
|
296
|
+
database="devdb",
|
|
297
|
+
user="postgres",
|
|
298
|
+
password="postgres"
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
cur = conn.cursor()
|
|
302
|
+
|
|
303
|
+
# Query
|
|
304
|
+
cur.execute("SELECT * FROM users WHERE id = %s", (1,))
|
|
305
|
+
rows = cur.fetchall()
|
|
306
|
+
|
|
307
|
+
# Insert
|
|
308
|
+
cur.execute(
|
|
309
|
+
"INSERT INTO users (username, email) VALUES (%s, %s)",
|
|
310
|
+
("john", "john@example.com")
|
|
311
|
+
)
|
|
312
|
+
conn.commit()
|
|
313
|
+
|
|
314
|
+
cur.close()
|
|
315
|
+
conn.close()
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### .NET (Npgsql)
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
dotnet add package Npgsql
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
```csharp
|
|
325
|
+
using Npgsql;
|
|
326
|
+
|
|
327
|
+
var connectionString = "Host=postgres;Port=5432;Database=devdb;Username=postgres;Password=postgres";
|
|
328
|
+
|
|
329
|
+
await using var conn = new NpgsqlConnection(connectionString);
|
|
330
|
+
await conn.OpenAsync();
|
|
331
|
+
|
|
332
|
+
// Query
|
|
333
|
+
await using var cmd = new NpgsqlCommand("SELECT * FROM users WHERE id = @id", conn);
|
|
334
|
+
cmd.Parameters.AddWithValue("id", 1);
|
|
335
|
+
await using var reader = await cmd.ExecuteReaderAsync();
|
|
336
|
+
|
|
337
|
+
while (await reader.ReadAsync())
|
|
338
|
+
{
|
|
339
|
+
Console.WriteLine($"{reader["username"]}: {reader["email"]}");
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### Go (pgx)
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
go get github.com/jackc/pgx/v5
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
```go
|
|
350
|
+
package main
|
|
351
|
+
|
|
352
|
+
import (
|
|
353
|
+
"context"
|
|
354
|
+
"github.com/jackc/pgx/v5"
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
func main() {
|
|
358
|
+
ctx := context.Background()
|
|
359
|
+
conn, err := pgx.Connect(ctx, "postgresql://postgres:postgres@postgres:5432/devdb")
|
|
360
|
+
if err != nil {
|
|
361
|
+
panic(err)
|
|
362
|
+
}
|
|
363
|
+
defer conn.Close(ctx)
|
|
364
|
+
|
|
365
|
+
// Query
|
|
366
|
+
var username, email string
|
|
367
|
+
err = conn.QueryRow(ctx, "SELECT username, email FROM users WHERE id = $1", 1).Scan(&username, &email)
|
|
368
|
+
|
|
369
|
+
// Insert
|
|
370
|
+
_, err = conn.Exec(ctx, "INSERT INTO users (username, email) VALUES ($1, $2)", "john", "john@example.com")
|
|
371
|
+
}
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
## Use Cases
|
|
375
|
+
|
|
376
|
+
### Application Development
|
|
377
|
+
|
|
378
|
+
- Local database for web applications
|
|
379
|
+
- API backend data storage
|
|
380
|
+
- Microservices data persistence
|
|
381
|
+
|
|
382
|
+
### Testing
|
|
383
|
+
|
|
384
|
+
- Integration tests with real database
|
|
385
|
+
- Schema migration testing
|
|
386
|
+
- Performance testing
|
|
387
|
+
|
|
388
|
+
### Learning SQL
|
|
389
|
+
|
|
390
|
+
- Practice SQL queries
|
|
391
|
+
- Database design
|
|
392
|
+
- PostgreSQL-specific features
|
|
393
|
+
|
|
394
|
+
### Data Analysis
|
|
395
|
+
|
|
396
|
+
- Local data warehouse
|
|
397
|
+
- ETL pipeline development
|
|
398
|
+
- SQL query optimization
|
|
399
|
+
|
|
400
|
+
## Extensions
|
|
401
|
+
|
|
402
|
+
PostgreSQL supports many extensions. Common ones:
|
|
403
|
+
|
|
404
|
+
```sql
|
|
405
|
+
-- Enable UUID support
|
|
406
|
+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
407
|
+
SELECT uuid_generate_v4();
|
|
408
|
+
|
|
409
|
+
-- Enable PostGIS (geospatial data)
|
|
410
|
+
CREATE EXTENSION IF NOT EXISTS postgis;
|
|
411
|
+
|
|
412
|
+
-- Enable full-text search
|
|
413
|
+
CREATE EXTENSION IF NOT EXISTS pg_trgm;
|
|
414
|
+
|
|
415
|
+
-- Enable cryptographic functions
|
|
416
|
+
CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
|
417
|
+
|
|
418
|
+
-- List installed extensions
|
|
419
|
+
\dx
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
## Troubleshooting
|
|
423
|
+
|
|
424
|
+
### Cannot connect to database
|
|
425
|
+
|
|
426
|
+
```bash
|
|
427
|
+
# Check if PostgreSQL container is running
|
|
428
|
+
docker-compose ps
|
|
429
|
+
# Note: Use 'docker compose' (without hyphen) if using Docker Compose V2
|
|
430
|
+
|
|
431
|
+
# Check PostgreSQL logs
|
|
432
|
+
docker-compose logs postgres
|
|
433
|
+
|
|
434
|
+
# Verify connection from dev container
|
|
435
|
+
psql -h postgres -U postgres -c "SELECT version();"
|
|
436
|
+
|
|
437
|
+
# Check network connectivity
|
|
438
|
+
ping postgres
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### Password authentication failed
|
|
442
|
+
|
|
443
|
+
```bash
|
|
444
|
+
# Verify environment variables
|
|
445
|
+
cat .devcontainer/.env
|
|
446
|
+
|
|
447
|
+
# Ensure .env file is loaded
|
|
448
|
+
# Rebuild container if needed
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### Database does not exist
|
|
452
|
+
|
|
453
|
+
```sql
|
|
454
|
+
-- List databases
|
|
455
|
+
psql -h postgres -U postgres -c "\l"
|
|
456
|
+
|
|
457
|
+
-- Create database
|
|
458
|
+
psql -h postgres -U postgres -c "CREATE DATABASE devdb;"
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
### Permission denied errors
|
|
462
|
+
|
|
463
|
+
```sql
|
|
464
|
+
-- Grant privileges to user
|
|
465
|
+
GRANT ALL PRIVILEGES ON DATABASE devdb TO myuser;
|
|
466
|
+
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO myuser;
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### Out of connections
|
|
470
|
+
|
|
471
|
+
```sql
|
|
472
|
+
-- Check active connections
|
|
473
|
+
SELECT count(*) FROM pg_stat_activity;
|
|
474
|
+
|
|
475
|
+
-- Check max connections
|
|
476
|
+
SHOW max_connections;
|
|
477
|
+
|
|
478
|
+
-- Kill idle connections
|
|
479
|
+
SELECT pg_terminate_backend(pid)
|
|
480
|
+
FROM pg_stat_activity
|
|
481
|
+
WHERE state = 'idle'
|
|
482
|
+
AND state_change < NOW() - INTERVAL '10 minutes';
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
### Data not persisting
|
|
486
|
+
|
|
487
|
+
Data is stored in a Docker volume and should persist across container restarts. If data is lost:
|
|
488
|
+
|
|
489
|
+
```bash
|
|
490
|
+
# Check volumes
|
|
491
|
+
docker volume ls
|
|
492
|
+
|
|
493
|
+
# Inspect volume
|
|
494
|
+
docker volume inspect <volume-name>
|
|
495
|
+
|
|
496
|
+
# If needed, recreate volume
|
|
497
|
+
docker-compose down -v # WARNING: Deletes all data
|
|
498
|
+
docker-compose up -d
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
## Performance Tuning
|
|
502
|
+
|
|
503
|
+
For development, PostgreSQL uses default settings. For better performance:
|
|
504
|
+
|
|
505
|
+
**Increase shared buffers (add to docker-compose.yml):**
|
|
506
|
+
|
|
507
|
+
```yaml
|
|
508
|
+
services:
|
|
509
|
+
postgres:
|
|
510
|
+
command: postgres -c shared_buffers=256MB -c max_connections=200
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
**Or create custom postgresql.conf:**
|
|
514
|
+
|
|
515
|
+
```ini
|
|
516
|
+
# Memory
|
|
517
|
+
shared_buffers = 256MB
|
|
518
|
+
effective_cache_size = 1GB
|
|
519
|
+
work_mem = 4MB
|
|
520
|
+
|
|
521
|
+
# Connections
|
|
522
|
+
max_connections = 200
|
|
523
|
+
|
|
524
|
+
# Query planner
|
|
525
|
+
random_page_cost = 1.1
|
|
526
|
+
effective_io_concurrency = 200
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
## Security Best Practices
|
|
530
|
+
|
|
531
|
+
1. **Change default password** - Use strong passwords in `.env`
|
|
532
|
+
2. **Don't commit .env** - Keep credentials out of version control
|
|
533
|
+
3. **Use least privilege** - Create users with minimal required permissions
|
|
534
|
+
4. **Limit connections** - Restrict connections to necessary IP addresses
|
|
535
|
+
5. **Regular backups** - Backup data regularly with `pg_dump`
|
|
536
|
+
6. **Update regularly** - Keep PostgreSQL updated
|
|
537
|
+
|
|
538
|
+
## Migration Tools
|
|
539
|
+
|
|
540
|
+
### Flyway
|
|
541
|
+
|
|
542
|
+
```bash
|
|
543
|
+
# Install Flyway CLI
|
|
544
|
+
# Add migration scripts to db/migration/
|
|
545
|
+
|
|
546
|
+
flyway -url=jdbc:postgresql://postgres:5432/devdb \
|
|
547
|
+
-user=postgres \
|
|
548
|
+
-password=postgres \
|
|
549
|
+
migrate
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
### Liquibase
|
|
553
|
+
|
|
554
|
+
```bash
|
|
555
|
+
# Create changelog.xml
|
|
556
|
+
liquibase --url=jdbc:postgresql://postgres:5432/devdb \
|
|
557
|
+
--username=postgres \
|
|
558
|
+
--password=postgres \
|
|
559
|
+
update
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
### Alembic (Python)
|
|
563
|
+
|
|
564
|
+
```bash
|
|
565
|
+
pip install alembic
|
|
566
|
+
|
|
567
|
+
# Initialize
|
|
568
|
+
alembic init migrations
|
|
569
|
+
|
|
570
|
+
# Configure alembic.ini
|
|
571
|
+
sqlalchemy.url = postgresql://postgres:postgres@postgres:5432/devdb
|
|
572
|
+
|
|
573
|
+
# Create migration
|
|
574
|
+
alembic revision -m "create users table"
|
|
575
|
+
|
|
576
|
+
# Apply migrations
|
|
577
|
+
alembic upgrade head
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
## Related Overlays
|
|
581
|
+
|
|
582
|
+
- **nodejs** - For Node.js applications with PostgreSQL
|
|
583
|
+
- **python** - For Python applications with Django/Flask
|
|
584
|
+
- **dotnet** - For .NET applications with Entity Framework
|
|
585
|
+
- **grafana** - For database monitoring dashboards
|
|
586
|
+
- **redis** - For caching layer with PostgreSQL
|
|
587
|
+
|
|
588
|
+
## Additional Resources
|
|
589
|
+
|
|
590
|
+
- [PostgreSQL Documentation](https://www.postgresql.org/docs/16/)
|
|
591
|
+
- [PostgreSQL Tutorial](https://www.postgresqltutorial.com/)
|
|
592
|
+
- [psql Commands](https://www.postgresql.org/docs/16/app-psql.html)
|
|
593
|
+
- [PostgreSQL Performance Tips](https://wiki.postgresql.org/wiki/Performance_Optimization)
|
|
594
|
+
- [Awesome PostgreSQL](https://github.com/dhamaniasad/awesome-postgres)
|
|
595
|
+
|
|
596
|
+
## Notes
|
|
597
|
+
|
|
598
|
+
- This overlay **requires compose stack** (uses docker-compose)
|
|
599
|
+
- PostgreSQL runs on port **5432** (configurable with port-offset)
|
|
600
|
+
- Data persists in Docker volume (survives container restarts)
|
|
601
|
+
- Use hostname **`postgres`** from development container
|
|
602
|
+
- Use **`localhost`** from host machine
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/devcontainers/spec/main/schemas/devContainer.base.schema.json",
|
|
3
|
+
"features": {
|
|
4
|
+
"ghcr.io/robbert229/devcontainer-features/postgresql-client:1": {}
|
|
5
|
+
},
|
|
6
|
+
"runServices": ["postgres"],
|
|
7
|
+
"forwardPorts": [5432],
|
|
8
|
+
"portsAttributes": {
|
|
9
|
+
"5432": {
|
|
10
|
+
"label": "PostgreSQL",
|
|
11
|
+
"onAutoForward": "notify"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"remoteEnv": {
|
|
15
|
+
"POSTGRES_HOST": "postgres",
|
|
16
|
+
"POSTGRES_PORT": "5432",
|
|
17
|
+
"POSTGRES_DB": "devdb",
|
|
18
|
+
"POSTGRES_USER": "postgres",
|
|
19
|
+
"POSTGRES_PASSWORD": "postgres"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
version: '3.8'
|
|
2
|
+
|
|
3
|
+
services:
|
|
4
|
+
postgres:
|
|
5
|
+
image: postgres:${POSTGRES_VERSION:-16}-alpine
|
|
6
|
+
restart: unless-stopped
|
|
7
|
+
volumes:
|
|
8
|
+
- postgres-data:/var/lib/postgresql/data
|
|
9
|
+
environment:
|
|
10
|
+
POSTGRES_DB: ${POSTGRES_DB:-devdb}
|
|
11
|
+
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
|
12
|
+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
|
|
13
|
+
ports:
|
|
14
|
+
- '${POSTGRES_PORT:-5432}:5432'
|
|
15
|
+
networks:
|
|
16
|
+
- devnet
|
|
17
|
+
|
|
18
|
+
volumes:
|
|
19
|
+
postgres-data:
|
|
20
|
+
|
|
21
|
+
networks:
|
|
22
|
+
devnet:
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Verification script for PostgreSQL overlay
|
|
3
|
+
# Confirms PostgreSQL is installed and accessible
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
echo "🔍 Verifying PostgreSQL overlay..."
|
|
8
|
+
echo ""
|
|
9
|
+
|
|
10
|
+
# Check psql is installed
|
|
11
|
+
echo "1️⃣ Checking psql client..."
|
|
12
|
+
if command -v psql &> /dev/null; then
|
|
13
|
+
psql --version
|
|
14
|
+
echo " ✅ psql client found"
|
|
15
|
+
else
|
|
16
|
+
echo " ❌ psql client not found"
|
|
17
|
+
exit 1
|
|
18
|
+
fi
|
|
19
|
+
|
|
20
|
+
# Check if PostgreSQL service is running
|
|
21
|
+
echo ""
|
|
22
|
+
echo "2️⃣ Checking PostgreSQL service..."
|
|
23
|
+
if command -v pg_isready &> /dev/null; then
|
|
24
|
+
# Wait up to 10 seconds for postgres to be ready
|
|
25
|
+
POSTGRES_READY=false
|
|
26
|
+
for i in {1..10}; do
|
|
27
|
+
if pg_isready -h postgres -p 5432 &> /dev/null; then
|
|
28
|
+
echo " ✅ PostgreSQL service is ready"
|
|
29
|
+
pg_isready -h postgres -p 5432
|
|
30
|
+
POSTGRES_READY=true
|
|
31
|
+
break
|
|
32
|
+
fi
|
|
33
|
+
sleep 1
|
|
34
|
+
done
|
|
35
|
+
|
|
36
|
+
if [ "$POSTGRES_READY" = false ]; then
|
|
37
|
+
echo " ❌ PostgreSQL service not ready after 10 seconds"
|
|
38
|
+
exit 1
|
|
39
|
+
fi
|
|
40
|
+
else
|
|
41
|
+
echo " ⚠️ pg_isready not found, skipping service check"
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
echo ""
|
|
45
|
+
echo "✅ PostgreSQL overlay verification complete"
|