|
| 1 | +# Quick start guide for GCP deployment |
| 2 | + |
| 3 | +Step-by-step guide to deploy postgres_ai monitoring on GCP. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. GCP account with active project |
| 8 | +2. gcloud CLI installed |
| 9 | +3. Terraform installed |
| 10 | +4. SSH key generated |
| 11 | + |
| 12 | +## Step 1: Install tools |
| 13 | + |
| 14 | +### Install gcloud CLI |
| 15 | + |
| 16 | +macOS: |
| 17 | +```bash |
| 18 | +brew install google-cloud-sdk |
| 19 | +``` |
| 20 | + |
| 21 | +Ubuntu/Debian: |
| 22 | +```bash |
| 23 | +curl https://sdk.cloud.google.com | bash |
| 24 | +``` |
| 25 | + |
| 26 | +### Authenticate |
| 27 | + |
| 28 | +```bash |
| 29 | +gcloud auth login |
| 30 | +gcloud auth application-default login |
| 31 | +``` |
| 32 | + |
| 33 | +### Set project |
| 34 | + |
| 35 | +```bash |
| 36 | +# List your projects |
| 37 | +gcloud projects list |
| 38 | + |
| 39 | +# Set active project |
| 40 | +gcloud config set project YOUR_PROJECT_ID |
| 41 | +``` |
| 42 | + |
| 43 | +### Enable APIs |
| 44 | + |
| 45 | +```bash |
| 46 | +gcloud services enable compute.googleapis.com |
| 47 | +``` |
| 48 | + |
| 49 | +### Install Terraform |
| 50 | + |
| 51 | +macOS: |
| 52 | +```bash |
| 53 | +brew install terraform |
| 54 | +``` |
| 55 | + |
| 56 | +Ubuntu/Debian: |
| 57 | +```bash |
| 58 | +wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg |
| 59 | +echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list |
| 60 | +sudo apt update && sudo apt install terraform |
| 61 | +``` |
| 62 | + |
| 63 | +## Step 2: Generate SSH key |
| 64 | + |
| 65 | +If you don't have an SSH key: |
| 66 | + |
| 67 | +```bash |
| 68 | +ssh-keygen -t rsa -b 4096 -f ~/.ssh/gcp_postgres_ai |
| 69 | +``` |
| 70 | + |
| 71 | +Get your public key: |
| 72 | + |
| 73 | +```bash |
| 74 | +cat ~/.ssh/gcp_postgres_ai.pub |
| 75 | +``` |
| 76 | + |
| 77 | +## Step 3: Configure deployment |
| 78 | + |
| 79 | +```bash |
| 80 | +cd terraform/gcp |
| 81 | +cp terraform.tfvars.example terraform.tfvars |
| 82 | +``` |
| 83 | + |
| 84 | +Edit `terraform.tfvars`: |
| 85 | + |
| 86 | +```hcl |
| 87 | +# Required |
| 88 | +project_id = "your-gcp-project-id" |
| 89 | +ssh_public_key = "ssh-rsa AAAAB3NzaC1... user@hostname" |
| 90 | +
|
| 91 | +# Optional |
| 92 | +region = "us-central1" |
| 93 | +grafana_password = "your-secure-password" |
| 94 | +machine_type = "e2-standard-2" |
| 95 | +data_volume_size = 50 |
| 96 | +``` |
| 97 | + |
| 98 | +## Step 4: Add monitoring instances |
| 99 | + |
| 100 | +Get your Postgres connection details and add to `terraform.tfvars`: |
| 101 | + |
| 102 | +```hcl |
| 103 | +monitoring_instances = [ |
| 104 | + { |
| 105 | + name = "production-db-1" |
| 106 | + conn_str = "host=10.0.0.5 port=5432 user=monitoring dbname=postgres password=mon_pass sslmode=require" |
| 107 | + environment = "production" |
| 108 | + cluster = "main" |
| 109 | + node_name = "primary" |
| 110 | + } |
| 111 | +] |
| 112 | +``` |
| 113 | + |
| 114 | +## Step 5: Validate and deploy |
| 115 | + |
| 116 | +```bash |
| 117 | +# Validate configuration |
| 118 | +./validate.sh |
| 119 | + |
| 120 | +# Initialize Terraform |
| 121 | +terraform init |
| 122 | + |
| 123 | +# Review changes |
| 124 | +terraform plan |
| 125 | + |
| 126 | +# Deploy |
| 127 | +terraform apply |
| 128 | +``` |
| 129 | + |
| 130 | +Type `yes` when prompted. |
| 131 | + |
| 132 | +## Step 6: Access Grafana |
| 133 | + |
| 134 | +After deployment completes (3-5 minutes): |
| 135 | + |
| 136 | +```bash |
| 137 | +# Get Grafana URL |
| 138 | +terraform output grafana_url |
| 139 | + |
| 140 | +# Get credentials |
| 141 | +terraform output -json grafana_credentials |
| 142 | +``` |
| 143 | + |
| 144 | +Open URL in browser and login with: |
| 145 | +- Username: `monitor` |
| 146 | +- Password: (from terraform.tfvars) |
| 147 | + |
| 148 | +## Step 7: Verify monitoring |
| 149 | + |
| 150 | +1. Open Grafana dashboards |
| 151 | +2. Check "Node performance overview" |
| 152 | +3. Verify your Postgres instances appear |
| 153 | + |
| 154 | +## Common tasks |
| 155 | + |
| 156 | +### Add more instances |
| 157 | + |
| 158 | +Edit `terraform.tfvars`: |
| 159 | + |
| 160 | +```hcl |
| 161 | +monitoring_instances = [ |
| 162 | + { |
| 163 | + name = "production-db-1" |
| 164 | + conn_str = "..." |
| 165 | + environment = "production" |
| 166 | + cluster = "main" |
| 167 | + node_name = "primary" |
| 168 | + }, |
| 169 | + { |
| 170 | + name = "production-db-2" # New instance |
| 171 | + conn_str = "..." |
| 172 | + environment = "production" |
| 173 | + cluster = "main" |
| 174 | + node_name = "standby" |
| 175 | + } |
| 176 | +] |
| 177 | +``` |
| 178 | + |
| 179 | +Apply changes: |
| 180 | + |
| 181 | +```bash |
| 182 | +terraform apply |
| 183 | +``` |
| 184 | + |
| 185 | +### SSH to instance |
| 186 | + |
| 187 | +```bash |
| 188 | +# Using gcloud |
| 189 | +gcloud compute ssh ubuntu@production-postgres-ai-monitoring --zone=us-central1-a |
| 190 | + |
| 191 | +# Using terraform output |
| 192 | +terraform output ssh_command |
| 193 | +``` |
| 194 | + |
| 195 | +### View logs |
| 196 | + |
| 197 | +```bash |
| 198 | +# Startup logs |
| 199 | +sudo tail -f /var/log/startup-script.log |
| 200 | + |
| 201 | +# Service logs |
| 202 | +sudo journalctl -u postgres-ai -f |
| 203 | + |
| 204 | +# Docker logs |
| 205 | +sudo docker-compose logs -f |
| 206 | +``` |
| 207 | + |
| 208 | +### Create backup |
| 209 | + |
| 210 | +```bash |
| 211 | +# Get disk name |
| 212 | +terraform output data_disk_name |
| 213 | + |
| 214 | +# Create snapshot |
| 215 | +gcloud compute disks snapshot production-postgres-ai-data \ |
| 216 | + --zone=us-central1-a \ |
| 217 | + --snapshot-names=backup-$(date +%Y%m%d) |
| 218 | +``` |
| 219 | + |
| 220 | +### Update configuration |
| 221 | + |
| 222 | +1. Edit `terraform.tfvars` |
| 223 | +2. Run `terraform apply` |
| 224 | +3. SSH to instance and restart: `sudo systemctl restart postgres-ai` |
| 225 | + |
| 226 | +### Cleanup |
| 227 | + |
| 228 | +To remove all resources: |
| 229 | + |
| 230 | +```bash |
| 231 | +terraform destroy |
| 232 | +``` |
| 233 | + |
| 234 | +## Troubleshooting |
| 235 | + |
| 236 | +### Cannot access Grafana |
| 237 | + |
| 238 | +Check firewall rules: |
| 239 | + |
| 240 | +```bash |
| 241 | +gcloud compute firewall-rules list --filter="name:postgres-ai" |
| 242 | +``` |
| 243 | + |
| 244 | +Get instance IP: |
| 245 | + |
| 246 | +```bash |
| 247 | +terraform output external_ip |
| 248 | +``` |
| 249 | + |
| 250 | +### Services not running |
| 251 | + |
| 252 | +SSH to instance and check: |
| 253 | + |
| 254 | +```bash |
| 255 | +sudo systemctl status postgres-ai |
| 256 | +sudo docker ps -a |
| 257 | +``` |
| 258 | + |
| 259 | +### Connection to Postgres failed |
| 260 | + |
| 261 | +Verify from instance: |
| 262 | + |
| 263 | +```bash |
| 264 | +# Test connection |
| 265 | +psql "host=10.0.0.5 port=5432 user=monitoring dbname=postgres sslmode=require" |
| 266 | +``` |
| 267 | + |
| 268 | +Check firewall rules in your Postgres network. |
| 269 | + |
| 270 | +## Next steps |
| 271 | + |
| 272 | +- Configure PostgresAI API key for automated reports |
| 273 | +- Set up monitoring alerts in Grafana |
| 274 | +- Create regular snapshot schedule |
| 275 | +- Review security settings |
| 276 | + |
| 277 | +## Support |
| 278 | + |
| 279 | +- Documentation: https://postgres.ai/docs |
| 280 | +- GitHub Issues: https://github.com/postgres-ai/postgres_ai/issues |
| 281 | + |
0 commit comments