Skip to content

Commit 5b12179

Browse files
committed
Add TimescaleDB full version support for PostgreSQL 17
- Update TimescaleDB to version 2.20.3 with full features (APACHE_ONLY=0) - Configure PostgreSQL 17 to exclude TimescaleDB and plv8 extensions - Add build configuration for CEP PostgreSQL 17.4.1.043 - Update gitignore to exclude tar.gz archives
1 parent 87829eb commit 5b12179

File tree

7 files changed

+153
-10
lines changed

7 files changed

+153
-10
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ result*
2525

2626
db/schema.sql
2727
common-nix.vars.pkr.hcl
28+
29+
# CEP PostgreSQL source archives
30+
*.tar.gz

CLAUDE.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## CRITICAL INSTRUCTION: PostgreSQL Version Restriction
6+
7+
**ALWAYS USE POSTGRESQL 17 ONLY**
8+
9+
- When starting servers, ONLY use: `nix run .#start-server 17`
10+
- When building, ONLY target PostgreSQL 17
11+
- When testing, ONLY use: `nix build .#checks.psql_17 -L`
12+
- When building AMIs, ONLY use: `nix run .#build-test-ami 17`
13+
- NEVER use PostgreSQL 15 or OrioleDB 17 variants
14+
- If asked to work with other versions, politely decline and explain you must only work with PostgreSQL 17
15+
16+
## Project Overview
17+
18+
This is **Supabase's PostgreSQL distribution** - an enhanced PostgreSQL build with 40+ extensions across three major versions (PostgreSQL 15, 17, and OrioleDB 17). The project uses Nix as the primary build system for reproducible builds and provides Docker/Packer alternatives for different deployment scenarios.
19+
20+
## Development Commands
21+
22+
### Primary Development Environment (Nix)
23+
```bash
24+
# Enter development environment
25+
nix develop
26+
27+
# Start PostgreSQL server (ONLY use version 17)
28+
nix run .#start-server 17
29+
30+
# Connect client with migrations applied
31+
nix run .#start-client
32+
33+
# Run database migrations
34+
nix run .#dbmate-tool
35+
36+
# Run all tests
37+
nix flake check
38+
39+
# Run tests for PostgreSQL 17 ONLY
40+
nix build .#checks.psql_17 -L
41+
```
42+
43+
### CI/CD and AMI Building
44+
```bash
45+
# Trigger Nix build
46+
nix run .#trigger-nix-build
47+
48+
# Build test AMI (PostgreSQL 17 ONLY)
49+
nix run .#build-test-ami 17
50+
51+
# Run infrastructure tests
52+
nix run .#run-testinfra
53+
54+
# Cleanup AMI
55+
nix run .#cleanup-ami
56+
```
57+
58+
### Legacy Build System
59+
```bash
60+
# Packer-based image building
61+
make init
62+
make output-cloudimg/packer-cloudimg
63+
make alpine-image
64+
```
65+
66+
## Architecture Overview
67+
68+
### PostgreSQL Version Support
69+
- **PostgreSQL 17**: The ONLY version to use for all development and builds
70+
- Other versions (15, OrioleDB 17) exist in the codebase but MUST NOT be used
71+
72+
Extension configuration is in `nix/postgresql/` but ONLY work with PostgreSQL 17.
73+
74+
### Build System Architecture
75+
- **Primary**: Nix flakes (`flake.nix`) for reproducible builds
76+
- **Fallback**: Docker containers for development
77+
- **Production**: Packer + Ansible for AMI creation
78+
79+
### Extension Management
80+
Extensions are organized in `nix/ext/` by category:
81+
- **Security**: pgsodium, vault, pgaudit
82+
- **Analytics**: TimescaleDB, pg_stat_monitor
83+
- **API**: pg_graphql, PostgREST integration
84+
- **Vector Search**: pgvector
85+
- **Geospatial**: PostGIS, pgRouting
86+
87+
### Migration System
88+
- Uses **dbmate** for schema migrations
89+
- Located in `migrations/` directory
90+
- Supports all PostgreSQL versions
91+
- Append-only migration pattern
92+
93+
### Testing Framework
94+
- **pg_regress**: PostgreSQL regression testing
95+
- **pgTAP**: Database unit testing in `migrations/tests/extensions/`
96+
- **testinfra**: Infrastructure testing with Python pytest
97+
- **PostgreSQL 17 testing**: All extensions tested against PostgreSQL 17 ONLY
98+
99+
## Extension Development
100+
101+
### Adding New Extensions
102+
1. Create build stage in appropriate Dockerfile
103+
2. Add version build args
104+
3. Use `checkinstall` for source-built extensions
105+
4. Copy package to extensions stage
106+
5. Add pgTAP test in `migrations/tests/extensions/`
107+
108+
### Extension Testing
109+
Create test file in `migrations/tests/extensions/`:
110+
```sql
111+
BEGIN;
112+
create extension if not exists your_extension with schema "extensions";
113+
ROLLBACK;
114+
```
115+
116+
## Migration Guidelines
117+
- **Never edit existing migrations** - always create new ones
118+
- **Idempotent**: All migrations must be rerunnable
119+
- **Role-based**: Use appropriate database roles for different migration phases
120+
- **PostgreSQL 17 specific**: Target PostgreSQL 17 ONLY
121+
122+
## Security Model
123+
- **supabase_admin**: Superuser role for administration
124+
- **authenticator**: Connection pooling role
125+
- **Row Level Security**: Built-in RLS policies
126+
- **Predefined roles**: For API access patterns
127+
128+
## Key Configuration
129+
- Default PostgreSQL port: `5435`
130+
- Default host: `localhost`
131+
- Superuser: `supabase_admin`
132+
- WAL level: `logical` with 5 replication slots
133+
- Large Systems Extensions enabled for ARM images

