Skip to content

Commit e3de28b

Browse files
authored
supabase/postgres v0.0.11 (#12)
v0.0.11 - max_replication_slots = 5 - readonly role for public schema - plpython3 - plv8
1 parent 0e100a1 commit e3de28b

File tree

10 files changed

+187
-18
lines changed

10 files changed

+187
-18
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Supabase Postgres
1+
# Postgres + goodies
22

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

@@ -7,12 +7,12 @@ Unmodified Postgres with some useful plugins. Our goal with this repo is not to
77
- ✅ Postgres [12](https://www.postgresql.org/about/news/1976/). Includes [generated columns](https://www.postgresql.org/docs/12/ddl-generated-columns.html) and [JSON path](https://www.postgresql.org/docs/12/functions-json.html#FUNCTIONS-SQLJSON-PATH) support
88
- ✅ Ubuntu 18.04 (Bionic)
99
-[pg-contrib-12](https://www.postgresql.org/docs/12/contrib.html). Because everyone should enable `pg_stat_statements`.
10-
- **readonly** role. A readonly role set up by default for the public schema.
11-
-[wal_level](https://www.postgresql.org/docs/current/runtime-config-wal.html) = logical. Ready for replication.
10+
- **readonly** role. A readonly role set up by default for the public schema.
11+
-[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.
1212
-[PostGIS](https://postgis.net/). Postgres' most popular extension - support for geographic objects.
1313
-[pgTAP](https://pgtap.org/). Unit Testing for Postgres
14-
- [plv8](https://github.com/plv8/plv8) - [coming soon](https://github.com/supabase/postgres/issues/5#issuecomment-621129147). Write in Javascript functions in Postgres.
15-
- [plpython3u](https://www.postgresql.org/docs/current/plpython-python23.html) - [coming soon](https://github.com/supabase/postgres/issues/5#issuecomment-621129797). Python3 enabled by default. Write in Python functions in Postgres.
14+
- [plv8](https://github.com/plv8/plv8) - Write in Javascript functions in Postgres.
15+
- [plpython3u](https://www.postgresql.org/docs/current/plpython-python23.html) - Python3 enabled by default. Write in Python functions in Postgres.
1616

1717
## Install
1818

@@ -24,11 +24,11 @@ See all installation instructions in the [repo wiki](https://github.com/supabase
2424

2525
## Motivation
2626

27-
After talking to a lot of techies, we've found that most believe Postgres is the best (operational) database but they *still* choose other databases. This is overwhelmingly because "the other one was quicker/easier". Our goal is to make it quick and simple to get started with Postgres, so that we never hear that excuse again.
27+
After talking to a lot of techies, we've found that most believe Postgres is the best (operational) database but they *still* choose other databases. This is overwhelmingly because "the other one was quicker/easier". Our goal is to make it fast and simple to get started with Postgres, so that we never hear that excuse again.
2828

29-
Our secondary goal is to show off some of the features that are particularly exciting about Postgres to convince new developers to choose it over other database (a decision which we hope they will appreciate when they start scaling).
29+
Our secondary goal is to show off a few of Postgres' most exciting features. This is to convince new developers to choose it over other database (a decision we hope they'll appreciate once they start scaling).
3030

31-
This is also the same build we offer at [Supabase](https://supabase.io), and everything we do is opensource. This repo makes it easy to *install* Postgres, Supabase makes it easy to *use* Postgres.
31+
Finally, this is the same build we offer at [Supabase](https://supabase.io), and everything we do is opensource. This repo makes it easy to *install* Postgres, Supabase makes it easy to *use* Postgres.
3232

3333
## Roadmap
3434

ansible/playbook.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@
1313
tasks:
1414
- include_tasks: tasks/setup-extensions.yml
1515

16+
- name: Dump SQL script
17+
copy:
18+
dest: /tmp/00-schema.sql
19+
src: ../docker/mnt/00-schema.sql
20+
21+
- name: Set up readonly user for the public schema
22+
become: yes
23+
become_user: postgres
24+
postgresql_query:
25+
db: postgres
26+
path_to_script: /tmp/00-schema.sql
27+
28+
- name: Delete SQL script
29+
file:
30+
path: /tmp/00-schema.sql
31+
state: absent
32+
1633
- name: Set up password for superadmin postgres
1734
become: yes
1835
become_user: postgres

ansible/tasks/setup-extensions.yml

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
cache_valid_time: 3600
1919
when: postgresql_version >= 10
2020

21-
- name: pgTAP - download latest releas
21+
- name: pgTAP - download latest release
2222
get_url:
2323
url: "https://github.com/theory/pgtap/archive/{{ pgtap_release }}.tar.gz"
2424
dest: /tmp
@@ -35,4 +35,66 @@
3535
make:
3636
chdir: /tmp/pgtap-1.1.0
3737
target: install
38-
become: yes
38+
become: yes
39+
40+
- name: Install plpython
41+
apt:
42+
pkg: postgresql-plpython3-12
43+
update_cache: yes
44+
cache_valid_time: 3600
45+
46+
- name: plv8 - download & install dependencies
47+
apt:
48+
pkg:
49+
- build-essential
50+
- ca-certificates
51+
- curl
52+
- git-core
53+
- python
54+
- gpp
55+
- cpp
56+
- pkg-config
57+
- apt-transport-https
58+
- cmake
59+
- libc++-dev
60+
- libc++abi-dev
61+
- postgresql-server-dev-12
62+
- libc++1
63+
- libtinfo5
64+
- libc++abi1
65+
update_cache: yes
66+
install_recommends: no
67+
68+
- name: plv8 - download latest release
69+
git:
70+
repo: https://github.com/plv8/plv8.git
71+
dest: /tmp/plv8
72+
version: r3.0alpha
73+
become: yes
74+
75+
- name: plv8 - build
76+
make:
77+
chdir: /tmp/plv8
78+
become: yes
79+
80+
- name: plv8 - install
81+
make:
82+
chdir: /tmp/plv8
83+
target: install
84+
become: yes
85+
86+
- name: plv8 - remove build dependencies
87+
apt:
88+
pkg:
89+
- ca-certificates
90+
- curl
91+
- git-core
92+
- python
93+
- gpp
94+
- cpp
95+
- pkg-config
96+
- apt-transport-https
97+
- cmake
98+
- libc++-dev
99+
- libc++abi-dev
100+
- postgresql-server-dev-12

ansible/tasks/setup-system.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@
44
apt: update_cache=yes upgrade=yes
55
# SEE http://archive.vn/DKJjs#parameter-upgrade
66

7-
- name: add universe repository for bionic
8-
apt_repository:
9-
repo: deb http://archive.ubuntu.com/ubuntu bionic universe
10-
state: present
11-
127
- name: Install essentials
138
apt:
149
pkg:
15-
- build-essential
1610
- ufw
1711
update_cache: yes
1812
cache_valid_time: 3600

ansible/vars.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
postgresql_version: 12
22
postgresql_wal_level: "logical"
3+
postgresql_max_wal_senders: 10
4+
postgresql_max_replication_slots: 5
35
postgresql_listen_addresses:
46
- "*"
57

digitalOcean.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"api_token": "{{user `do_token`}}",
99
"image": "ubuntu-18-04-x64",
1010
"region": "{{user `region`}}",
11-
"size": "512mb",
11+
"size": "s-1vcpu-1gb",
1212
"ssh_username": "root",
13-
"snapshot_name": "supabase-postgresql-0.0.8"
13+
"snapshot_name": "supabase-postgresql-0.0.11"
1414
}],
1515
"provisioners": [
1616
{

docker/Dockerfile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
FROM postgres:12
2+
3+
# install postgis
4+
ENV POSTGIS_MAJOR 3
5+
ENV POSTGIS_VERSION 3.0.0+dfsg-2~exp1.pgdg100+1
6+
RUN apt-get update \
7+
&& apt-cache showpkg postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR \
8+
&& apt-get install -y --no-install-recommends \
9+
postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR \
10+
postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR-scripts \
11+
&& apt-get install software-properties-common -y \
12+
&& apt-get install git -y \
13+
&& apt-get install build-essential -y \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
# install pgtap
17+
ENV PGTAP_VERSION v1.1.0
18+
RUN git clone git://github.com/theory/pgtap.git \
19+
&& cd pgtap && git checkout tags/$PGTAP_VERSION \
20+
&& make install
21+
22+
# install plpython3
23+
RUN apt-get update \
24+
&& apt-get install postgresql-plpython3-12 -y
25+
26+
# install plv8
27+
ENV PLV8_VERSION=r3.0alpha
28+
29+
RUN buildDependencies="build-essential \
30+
ca-certificates \
31+
curl \
32+
git-core \
33+
python \
34+
gpp \
35+
cpp \
36+
pkg-config \
37+
apt-transport-https \
38+
cmake \
39+
libc++-dev \
40+
libc++abi-dev \
41+
postgresql-server-dev-$PG_MAJOR" \
42+
&& runtimeDependencies="libc++1 \
43+
libtinfo5 \
44+
libc++abi1" \
45+
&& apt-get update \
46+
&& apt-get install -y --no-install-recommends ${buildDependencies} ${runtimeDependencies} \
47+
&& mkdir -p /tmp/build \
48+
&& cd /tmp/build \
49+
&& git clone https://github.com/plv8/plv8.git \
50+
&& cd plv8 \
51+
&& git checkout ${PLV8_VERSION} \
52+
&& make static \
53+
&& make install \
54+
&& rm -rf /root/.vpython_cipd_cache /root/.vpython-root \
55+
&& apt-get clean \
56+
&& apt-get remove -y ${buildDependencies} \
57+
&& apt-get autoremove -y \
58+
&& rm -rf /tmp/build /var/lib/apt/lists/*
59+
60+
RUN mkdir -p /docker-entrypoint-initdb.d
61+
ADD ./mnt /docker-entrypoint-initdb.d/

docker/docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '3'
2+
3+
services:
4+
db:
5+
image: supabase/postgres
6+
ports:
7+
- "6543:5432"
8+
environment:
9+
POSTGRES_PASSWORD: postgres

docker/mnt/00-schema.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Strip everyone on rights to the public schema except for the user postgres
2+
REVOKE ALL ON schema public FROM public;
3+
GRANT ALL ON schema public TO postgres;
4+
5+
6+
-- Provide read only access to the schema and its current content
7+
CREATE ROLE public_readonly;
8+
GRANT CONNECT ON DATABASE postgres TO public_readonly;
9+
GRANT USAGE ON SCHEMA public TO public_readonly;
10+
GRANT SELECT ON ALL TABLES IN SCHEMA public TO public_readonly;
11+
12+
-- Provide read only access to future tables in the schema
13+
ALTER DEFAULT PRIVILEGES IN SCHEMA public
14+
GRANT SELECT ON TABLES TO public_readonly;

docker/mnt/init-permissions.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "host replication $POSTGRES_USER 0.0.0.0/0 trust" >> $PGDATA/pg_hba.conf
5+
echo "shared_preload_libraries = 'pg_stat_statements'" >> $PGDATA/postgresql.conf
6+
echo "pg_stat_statements.max = 10000" >> $PGDATA/postgresql.conf
7+
echo "pg_stat_statements.track = all" >> $PGDATA/postgresql.conf
8+
echo "wal_level=logical" >> $PGDATA/postgresql.conf
9+
echo "max_replication_slots=5" >> $PGDATA/postgresql.conf
10+
echo "max_wal_senders=10" >> $PGDATA/postgresql.conf

0 commit comments

Comments
 (0)