Skip to content

Commit b0b975a

Browse files
dragarciadarora
andauthored
Supabase Postgres 14.1.0 (#98)
* chore: bump postgres and pgbouncer - #67 #68 * chore: #65 sha-scram-256 encryption * chore: Bump to Postgres 14.0 * chore: bump up existing extensions * Use PG 14 version of postgresql.conf * move up running of SQL files - to a part where the DB is still up and running * new extensions: - rum - pg_hashids * Cleanup build dependencies immediately after installation * Remove hardcoded values for Postgres major * Update variables * Update wal-g installation process * add build dependencies for supautils * changes to pgbouncer config - use scram-sha-256 encryption - list out additional build dependencies - assign postgres as stats user * Revert "Cleanup build dependencies immediately after installation" This reverts commit 25c93de. * Minimise packages cleaned up - some extensions were dependent to them * link pg binaries only at the end * remove postgres as pgbouncer stats_users * bump to Postgres 14.1 * rename filename for pgsodium * update regex for session_preload_libraries * Update README * update download URLs for postgrest * Bump versions * feat: build AMIs using Github Actions (#101) * feat: build AMIs using Github Actions * eliminate two-step build Co-authored-by: dragarcia <[email protected]> * Transfer ownership of pgbouncer process to pgbouncer user * increased timeout for get_url * further hardening of pgbouncer - no access to public schema - cannot connect to port 5432 by pgbouncer user other than localhost * bump common.vars.json * Enhancements to docker images (#108) * GA for dockerhub * Shift removal of unused packages at the bottom - For some reason, this disrupts the ansible process - Err: the connection plugin 'local' was not found * No longer use init.sh for docker * Use Dockerfile when building docker images * cleanup /tmp via the Dockerfile * more changes to docker build - move more cleanup to the Dockerfile - run everything under one command in the Dockerfile * Commenting these out for now - Need to configure runners first - Will uncomment in another PR once done * ignore caretion of symbolic link for plv8 in docker arm build * Temporarily remove CI files for Dockerhub Co-authored-by: Div Arora <[email protected]>
1 parent af1f833 commit b0b975a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+383
-271
lines changed

.github/workflows/ci.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Run CI checks
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
8+
jobs:
9+
build:
10+
runs-on: [self-hosted, linux]
11+
timeout-minutes: 150
12+
13+
steps:
14+
- name: Checkout Repo
15+
uses: actions/checkout@v2
16+
17+
- name: Build AMI
18+
run: |
19+
packer build -timestamp-ui -color=false -on-error=abort -var-file common.vars.json -var-file development-arm.vars.json amazon.json

Dockerfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
ARG PLATFORM
2+
ARG VERSION
3+
4+
FROM --platform=$PLATFORM postgres:$VERSION
5+
6+
COPY ansible/ /tmp/ansible/
7+
8+
RUN apt update && \
9+
apt install -y ansible && \
10+
cd /tmp/ansible && \
11+
ansible-playbook playbook-docker.yml && \
12+
apt -y update && \
13+
apt -y upgrade && \
14+
apt -y autoremove && \
15+
apt -y autoclean && \
16+
apt install -y default-jdk-headless && \
17+
rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/*
18+
19+
ENV LANGUAGE=en_US.UTF-8
20+
ENV LANG=en_US.UTF-8
21+
ENV LC_ALL=en_US.UTF-8

README.md

+29-26
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,35 @@
33
Unmodified Postgres with some useful plugins. Our goal with this repo is not to modify Postgres, but to provide some of the most common extensions with a one-click install.
44

55
## Primary Features
6-
- ✅ Postgres [13](https://www.postgresql.org/about/news/postgresql-13-released-2077/).
6+
- ✅ Postgres [14](https://www.postgresql.org/about/news/postgresql-14-released-2318/).
77
- ✅ Ubuntu 20.04 (Focal Fossa).
88
-[wal_level](https://www.postgresql.org/docs/current/runtime-config-wal.html) = logical and [max_replication_slots](https://www.postgresql.org/docs/current/runtime-config-replication.html) = 5. Ready for replication.
99
-[Large Systems Extensions](https://github.com/aws/aws-graviton-getting-started#building-for-graviton-and-graviton2). Enabled for ARM images.
1010

1111
## Extensions
12-
| Extension | Description |
13-
| ------------- | ------------- |
14-
| [Postgres contrib modules](https://www.postgresql.org/docs/current/contrib.html) | Because everyone should enable `pg_stat_statements`. |
15-
| [PostGIS](https://postgis.net/) | Postgres' most popular extension - support for geographic objects. |
16-
| [pgRouting](https://pgrouting.org/) | Extension of PostGIS - provides geospatial routing functionalities. |
17-
| [pgTAP](https://pgtap.org/) | Unit Testing for Postgres. |
18-
| [pg_cron](https://github.com/citusdata/pg_cron) | Run CRON jobs inside Postgres. |
19-
| [pgAudit](https://www.pgaudit.org/) | Generate highly compliant audit logs. |
20-
| [pgjwt](https://github.com/michelp/pgjwt) | Generate JSON Web Tokens (JWT) in Postgres. |
21-
| [pgsql-http](https://github.com/pramsey/pgsql-http) | HTTP client for Postgres. |
22-
| [plpgsql_check](https://github.com/okbob/plpgsql_check) | Linter tool for PL/pgSQL. |
23-
| [pg-safeupdate](https://github.com/eradman/pg-safeupdate) | Protect your data from accidental updates or deletes. |
24-
| [wal2json](https://github.com/eulerto/wal2json) | JSON output plugin for logical replication decoding. |
25-
| [PL/Java](https://github.com/tada/pljava) | Write in Java functions in Postgres. |
26-
| [plv8](https://github.com/plv8/plv8) | Write in Javascript functions in Postgres. |
27-
| [pg_plan_filter](https://github.com/pgexperts/pg_plan_filter) | Only allow statements that fulfill set criteria to be executed. |
28-
| [pg_net](https://github.com/supabase/pg_net) | Expose the SQL interface for async networking. |
29-
| [pg_sodium](https://github.com/michelp/pgsodium) | Modern encryption API using libsodium. |
30-
31-
Can't find your favorite extension? Suggest for it to be added into future versions [here](https://github.com/supabase/supabase/discussions/679)!
12+
| Extension | Version | Description |
13+
| ------------- | :-------------: | ------------- |
14+
| [Postgres contrib modules](https://www.postgresql.org/docs/current/contrib.html) | - | Because everyone should enable `pg_stat_statements`. |
15+
| [PostGIS](https://postgis.net/) | [3.1.4](https://git.osgeo.org/gitea/postgis/postgis/raw/tag/3.1.4/NEWS) | Postgres' most popular extension - support for geographic objects. |
16+
| [pgRouting](https://pgrouting.org/) | [v3.3.0](https://github.com/pgRouting/pgrouting/releases/tag/v3.3.0) | Extension of PostGIS - provides geospatial routing functionalities. |
17+
| [pgTAP](https://pgtap.org/) | [v1.1.0](https://github.com/theory/pgtap/releases/tag/v1.1.0) | Unit Testing for Postgres. |
18+
| [pg_cron](https://github.com/citusdata/pg_cron) | [v1.4.1](https://github.com/citusdata/pg_cron/releases/tag/v1.4.1) | Run CRON jobs inside Postgres. |
19+
| [pgAudit](https://www.pgaudit.org/) | [1.6.1](https://github.com/pgaudit/pgaudit/releases/tag/1.6.1) | Generate highly compliant audit logs. |
20+
| [pgjwt](https://github.com/michelp/pgjwt) | [commit](https://github.com/michelp/pgjwt/commit/9742dab1b2f297ad3811120db7b21451bca2d3c9) | Generate JSON Web Tokens (JWT) in Postgres. |
21+
| [pgsql-http](https://github.com/pramsey/pgsql-http) | [1.3.1](https://github.com/pramsey/pgsql-http/releases/tag/v1.3.1) | HTTP client for Postgres. |
22+
| [plpgsql_check](https://github.com/okbob/plpgsql_check) | [2.0.6](https://github.com/okbob/plpgsql_check/releases/tag/v2.0.6) | Linter tool for PL/pgSQL. |
23+
| [pg-safeupdate](https://github.com/eradman/pg-safeupdate) | [1.4](https://github.com/eradman/pg-safeupdate/releases/tag/1.4) | Protect your data from accidental updates or deletes. |
24+
| [wal2json](https://github.com/eulerto/wal2json) | [2.4](https://github.com/eulerto/wal2json/releases/tag/wal2json_2_4) | JSON output plugin for logical replication decoding. |
25+
| [PL/Java](https://github.com/tada/pljava) | [1.6.3](https://github.com/tada/pljava/releases/tag/V1_6_3) | Write in Java functions in Postgres. |
26+
| [plv8](https://github.com/plv8/plv8) | [commit](https://github.com/plv8/plv8/commit/3656177d384e3e02b74faa8e2931600f3690ab59) | Write in Javascript functions in Postgres. |
27+
| [pg_plan_filter](https://github.com/pgexperts/pg_plan_filter) | [commit](https://github.com/pgexperts/pg_plan_filter/commit/5081a7b5cb890876e67d8e7486b6a64c38c9a492) | Only allow statements that fulfill set criteria to be executed. |
28+
| [pg_net](https://github.com/supabase/pg_net) | [v0.3](https://github.com/supabase/pg_net/releases/tag/v0.3) | Expose the SQL interface for async networking. |
29+
| [rum](https://github.com/postgrespro/rum) | [1.3.9](https://github.com/postgrespro/rum/releases/tag/1.3.9) | An alternative to the GIN index. |
30+
| [pg_hashids](https://github.com/iCyberon/pg_hashids) | [commit](https://github.com/iCyberon/pg_hashids/commit/83398bcbb616aac2970f5e77d93a3200f0f28e74) | Generate unique identifiers from numbers. |
31+
| [pg_sodium](https://github.com/michelp/pgsodium) | [v1.3.0](https://github.com/michelp/pgsodium/releases/tag/v1.3.0) | Modern encryption API using libsodium. |
32+
33+
34+
Can't find your favorite extension? Suggest for it to be added into future releases [here](https://github.com/supabase/supabase/discussions/679)!
3235

3336
## Enhanced Security
3437
*This is only available for our AWS EC2/ DO Droplet images*
@@ -42,11 +45,11 @@ Aside from having [ufw](https://help.ubuntu.com/community/UFW),[fail2ban](https:
4245
## Additional Goodies
4346
*This is only available for our AWS EC2/ DO Droplet images*
4447

45-
| Goodie | Description |
46-
| ------------- | ------------- |
47-
| [PgBouncer](https://www.pgbouncer.org/) | Set up Connection Pooling. |
48-
| [PostgREST](https://postgrest.org/en/stable/) | Instantly transform your database into an RESTful API. |
49-
| [WAL-G](https://github.com/wal-g/wal-g#wal-g) | Tool for physical database backup and recovery. |
48+
| Goodie | Version | Description |
49+
| ------------- | :-------------: | ------------- |
50+
| [PgBouncer](https://www.pgbouncer.org/) | [1.16.1](http://www.pgbouncer.org/changelog.html#pgbouncer-116x) | Set up Connection Pooling. |
51+
| [PostgREST](https://postgrest.org/en/stable/) | [v8.0.0](https://github.com/PostgREST/postgrest/releases/tag/v8.0.0) | Instantly transform your database into an RESTful API. |
52+
| [WAL-G](https://github.com/wal-g/wal-g#wal-g) | [v1.1](https://github.com/wal-g/wal-g/releases/tag/v1.1) | Tool for physical database backup and recovery. |
5053

5154
## Install
5255

amazon.json

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
{
22
"variables": {
3-
"aws_access_key": "",
4-
"aws_secret_key": "",
5-
"region": "af-south-1",
6-
"ami_regions": "af-south-1",
7-
"ami": "ami-08a4b40f2fe1e4b35",
8-
"ami_name": "supabase-postgres-13.3.0.4",
9-
"environment": "prod",
10-
"ansible_arguments": "--skip-tags,install-postgrest,--skip-tags,install-pgbouncer,--skip-tags,install-supabase-internal"
3+
"profile": "{{env `AWS_PROFILE`}}"
114
},
125
"builders": [
136
{
147
"type": "amazon-ebs",
15-
"access_key": "{{user `aws_access_key`}}",
16-
"secret_key": "{{user `aws_secret_key`}}",
8+
"profile": "{{user `profile`}}",
179
"region": "{{user `region`}}",
1810
"ami_regions": "{{user `ami_regions`}}",
19-
"source_ami": "{{user `ami`}}",
20-
"instance_type": "m5.2xlarge",
11+
"source_ami": "{{user `ubuntu-2004`}}",
12+
"instance_type": "{{user `instance-type`}}",
2113
"ssh_username": "ubuntu",
22-
"ami_name": "{{user `ami_name`}}",
14+
"ami_name": "supabase-postgres-{{user `postgres-version`}}",
2315
"tags": {
2416
"environment": "{{user `environment`}}",
25-
"appType": "postgres"
17+
"appType": "postgres",
18+
"creator": "packer"
19+
},
20+
"run_tags": {
21+
"creator": "packer"
22+
},
23+
"snapshot_tags": {
24+
"creator": "packer"
25+
},
26+
"run_volume_tags": {
27+
"creator": "packer"
2628
},
2729
"launch_block_device_mappings": [
2830
{
2931
"device_name": "/dev/sda1",
3032
"volume_size": 16,
31-
"volume_type": "gp2",
33+
"volume_type": "gp3",
3234
"delete_on_termination": true
3335
}
3436
]
@@ -45,7 +47,7 @@
4547
"type": "ansible",
4648
"user": "ubuntu",
4749
"playbook_file": "ansible/playbook.yml",
48-
"extra_arguments": "{{user `ansible_arguments`}}"
50+
"extra_arguments": "--skip-tags,install-postgrest"
4951
},
5052
{
5153
"execute_command": "echo 'packer' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'",

ansible/files/docker_mnt/init.sh

-3
This file was deleted.

ansible/files/pgbouncer_config/pgbouncer.ini.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ unix_socket_dir = /tmp
113113
;;;
114114

115115
;; any, trust, plain, md5, cert, hba, pam
116-
auth_type = md5
116+
auth_type = scram-sha-256
117117
auth_file = /etc/pgbouncer/userlist.txt
118118

119119
;; Path to HBA-style auth config

ansible/files/pgbouncer_config/pgbouncer.service.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ After=network.target
3030

3131
[Service]
3232
Type=notify
33-
User=postgres
33+
User=pgbouncer
3434
ExecStart=/usr/local/bin/pgbouncer /etc/pgbouncer/pgbouncer.ini
3535
ExecReload=/bin/kill -HUP $MAINPID
3636
KillSignal=SIGINT

ansible/files/pgbouncer_config/pgbouncer_auth_schema.sql

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
CREATE USER pgbouncer;
22

3+
REVOKE ALL PRIVILEGES ON SCHEMA public FROM pgbouncer;
4+
35
CREATE SCHEMA pgbouncer AUTHORIZATION pgbouncer;
46

57
CREATE OR REPLACE FUNCTION pgbouncer.get_auth(p_usename TEXT)
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Directory for PostgreSQL sockets, lockfiles and stats tempfiles
2-
d /run/pgbouncer 2775 postgres postgres - -
2+
d /run/pgbouncer 2775 pgbouncer postgres - -

ansible/files/postgresql_config/pg_hba.conf.j2

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ local all all peer
8484
# IPv4 local connections:
8585
host all all 127.0.0.1/32 trust
8686
# IPv6 local connections:
87-
host all all ::1/128 md5
87+
host all all ::1/128 scram-sha-256
8888
# Local root Unix user, passwordless access
8989
local all postgres peer map=root_as_postgres
9090
# IPv4 external connections
91-
host all all 0.0.0.0/0 md5
91+
host all all 0.0.0.0/0 scram-sha-256
9292

9393
# MD5 hashed password hosts
9494

ansible/files/postgresql_config/postgresql.conf.j2

+16-16
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
# "postgres -c log_connections=on". Some parameters can be changed at run time
2525
# with the "SET" SQL command.
2626
#
27-
# Memory units: kB = kilobytes Time units: ms = milliseconds
27+
# Memory units: B = bytes Time units: us = microseconds
28+
# kB = kilobytes ms = milliseconds
2829
# MB = megabytes s = seconds
2930
# GB = gigabytes min = minutes
3031
# TB = terabytes h = hours
@@ -92,7 +93,7 @@ listen_addresses = '*' # what IP address(es) to listen on;
9293
# - Authentication -
9394

9495
authentication_timeout = 1min # 1s-600s
95-
password_encryption = md5 # scram-sha-256 or md5
96+
password_encryption = scram-sha-256 # scram-sha-256 or md5
9697
db_user_namespace = off
9798

9899
# GSSAPI using Kerberos
@@ -105,6 +106,7 @@ ssl = off
105106
ssl_ca_file = ''
106107
ssl_cert_file = ''
107108
ssl_crl_file = ''
109+
ssl_crl_dir = ''
108110
ssl_key_file = ''
109111
ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
110112
ssl_prefer_server_ciphers = on
@@ -124,28 +126,28 @@ ssl_passphrase_command_supports_reload = off
124126

125127
shared_buffers = 128MB # min 128kB
126128
# (change requires restart)
127-
# huge_pages = try # on, off, or try
129+
#huge_pages = try # on, off, or try
128130
# (change requires restart)
129-
# huge_page_size = 0 # zero for system default
131+
#huge_page_size = 0 # zero for system default
130132
# (change requires restart)
131-
# temp_buffers = 8MB # min 800kB
132-
# max_prepared_transactions = 0 # zero disables the feature
133+
#temp_buffers = 8MB # min 800kB
134+
#max_prepared_transactions = 0 # zero disables the feature
133135
# (change requires restart)
134136
# Caution: it is not advisable to set max_prepared_transactions nonzero unless
135137
# you actively intend to use prepared transactions.
136-
# work_mem = 4MB # min 64kB
137-
# hash_mem_multiplier = 1.0 # 1-1000.0 multiplier on hash table work_mem
138-
# maintenance_work_mem = 64MB # min 1MB
139-
# autovacuum_work_mem = -1 # min 1MB, or -1 to use maintenance_work_mem
140-
# logical_decoding_work_mem = 64MB # min 64kB
141-
# max_stack_depth = 2MB # min 100kB
142-
# shared_memory_type = mmap # the default is the first option
138+
#work_mem = 4MB # min 64kB
139+
#hash_mem_multiplier = 1.0 # 1-1000.0 multiplier on hash table work_mem
140+
#maintenance_work_mem = 64MB # min 1MB
141+
#autovacuum_work_mem = -1 # min 1MB, or -1 to use maintenance_work_mem
142+
#logical_decoding_work_mem = 64MB # min 64kB
143+
#max_stack_depth = 2MB # min 100kB
144+
#shared_memory_type = mmap # the default is the first option
143145
# supported by the operating system:
144146
# mmap
145147
# sysv
146148
# windows
147149
# (change requires restart)
148-
# dynamic_shared_memory_type = posix # the default is the first option
150+
#dynamic_shared_memory_type = posix # the default is the first option
149151
# supported by the operating system:
150152
# posix
151153
# sysv
@@ -765,8 +767,6 @@ jit_provider = 'llvmjit' # JIT library to use
765767

766768
#exit_on_error = off # terminate session on any error?
767769
#restart_after_crash = on # reinitialize after backend crash?
768-
#remove_temp_files_after_crash = on # remove temporary files after
769-
# backend crash?
770770
#data_sync_retry = off # retry or panic on failure to fsync
771771
# data?
772772
# (change requires restart)

ansible/files/supabase_facts.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[general]
2-
postgres_version=13
2+
postgres_version=14

ansible/playbook-docker.yml

+2-38
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
1-
- name: Preparing Docker container
2-
hosts: localhost
3-
tasks:
4-
- name: Pull Postgres Image
5-
docker_container:
6-
name: "supabase-postgres-build"
7-
image: "postgres:13.3"
8-
env:
9-
LANGUAGE: "en_US.UTF-8"
10-
LANG: "en_US.UTF-8"
11-
LC_ALL: "en_US.UTF-8"
12-
state: started
13-
memory: 4G
14-
memory_swap: 6G
15-
command: tail -f /dev/null
16-
- name: Add Postgres Image to Ansible Hosts
17-
add_host:
18-
name: "supabase-postgres-build"
19-
ansible_connection: docker
20-
ansible_ssh_user: root
21-
221
- name: Build Supabase Postgres
23-
hosts: "supabase-postgres-build"
2+
hosts: localhost
243
gather_facts: false
254

265
vars_files:
@@ -34,19 +13,4 @@
3413
import_tasks: tasks/setup-extensions.yml
3514

3615
- name: Cleanup container
37-
import_tasks: tasks/docker/cleanup.yml
38-
39-
- name: Create supabase/postgres docker image
40-
hosts: localhost
41-
tasks:
42-
- name: Commit Docker image
43-
command: docker commit --change='CMD ["postgres"]' "supabase-postgres-build" "supabase/postgres"
44-
45-
- name: Clean Up Postgres Image
46-
hosts: localhost
47-
tasks:
48-
- name: Remove Running Base Image
49-
docker_container:
50-
name: supabase-postgres-build
51-
state: absent
52-
force_kill: yes
16+
import_tasks: tasks/docker/cleanup.yml

0 commit comments

Comments
 (0)