ansible/tasks/stage2-setup-postgres.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@
1818
set_fact:
1919
is_psql_15: "{{ psql_version in ['psql_15'] }}"
2020

21-
- name: Remove specified extensions from postgresql.conf if orioledb-17 or 17 build
21+
- name: Remove specified extensions from postgresql.conf if orioledb-17 build
2222
ansible.builtin.command:
2323
cmd: >
2424
sed -i 's/ timescaledb,//g'
2525
/etc/postgresql/postgresql.conf
26-
when: is_psql_oriole or is_psql_17 and stage2_nix
26+
when: is_psql_oriole and stage2_nix
2727
become: yes
2828

29-
- name: Remove specified extensions from supautils.conf if orioledb-17 or 17 build
29+
- name: Remove specified extensions from supautils.conf if orioledb-17 build
3030
ansible.builtin.command:
3131
cmd: >
3232
sed -i 's/ timescaledb,//g; s/ plv8,//g'
3333
/etc/postgresql-custom/supautils.conf
34-
when: is_psql_oriole or is_psql_17 and stage2_nix
34+
when: is_psql_oriole and stage2_nix
3535
become: yes
3636

3737
- name: Remove db_user_namespace from postgresql.conf if orioledb-17 or 17 build

ansible/vars.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ postgres_major:
66
- "15"
77
- "17"
88
- "orioledb-17"
9+
- "cep"
910

1011
# Full version strings for each major version
1112
postgres_release:
1213
postgresorioledb-17: "17.0.1.093-orioledb"
1314
postgres17: "17.4.1.043"
1415
postgres15: "15.8.1.100"
16+
postgrescep: "17.4.1.043-cep"
1517

1618
# Non Postgres Extensions
1719
pgbouncer_release: "1.19.0"

flake.nix

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163

164164
#Where we import and build the orioledb extension, we add on our custom extensions
165165
# plus the orioledb option
166-
#we're not using timescaledb or plv8 in the orioledb-17 version or pg 17 of supabase extensions
166+
#we're not using timescaledb or plv8 in the orioledb-17 version but timescaledb is now enabled for pg 17
167167
orioleFilteredExtensions = builtins.filter
168168
(
169169
x:
@@ -173,7 +173,12 @@
173173
) ourExtensions;
174174

175175
orioledbExtensions = orioleFilteredExtensions ++ [ ./nix/ext/orioledb.nix ];
176-
dbExtensions17 = orioleFilteredExtensions;
176+
dbExtensions17 = builtins.filter
177+
(
178+
x:
179+
x != ./nix/ext/plv8.nix &&
180+
x != ./nix/ext/timescaledb-2.9.1.nix
181+
) ourExtensions;
177182
getPostgresqlPackage = version:
178183
pkgs.postgresql."postgresql_${version}";
179184
# Create a 'receipt' file for a given postgresql package. This is a way

nix/ext/timescaledb-2.9.1.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ stdenv.mkDerivation rec {
1414
hash = "sha256-fvVSxDiGZAewyuQ2vZDb0I6tmlDXl6trjZp8+qDBtb8=";
1515
};
1616

17-
cmakeFlags = [ "-DSEND_TELEMETRY_DEFAULT=OFF" "-DREGRESS_CHECKS=OFF" "-DTAP_CHECKS=OFF" "-DAPACHE_ONLY=1" ]
17+
cmakeFlags = [ "-DSEND_TELEMETRY_DEFAULT=OFF" "-DREGRESS_CHECKS=OFF" "-DTAP_CHECKS=OFF" "-DAPACHE_ONLY=0" ]
1818
++ lib.optionals stdenv.isDarwin [ "-DLINTER=OFF" ];
1919

2020
# Fix the install phase which tries to install into the pgsql extension dir,

nix/ext/timescaledb.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
stdenv.mkDerivation rec {
44
pname = "timescaledb-apache";
5-
version = "2.16.1";
5+
version = "2.20.3";
66

77
nativeBuildInputs = [ cmake ];
88
buildInputs = [ postgresql openssl libkrb5 ];
@@ -11,10 +11,10 @@ stdenv.mkDerivation rec {
1111
owner = "timescale";
1212
repo = "timescaledb";
1313
rev = version;
14-
hash = "sha256-sLxWdBmih9mgiO51zLLxn9uwJVYc5JVHJjSWoADoJ+w=";
14+
hash = "sha256-Ma6h2ISMjBz14y5Pbx4T4QOMrrvUy5wkPyKawm9rpx0=";
1515
};
1616

17-
cmakeFlags = [ "-DSEND_TELEMETRY_DEFAULT=OFF" "-DREGRESS_CHECKS=OFF" "-DTAP_CHECKS=OFF" "-DAPACHE_ONLY=1" ]
17+
cmakeFlags = [ "-DSEND_TELEMETRY_DEFAULT=OFF" "-DREGRESS_CHECKS=OFF" "-DTAP_CHECKS=OFF" "-DAPACHE_ONLY=0" ]
1818
++ lib.optionals stdenv.isDarwin [ "-DLINTER=OFF" ];
1919

2020
# Fix the install phase which tries to install into the pgsql extension dir,

0 commit comments

Comments
 (0)